C++ General

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.

 

Leave a Comment