$22
Assignment 6
Given the code answer the questions:
#include <iostream1. using namespace std;2. 3. 4. int testing (int a, float b);5. 6. int main()7. {8. int x;9. float y;10. cout << "Enter an integer and a decimal number"<< endl;11. cin x y;12. cout << testing (x, y);13. return 0;14. }15. 16. int testing (int c, float d)17. {18. //if d is greater than c, return the integer part of d, else return c19. 20. if (d c) 21. return (int) d;22. else23. return c;24. }25. Q 1. Is line 5 a call to function testing, a definition of function testing or the prototype of function testing? Q2. What are the names of the parameters to fucntion testing? remember the parameters are the ones that appear in the definition, not in the prototype Q3. If we change the names of the parameters, will function testing still work? That is, if we rewrite the code and replace them throughout the function with the names number1 and number2, would the computation and results be the same? Try it Q4. Is d inside the function the same variable as (another name for) the caling variable y, or not? In
other words, if we assigned a value to d inside the function, at the end of the execution of test, would the value of y be changed too? Q5. Given the functions below, explain the difference in behavior when these two functions are called using the concept of calling by-reference vs calling by-value: #include <iostream using namespace std; void change (int & val) { val = 27; } and void change2 (int val) { val = 27; } int main() { int x = 99; change2(x); cout << "After calling change2() , the value of x is " << x << endl; change(x) ; cout << "After calling change() , the value of x is " << x << endl; return 0;
Q6. Using the notion of scope explain what instances of variable x are displayed AND WHY. #include <iostream using namepsace std; int x = 12; int main() { int x = 9; { int x = 10 cout << x << endl; }
cout << x << endl; return 0; }