1) An algorithm is
A) a finite set of steps to solve a problem.
B) a complete computer program.
C) the inputs and outputs of a program.
D) the part of the computer that does the processing.
2) When you forget to declare a variable before you use it (i.e., you try to use an undeclared variable in your program), it is called a(n)
A) logic error B) syntax error C) run-time error D) operator error
3) Which of the following is a valid declaration for a char variable?
A) char code = “c”; B) char code = ‘c’;
C) char code = ‘check’; D) char code = “check”;
4) The following type of memory is used to store your program and variables while your program executes.
1) _____
2) _____
3) _____
4) _____
5) _____ 6) _____
7) _____
8) _____
9) _____
10) _____
A) solid state memory C) disk drive memory
5) Which of the following is not a valid identifier? A) my_Integer B) double
B) secondary memory
D) random access memory (RAM)
6) What is the value of x after the following statements execute? int x, y, z;
y = 10;
z = 3;
x = y* z + 3;
A) 60 B) 33 C) 30
7) Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat?
A) cin >> myFloat; B) cin << myFloat; C) cin >> myFloat >> endl; D) cin >> "myFloat";
8) What is the value of x after the following statements execute? float x;
x = 15/4;
A) 4.0 B) 60 C) 3.75
9) What is the value of x after the following statements execute? double x;
x = 0;
x += 3.0 * 4.0; x -= 2.0;
A) 22.0 B) 14.0 C) 10.0
10) What is the correct way to write the condition y < x < z?
A) (y < x < z) B) ((y < x) && (x < z)) C)((y>x)∣ ∣ (y<z)) D)((y<x)&&z)
D) 3.0
D) 12.0
C) total3
D) myInt
D) garbage
11) Given the following code fragment and the input value of 2.0, what output is generated? double tax;
double total;
cout << "enter the cost of the item\n";
cin >> total;
if ( total >= 3.0) {
tax = 0.10;
cout << total + (total * tax) << endl; }
else {
cout << total << endl; }
A) 3.1 B) 2.2 C) 2.0 D) 4.4
12) Given the following code fragment, and an input value of 5, what is the output? int x;
11) _____
cin >> x; if( x < 3) {
cout << "small\n"; }
else {
if( x < 4) {
cout << "medium\n"; }
else {
if( x < 6) {
cout << "large\n"; }
else {
cout << "giant\n"; }
} }
A) medium
B) small
C) large
D) giant
13) Given the following code fragment, what is the final value of y? int x, y;
x = -1;
y = 0; while(x < 3) {
y += 2;
x += 1; }
13) _____
A) 6
B) 10
C) 8
D) 2
12) _____
14) Which boolean operation is described by the following table?
14) _____
A
B
Operation
True
True
True
True
False
True
False
True
True
False
False
False
A) not B) and
C) or D) none of the above
15) If the value of a is 3 and the value of b is 6, what is the value of the following expression? (a == 3 && (a > 10 || b <= 6))
15) _____
16) _____
17) _____
18) _____
19) _____ 20) _____ 21) _____
22) _____
A) 0 B) false C) illegal syntax
16) What is the output of the following code fragment if x is 15? if(x < 20)
if(x < 10)
cout << "less than 10 ";
else
cout << "large\n";
A) large C) nothing
17) Given the following code, what is the final value of i? int i;
D) true
for(i = 0; i <= 4;i ++ ) {
cout << i << endl; }
A) 0
B) 4
C) 5
D) 3
18) If you want a loop to keep iterating while x >= 10 or y <= 3, what would be the proper loop condition test?
A) (x < 10 && y > 3) C) (x >=10 && y <= 3)
19) Which loop structure always executes at least once? A) sentinel B) while
B) (x >= 10 || y <= 3) D) (x > 10 || y < 3)
C) for 20) Which of the following is a valid case statement in a switch?
D) do-while D) case x < 4:
for this
D) 6.0
A) case 1.5: B) case 1:
21) What is wrong with the following for loop? for(int i = 0;i < 10;i -- )
{
cout << "Hello\n"; }
A) infinite loop
C) i is not initialized.
C) case 'ab':
B) cannot use a for-loop D) off-by-one error
22) What is the value of x after the following code fragment executes? double x = 36.0;
x = sqrt(x);
A) 3.0 B) 2.456 C) 36.0
B) less than 10
D) no output, syntax error
23) The fabs(double num) function
A) returns the most fabulous number.
B) returns the negative value of num.
C) returns the absolute value of num.
D) returns the largest whole number <= num.
24) What is the output of the following program fragment? cout << static_cast < float > (3/4) << endl;
A) 0.75 B) 0.0 C) 0.5
25) What is the value returned by the following function? int function( )
D) 3
D) 10
23) _____
24) _____
25) _____
26) _____
27) _____
28) _____
29) _____
30) _____
{
int value = 35;
return value + 5;
value += 10; }
A) 40
B) 50
C) 35
26) If you need to write a function that will compute the cost of some candy, where each piece costs 25 cents, which would be an appropriate function declaration?
A) char calculateCost(int count); B) int calculateCost(int count); C) int calculateCost int count; D) int calculateCost(char name);
27) When parameters are passed between the calling code and the called function, parameters and arguments are matched by
A) their names.
B) their data types.
C) their relative positions in the parameter and argument lists.
D) They are not matched up at all.
28) Which of the following are valid function calls to the fabs function? A) double x = fabs(3.5);
B) cout << fabs(3.5); C) cin >> fabs(3.5); D) fabs(cin >> x);
E) A and B
29) What is the output of the following code fragment?
double size, volume = 16.0; size = sqrt(sqrt(volume)) / 3; cout.setf(ios::fixed) cout.setf(ios::showpoint); cout.precision(2);
cout << size;
A) 0 B) 0.00
C) 0.67
D) 0.6666667
30) Which of the following is a legal call to the computeOutput function? double computeOutput(int total);
A) computeOutput(myTotal) = total; B) cout << computeOutput(int mytotal); C) double computeOutput(myTotal); D) cout << computeOutput(myTotal);