710 likes | 727 Views
CS 101 First Exam Review. 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 ;
E N D
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;
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;
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
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
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;
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;
MC-4 • The statement that correctly defines an integer called “sum” is • a. sum : integer; • b. integer sum; • c. int sum; • d. sum int;
MC-4 • The statement that correctly defines an integer called “sum” is • a. sum : integer; • b. integer sum; • c. int sum; • d. sum int;
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).
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).
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;
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;
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
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
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
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
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
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
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
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
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.
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.
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
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
MC-13 • In C++, the expression • 1 / 2 - 1 % 3 * 2 + 3 = • a. 1 • b. 1.5 • c. 5 • d. -1
MC-13 • In C++, the expression • 1 / 2 - 1 % 3 * 2 + 3 = • a. 1 • b. 1.5 • c. 5 • d. -1
MC-14 • Statements that the compiler ignore are • a. Selection Statements • b. Loop Statements • c. Include statements • d. Comments
MC-14 • Statements that the compiler ignore are • a. Selection Statements • b. Loop Statements • c. Include statements • d. Comments
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;
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;
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;
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;
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; • }
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; • }
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.
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.
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
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
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. 26 There it is.
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. 26 There it is.
MC-21 • Assuming that the user types 14.92 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. 14.92 • d. 15
MC-21 • Assuming that the user types 14.92 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. 14.92 • d. 15
MC-22 • What is the result of the following code: int a = 53; int b = 6; cout << a / b; • a. 8.833 • b 9 • c. 8 • d. 5
MC-22 • What is the result of the following code: int a = 53; int b = 6; cout << a / b; • a. 8.833 • b 9 • c. 8 • d. 5
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";
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";
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; • else cout << guess; • c. if (total == guess) cout << total; • else cout << guess; • d. if (total == guess) cout << guess; • else cout << total;
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; • else cout << guess; • c. if (total == guess) cout << total; • else cout << guess; • d. if (total == guess) cout << guess; • else cout << total;
MC-25 • 3. If gradehas the value of 50 what will the following code print? • if (grade >= 50) cout << “Passed”; • a. nothing • b. 50 • c. “Passed” • d. Passed