Functions in C++ with Examples – 2 – Programming Code Examples

# Functions in C++ with Examples – 24 min read

### EXERCISE 1

Write a function f having as parameters a table t of any size and an integer n indicating the size of the array. f must return with a return a boolean b indicating if there is a value between 0 and 10 in the n first boxes of the table t. Test this function.

### EXERCISE 2

Write a function f having as parameters a table t of any size and an integer n indicating the size of the array. f must return with a return the number of values between 0 and 10 in the first n boxes of the table t.Test this function.

### EXERCISE 3

Write a function f having as parameters a table t of any size and an integer n indicating the size of the array. f has another parameter v, integer passed by reference. f must return with a return a boolean b indicating if there is a value between 1 and 10 in the n first boxes of the table t. If f returns true, v is equal to the value of the first box in the array between 0 and 10. Test this function.

### EXERCISE 4

Write a function f having as parameters a table t1 of any size and an integer n indicating the size of the array, as well as a table t2 of the same size as t1. f must return an integer nb indicating the number of values between 0 and 10 in table t1. f must put in table t2 the different values between 0 and 10 that he encountered in table t1.

### EXERCISE 5

Write a function f having as parameters a table t of any size and an integer n indicating the size of the array. f must return an integer equal to the index of the first box of the array (among the first n) between 0 and 10. If there is no such value, the function returns -1. Test this function.
{"ft_lang_label":"__label__en","ft_lang_prob":0.60033274,"math_prob":0.9847092,"size":4773,"snap":"2021-43-2021-49","text_gpt3_token_len":1775,"char_repetition_ratio":0.12560286,"word_repetition_ratio":0.6334728,"special_character_ratio":0.4797821,"punctuation_ratio":0.13617021,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9867371,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-06T23:59:47Z\",\"WARC-Record-ID\":\"<urn:uuid:9bbb2aa5-ad9b-4cfb-b08a-3322cdde6b53>\",\"Content-Length\":\"159388\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c9f7c3ab-1faf-4d11-a6c5-34573640ecf6>\",\"WARC-Concurrent-To\":\"<urn:uuid:55abd733-5770-47c1-ad3e-6d93d7b2d796>\",\"WARC-IP-Address\":\"51.195.14.65\",\"WARC-Target-URI\":\"https://www.code4example.com/uncategorized/functions-in-c-with-examples-2/\",\"WARC-Payload-Digest\":\"sha1:EAQVSZ27LLC3YANNE5ET33GIU6DX4X6N\",\"WARC-Block-Digest\":\"sha1:GSNJNJUMUJFFE24BOXICULUNLGC2UN6R\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363327.64_warc_CC-MAIN-20211206224536-20211207014536-00491.warc.gz\"}"}