docx
Multiple Choice (Write the answer choice in the blank provided on the left)
____ 1. A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is
called a(n) ____.
a. algorithm c. compiler
b. linker d. debugger
____ 2. Suppose that a, b, and c are int variables, z is a float variable, and the input is:
2 32.6 12.1 5
Choose the values of x, y, z, and a after the following statements executes:
int a;
int b;
int c;
float z;
cin >> a >> b >> z >> c;
a. a = 2, b = 32.6, z = 12.1, c = 5
b. a = 2, b = 32, z = 0.6, c = 12
c. a = 2, b = 32, z = 0.6, c = 12.1
d. a = 2, b = 32.6, z = 0.6, c = 12
____ 3. What is the output of the following code fragment if the input value is 3?
int num, alpha;
alpha = 10;
cin >> num;
switch (num)
{
case 3:
alpha++;
case 8:
alpha += 4;
default:
alpha += 5;
}
cout << alpha << endl;
a. 10 c. 15
b. 11 d. 20
Page 1 of 3
COSC1436CppFinalREVIEW.docx
____ 7. Which of the following is a correct definition of a function that takes two integer parameters and
returns the value of the smallest of them?
a. int smallest (int a, int b) c. int smallest (int a, int b)
{ {
int smallest; int smallest = a;
if (a < b) if (b < smallest)
smallest = a; smallest = b;
else if (b < a) cout << smallest;
smallest = b; }
cout << smallest;
}
d. void smallest (int a, int b)
b. int smallest (int a, int b)
{
{
int smallest = a;
int smallest = a;
if (b < smallest)
if (b < smallest)
smallest = b;
smallest = b;
return smallest;
return smallest;
}
}
Page 2 of 3
COSC1436CppFinalREVIEW.docx
Write C++ Source Code for a Modular Program that initializes in main() a 5-element, int array called
numArray with the values 1, 2, 3, 4, and 5. The program should then call the following functions that calculate,
format and display the result as in the EXAMPLE OUTPUT below:
1) calculateAverage This function will accept the numArray as an argument (parameter) and should
then calculate and return the average of the 5 numbers.
2) printAverage This function should accept the average of the 5 numbers as an argument (parameter)
and then print the average
EXAMPLE OUTPUT:
Page 3 of 3