1 / 71

CS 101 First Exam Review

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 ;

wriehle
Download Presentation

CS 101 First Exam Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 101First 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 • d. -1

  27. MC-13 • In C++, the expression • 1 / 2 - 1 % 3 * 2 + 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. 26 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. 26 There it is.

  42. 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

  43. 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

  44. 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

  45. 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

  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; • else cout << guess; • c. if (total == guess) cout << total; • else cout << guess; • 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; • else cout << guess; • c. if (total == guess) cout << total; • else cout << guess; • d. if (total == guess) cout << guess; • else cout << total;

  50. 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

More Related