Anda di halaman 1dari 3

COSC1436CppFinalREVIEW.

docx

COSC1436 Programming Fundamentals I C++


Final Exam REVIEW

Final Exam Part 1

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

____ 4. What is the output of the following code?


int x = 2;
while (x > 10)
cout << "Hello" << endl;
cout << "Welcome" << endl;
cout << "Bye" << endl;
a. Hello c. Welcome
Bye
b. Welcome d. Nothing is printed

____ 5. What is the output of the following code?


int j;
for (j = 1; j <= 1; j++)
cout << j << " ";
cout << j << endl;
a. 1 c. 1 2
b. 1 1 d. 2 2

____ 6. What is the value of x after the following statements execute?


int x = 5;
int y = 40;
do
x *= 2;
while (x <= y);
a. 5 c. 20
b. 80 d. 40

____ 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

____ 8. Given the following declaration:


int j;
double sum;
double sale[5][3];
which of the following correctly finds the sum of the elements of the second column of sale?
a. sum = 0;
for(j = 0; j < 5; j++)
sum = sum + sale[j][1];
b. sum = 0;
for(j = 0; j < 3; j++)
sum = sum + sale[j][2];
c. sum = 0;
for(j = 0; j < 5; j++)
sum = sum + sale[j][0];
d. sum = 0;
for(j = 0; j < 5; j++)
sum = sum + sale[j][2];

Final Exam Part 2 & 3

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:

Average of the numbers = 3.0

Page 3 of 3

Anda mungkin juga menyukai