Consider the following C++ program: 1. #include 2. using namespace std; 3. 4. in
ID: 3771345 • Letter: C
Question
Consider the following C++ program:
1. #include
2. using namespace std;
3.
4. int f(double a[], const int b, double & c, bool d);
5.
6. int main()
7. {
8. double x[] = {5.5, 3.2, 1.1, 9.5, 4.0, 2.4};
9. int y[] = {7, 3, 8, 5, 9};
10.
11. int i = 3, j = 5, k = 7;
12. double r = 2.0, s = 3.0;
13. const double t = 4.0;
14. bool p = true, q = false;
15.
16. k = f(x, i*j, t, q);
17. i = f(y, 8, r, false);
18. r = f(x, y[3], s, p);
19. j = f(x, i, r+s, true);
20.
21. return 0;
22. }
Which of the function calls in the above program are illegal? State the line number(s) with the illegal function calls. Justify your answer for each illegal function call. (Zero credit for giving an answer with no justification.)
also please explain why, thanks
Explanation / Answer
1. k = f(x, i*j, t, q);
2. i = f(y, 8, r, false);
3. r = f(x, y[3], s, p);
4. j = f(x, i, r+s, true);
1.Illegal. function call argument 3 is const double while in the declaration its is double. Type mismatch.
2.Illegal. convert ‘int*’ to ‘double*’ : function declaration and definition is for double[] while the function call pass an integer array x[] which is illegal.
3.Legal :
4.Illegal : invalid initialization of non-const reference of type ‘double&’ from an rvalue of type ‘double’.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.