6. Given the following function definition
void calc (int a, int &b)
{
int c;
c = a + 5;
a = a * 2;
b = c + a + 2;
}
What is the output of the following code fragment that invokes calc? (3 points)
int x = 10;
int y = 3;
int z = 15;
calc (x, y); cout < x="">< “="" “="">< y="">< “="" “="">< z=""><>
7. a What is the output from the following code segment? 2.5 points
b. If there is no output, a runtime error, compile error or an infinite loop, please identify and explain. 2.5 points
int point = 1;
while ( point ! = 13)
{
cout < point="">< “,="" ”;="" point="" +="3;">
8.Evaluate the following expressions, assume the following declarations:
int x = 4;
int y = 9 / 2;
int num = 6;
num *= x + y; What is the value of the num after expression is evaluated?
9.Evaluate the following expression: (y > 35), where y (data-type int) has the value ……
10. What will be the following code display?
int num = 0; int a = 0, b = 0, c = 0, d = 0, x = 0; if (num > 1 && num <= 5)="" {="" a="a" +="" 1;="" }="" else="" if="" (num="=" 8)="" {="" b="b" +="" 1;="" x="8;" }="" else="" if="" (num=""> 8 && num < 10)="" {="" c="c" *="" 2;="" }="" else="" {="" d="" +="5;">
11.Rewrite the following conditional expressions as if/else statements: cout < ((="" (x="" %="" 2)="=" 0="">
12.What is the output of the following code fragment? int x, y; x = 10; y = 2; while (x > y) { y ++; x -= 2; cout < “x="“">< x=""><”\n”>”\n”>< “y="“">< y="">< endl;="">
13. Indicate if the following condition is True or False Assume the variables x=5, y=6 and z=8. 7 <= x="" &&="" z=""> 4 True False
14. Write a function prototype and a function definition called sum that receives an array of type integer, and the number of elements in the array. It returns the sum of the numbers in the array.
15.
15.Determine all the output from the following segment of program as it would appear on the screen.
a. Lines 1, 2, and 3 are called function ____________. The function __________ are in lines 17-31.
b. Explain what int =5 means in line 2.
c. Explain the significance of the & in line 3. Explain what the word static means in line 23.
d. Explain the difference between line 10 and line 13.
int f_1();
void f_2(int = 3);
float f_3(int &);
int main()
{
int x = 10, y;
float z; y = f_1();
cout < "y:="" "="">< y=""><>
f_2(); z = f_3(x);
cout < "z:="" "="">< z=""><>
f_2(x); cout < "x:="" "="">< x=""><>
return 0;
}
int f_1()
{
int x = 12; x += 8; return x; }
void f_2(int y) { static int x = 6; x -= y; cout < "x:"="">< x="" *="" x=""><>
}
float f_3(int & x) { x += 3;
cout < "x:"="">< x=""><>
return 103.3333;
}
16. Using a looping structure, prompt user for negative integer values from the keyboard. Ignore all positive values and terminate the loop once a value 0 is entered. After the loop ends, print the total of the read integers. Example:
17. Indicate if the following expression is True or False Assume the variables int a = - 3, b = 6, c = 6; a >= -1 || c <= (b="" +="" a="">=>
18. Evaluating Sorts Given the following array: 41, 32, 5, 8, 7, 50, 11 Show what the array looks like after the first swap of a Selection Sort in ascending order.
19. Evaluate the following expression (y>35), where y (data type int) has the value 15
20. Write a function called expensive books which receive a double array of book prices and the number of books
21. Evaluate the following expression (3% 5-7/6 )
=>=>