Download presentation
Presentation is loading. Please wait.
1
CS 101 First Exam Review
2
MC-1 The statement that correctly assigns the sum of the two variables “loop_count” and “petrol_cost” to the variable “sum”, is a. loop_count = sum + petrol_cost; b. petrol_cost = sum - loop_count; c. sum = petrol_cost / loop_count; d. sum = loop_count + petrol_cost;
3
MC-1 The statement that correctly assigns the sum of the two variables “loop_count” and “petrol_cost” to the variable “sum”, is a. loop_count = sum + petrol_cost; b. petrol_cost = sum - loop_count; c. sum = petrol_cost / loop_count; d. sum = loop_count + petrol_cost;
4
MC-2 Which of these following variable names are valid?
1. 3set 2. PAY DAY 3. bin_2 4. cin 5. num-5 a. 1, 2 & 4 b. 2, 3 & 5 c. 2 & 5 d. 3 & 4
5
MC-2 Which of these following variable names are valid?
1. 3set 2. PAY DAY 3. bin_2 4. cin 5. num-5 a. 1, 2 & 4 b. 2, 3 & 5 c. 2 & 5 d. 3 & 4
6
MC-3 The correct statement which divides the variable “t” by the value 10 and stores the result in the variable “d”, is a. d = t/10; b. d = 10/t; c. t = d/10; d. t = 10/d;
7
MC-3 The correct statement which divides the variable “t” by the value 10 and stores the result in the variable “d”, is a. d = t/10; b. d = 10/t; c. t = d/10; d. t = 10/d;
8
MC-4 The statement that correctly defines an integer called “sum” is
a. sum : integer; b. integer sum; c. int sum; d. sum int;
9
MC-4 The statement that correctly defines an integer called “sum” is
a. sum : integer; b. integer sum; c. int sum; d. sum int;
10
MC-5 Select the incorrect statement.
a. 9 % 4 produce the same output as 4 % 3 b. Z = X - -Y; The same as Z = X - (-Y); The same as Z = X + Y; c. X*Y < Z+3 is the same as (X*Y) < (Z+3) d. Assume that x = 7, y = 25, and z = 24.4, then (x != y-18) produces the same output as (x+y != z).
11
MC-5 Select the incorrect statement.
a. 9 % 4 produce the same output as 4 % 3 b. Z = X - -Y; The same as Z = X - (-Y); The same as Z = X + Y; c. X*Y < Z+3 is the same as (X*Y) < (Z+3) d. Assume that x = 7, y = 25, and z = 24.4, then (x != y-18) produces the same output as (x+y != z).
12
MC-6 Convert f = e into a valid C++ assignment. a. f = a+b / c-d * e;
b. f = (a+b) / (c-d) * e; c. f = (a+b)/c-d * e; d. f = a+b / (c-d) * e;
13
MC-6 Convert f = e into a valid C++ assignment. a. f = a+b / c-d * e;
b. f = (a+b) / (c-d) * e; c. f = (a+b)/c-d * e; d. f = a+b / (c-d) * e;
14
MC-7 What is the output of the following? int x = 1, y = 2, z = 3;
cout << 3 / x / (y – x); a. 1 b. 2 c. 3 d. 4
15
MC-7 What is the output of the following? int x = 1, y = 2, z = 3;
cout << 3 / x / (y – x); a. 1 b. 2 c. 3 d. 4
16
MC-8 What is the output of the following statement?
cout << ((3*4*(5/2-(21%4-1)*2)+1)-1); a. 12 b. -25 c. 47 d. 24
17
MC-8 What is the output of the following statement?
cout << ((3*4*(5/2-(21%4-1)*2)+1)-1); a. 12 b. -25 c. 47 d. 24
18
MC-9 How is the following expression is written in C++? y = 3 x2 – 2x
a. y = 3 * x + x – 2 + x b. y = (3 + (x * x)) – (2 + x) c. y = 3 * x^2 – 2 * x d. y = 3 * x * x – 2 * x
19
MC-9 How is the following expression is written in C++? y = 3 x2 – 2x
a. y = 3 * x + x – 2 + x b. y = (3 + (x * x)) – (2 + x) c. y = 3 * x^2 – 2 * x d. y = 3 * x * x – 2 * x
20
MC-10 Given int a = 7 and int b = 3 then the value of Y will be:
Y = ( a * b % ( a + b +2) – ( a / b) ) a. 3 b. 7 c. 5 d. Non of the answers
21
MC-10 Given int a = 7 and int b = 3 then the value of Y will be:
Y = ( a * b % ( a + b +2) – ( a / b) ) a. 3 b. 7 c. 5 d. Non of the answers
22
MC-11 Choose the right statement.
a. A C++ program that prints 3 lines must contain 3 cout statements. b. A C++ program that prints 3 lines must contain 2 cout statements. c. A C++ program that prints 3 lines must contain 1 cout statement. d. A C++ program that prints 3 lines may contain 1 or more cout statements.
23
MC-11 Choose the right statement.
a. A C++ program that prints 3 lines must contain 3 cout statements. b. A C++ program that prints 3 lines must contain 2 cout statements. c. A C++ program that prints 3 lines must contain 1 cout statement. d. A C++ program that prints 3 lines may contain 1 or more cout statements.
24
MC-12 Which of the following statements is incorrect?
a. The modulus operator (%) can be used only with an integer operand. b. The arithmetic operators *, /, % all have the same level of precedence. c. C++ considers the two variables (number and NUMBER) to be identical. d. None of the above
25
MC-12 Which of the following statements is incorrect?
a. The modulus operator (%) can be used only with an integer operand. b. The arithmetic operators *, /, % all have the same level of precedence. c. C++ considers the two variables (number and NUMBER) to be identical. d. None of the above
26
MC-13 In C++, the expression 1 / 2 - 1 % 3 * 2 + 3 = a. 1 b. 1.5 c. 5
1 / % 3 * = a. 1 b. 1.5 c. 5 d. -1
27
MC-13 In C++, the expression 1 / 2 - 1 % 3 * 2 + 3 = a. 1 b. 1.5 c. 5
1 / % 3 * = a. 1 b. 1.5 c. 5 d. -1
28
MC-14 Statements that the compiler ignore are a. Selection Statements
b. Loop Statements c. Include statements d. Comments
29
MC-14 Statements that the compiler ignore are a. Selection Statements
b. Loop Statements c. Include statements d. Comments
30
MC-15 The statement which correctly assigns the value of the variable “num” to the variable “tot”, is a. tot := num; b. num = tot; c. tot = num; d. num := tot;
31
MC-15 The statement which correctly assigns the value of the variable “num” to the variable “tot”, is a. tot := num; b. num = tot; c. tot = num; d. num := tot;
32
MC-16 The correct definition of three variables called x, y, and z, which can hold integer values, is a. int x, y, z b. int x, y, z; c. int x; y; z; d. int x y z;
33
MC-16 The correct definition of three variables called x, y, and z, which can hold integer values, is a. int x, y, z b. int x, y, z; c. int x; y; z; d. int x y z;
34
MC-17 Find the errors in the following program?
1. include <iostream.h> 2. int main( { 3. int x; 4. cout << ”Enter a value for x” << endl; 5. cin > x; 6. x = 5 – 3 7. return 0; }
35
MC-17 Find the errors in the following program?
1. include <iostream.h> 2. int main( { 3. int x; 4. cout << ”Enter a value for x” << endl; 5. cin > x; 6. x = 5 – 3 7. return 0; }
36
MC-18 What are the values of x, y, z, r, s, and t after the code is executed int x,y,z; float r,s,t; z=2; y=z-1; x=z+4; r=x/y; s=r/z; t=z%y; a. x=4, y=1, z=2, r=2, s=3, t=2. b. x=6, y=4, z=2, r=6, s=3, t=1. c. x=6, y=1, z=2, r=6, s=3, t=0. d. x=4, y=4, z=4, r=2, s=2, t=1.
37
MC-18 What are the values of x, y, z, r, s, and t after the code is executed int x,y,z; float r,s,t; z=2; y=z-1; x=z+4; r=x/y; s=r/z; t=z%y; a. x=4, y=1, z=2, r=2, s=3, t=2. b. x=6, y=4, z=2, r=6, s=3, t=1. c. x=6, y=1, z=2, r=6, s=3, t=0. d. x=4, y=4, z=4, r=2, s=2, t=1.
38
MC-19 Which of the following is NOT a valid identifier (i.e. CANNOT be used as a name for a variable). a. phone_number b. EXTRACREDIT c. DOUBLE d. my course
39
MC-19 Which of the following is NOT a valid identifier (i.e. CANNOT be used as a name for a variable). a. phone_number b. EXTRACREDIT c. DOUBLE d. my course
40
MC-20 What is the output of the following statement? int num = 26;
cout << "Here it is." << num << "\nThere it is."; a. Here it is.There it is. b. Here it is.26\nThere it is. c. Here it is.26 There it is. d. Here it is There it is.
41
MC-20 What is the output of the following statement? int num = 26;
cout << "Here it is." << num << "\nThere it is."; a. Here it is.There it is. b. Here it is.26\nThere it is. c. Here it is.26 There it is. d. Here it is There it is.
42
MC-21 Assuming that the user types followed by a return, what is the output of the following code: int num; cout << "Enter a number: "; cin >> num; cout << num; a. 0 b. 14 c d. 15
43
MC-21 Assuming that the user types followed by a return, what is the output of the following code: int num; cout << "Enter a number: "; cin >> num; cout << num; a. 0 b. 14 c d. 15
44
MC-22 What is the result of the following code:
int a = 53; int b = 6; cout << a / b; a b 9 c. 8 d. 5
45
MC-22 What is the result of the following code:
int a = 53; int b = 6; cout << a / b; a b 9 c. 8 d. 5
46
MC-23 The statement that compares the value of an integer called sum against the value 65, and if it is greater, prints the text string "Sorry, try again", is a. if (sum > "65") cout << "Sorry, try again"; b. if (sum > 65) cout << "Sorry, try again"; c. if (65 == sum) cout << "Sorry, try again"; d. if (sum >= 65) cout << "Sorry, try again";
47
MC-23 The statement that compares the value of an integer called sum against the value 65, and if it is greater, prints the text string "Sorry, try again", is a. if (sum > "65") cout << "Sorry, try again"; b. if (sum > 65) cout << "Sorry, try again"; c. if (65 == sum) cout << "Sorry, try again"; d. if (sum >= 65) cout << "Sorry, try again";
48
MC-24 The statement that compares total for equality to guess, and if equal prints the value of total, and if not equal prints the value of guess, is a. if (total = guess) cout << total); else cout << guess; b. if (total < guess) cout << total; c. if (total == guess) cout << total; d. if (total == guess) cout << guess; else cout << total;
49
MC-24 The statement that compares total for equality to guess, and if equal prints the value of total, and if not equal prints the value of guess, is a. if (total = guess) cout << total); else cout << guess; b. if (total < guess) cout << total; c. if (total == guess) cout << total; d. if (total == guess) cout << guess; else cout << total;
50
MC-25 3. If grade has the value of 50 what will the following code print? if (grade >= 50) cout << “Passed”; a. nothing b. 50 c. “Passed” d. Passed
51
MC-25 3. If grade has the value of 50 what will the following code print? if (grade >= 50) cout << “Passed”; a. nothing b. 50 c. “Passed” d. Passed
52
MC-26 In C++, the condition x > y > z
a. evaluates correctly and could be replaced by (x > y && y > z) b. generates syntax error and should be replaced by (x > y || y > z) c. evaluates correctly and could be replaced by (x > y || y > z) d. generates syntax error and should be replaced by (x > y && y > z)
53
MC-26 In C++, the condition x > y > z
a. evaluates correctly and could be replaced by (x > y && y > z) b. generates syntax error and should be replaced by (x > y || y > z) c. evaluates correctly and could be replaced by (x > y || y > z) d. generates syntax error and should be replaced by (x > y && y > z)
54
MC-27 The AND (&&) operator
a. has less precedence than the OR (II) operator b. associates from right to left c. stops evaluation upon finding one condition to be true d. is a binary operator
55
MC-27 The AND (&&) operator
a. has less precedence than the OR (II) operator b. associates from right to left c. stops evaluation upon finding one condition to be true d. is a binary operator
56
MC-28 The expression if (num != 65) can be replaced by:
a. if (num > 65 && num < 65) b. if ((num == 65)) c. if (num – 65) d. if ( !(num – 65))
57
MC-28 The expression if (num != 65) can be replaced by:
a. if (num > 65 && num < 65) b. if ((num == 65)) c. if (num – 65) d. if ( !(num – 65))
58
MC-29 What is the output of the following code, assuming that x = 12;
if(x = 6) x = x + 1; cout << x; a. 12 b. 6 c. 7 d. x
59
MC-29 What is the output of the following code, assuming that x = 12;
if(x = 6) x = x + 1; cout << x; a. 12 b. 6 c. 7 d. x
60
MC-30 The statement that tests to see if sum is equal to 10 or total is less than 20, and if so, prints the text string "incorrect.", is a. if ((sum = 10) && (total < 20)) cout << ”incorrect"; b. if ((sum == 10) && (total < 20)) cout << "incorrect"; c. if ((sum == 10) || (total < 20)) cout << "incorrect";
61
MC-30 The statement that tests to see if sum is equal to 10 or total is less than 20, and if so, prints the text string "incorrect.", is a. if ((sum = 10) && (total < 20)) cout << ”incorrect"; b. if ((sum == 10) && (total < 20)) cout << "incorrect"; c. if ((sum == 10) || (total < 20)) cout << "incorrect";
62
MC-31 If f is equal 1 and c is not equal an 'X', then assign the value 0 to f, else set f to 1. a. if ((f == 1) && (c != 'X')) f = 0; else f = 1; b. if ((f == 1) && (c <> 'X')) f = 0; else f = 1; c. if ((f = 1) && (c != 'X')) f = 0;
63
MC-31 If f is equal 1 and c is not equal an 'X', then assign the value 0 to f, else set f to 1. a. if ((f == 1) && (c != 'X')) f = 0; else f = 1; b. if ((f == 1) && (c <> 'X')) f = 0; else f = 1; c. if ((f = 1) && (c != 'X')) f = 0;
64
MC-32 What does the following code fragment print?
int h = 13; if (h <= 12) cout << "Low bridge: "; cout << "proceed with caution."; a. Nothing is written. b. Low bridge: c. proceed with caution. d. Low bridge: proceed with caution.
65
MC-32 What does the following code fragment print?
int h = 13; if (h <= 12) cout << "Low bridge: "; cout << "proceed with caution."; a. Nothing is written. b. Low bridge: c. proceed with caution. d. Low bridge: proceed with caution.
66
MC-33 What is the output of the following code? int x = 0, y = 1, z;
if(x) z = 1; else z = 2; if(y) z = 3; else z = 4; cout << z; a. 4 b. 3 c. 2 d. 1
67
MC-33 What is the output of the following code? int x = 0, y = 1, z;
if(x) z = 1; else z = 2; if(y) z = 3; else z = 4; cout << z; a. 4 b. 3 c. 2 d. 1
68
MC-34 One of these is a Correct C++ statement
a. if x == 1 cout << x; b. if (x == 1 ) then cout << x; c. if (x == 1) cout << x; d. if (x == 1) cout >> x;
69
MC-34 One of these is a Correct C++ statement
a. if x == 1 cout << x; b. if (x == 1 ) then cout << x; c. if (x == 1) cout << x; d. if (x == 1) cout >> x;
70
MC-35 What is the output of the following code? int a = 7; if(a = 1) {
if (a == 22) cout << a; } else cout << a; cout << 88; a. 88 b. 788 c. 880 d. 088
71
MC-35 What is the output of the following code? int a = 7; if(a = 1) {
if (a == 22) cout << a; } else cout << a; cout << 88; a. 88 b. 788 c. 880 d. 088
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.