Question 10 Which of the following is a valid function proto
Question 10
Which of the following is a valid function prototype for the following function definition? void TotalAmount(int a, float &b, string name); { //........... }
void TotalAmount(int, float, string);
void TotalAmount(int &, float &, string &);
void TotalAmount(int, float &, string);
intTotalAmount(int, float, string);
--------------------------------
Question 11
Which of the following is a valid function name?
display Total11
displayTotal11
11displayTotal
The second and third names are correct
--------------------------------
Question 12
Which of the following is a valid function header for a C++ function that receives a number with a decimal first and an integer second, and then returns the sum of the numbers passed to the function.
int sum (double num1, int num2)
int sum (int num1, double num2)
double sum (double num1, int num2)
double sum (int num1, double num2)
--------------------------------
Question 13
Which of the following can be used to call the function calcNewPrice?
//prototype for calcNewPrice
void calcNewPrice(float, float &);
calcNewPrice(float a, float b);
cout << calcNewPrice( a, b);
calcNewPrice(a, b);
calcNewPrice( a, &b);
Solution
Question 10: void TotalAmount(int, float, string);
Because in this option the syntax of the code is intact whereas in other options syntax in not correct. Let\'s discuss each one of them one by one.
void TotalAmount(int a, float &b, string name); { //........... }
Prototype of the function means declaring that function before using it in a program just like variables so here float &b is not correct, float *b would have been the correct way to do it.
void TotalAmount(int &, float &, string &);
As we can see syntax here is completely invalid
void TotalAmount(int, float &, string);
Syntax is not correct
intTotalAmount(int, float, string);
Syntax is incorrect, int TotalAmount(int, float, string); would have been valid syntax.
Question 11: displayTotal11
Only second name here is correct, first one is not correct because there is no white space allowed while declaring a function or variable.
And for third; A function or variable can never start with the number.
Question 12: double sum (double num1, int num2)
Since function is called with the decimal first and integer second as we can see num1 is a decimal and num2 is an integer. Because two number which are going to be added are of different data type so the answer must be in the double in this case. So for returning correct output from the calling function double will be used for returning the value.
Question 13: calcNewPrice(a, b);
Since variable declaration is done before calling the function. This means that other options are incorrect syntactically.

