Presentation is loading. Please wait.

Presentation is loading. Please wait.

Smoking is prohibited 1 CS 101 First Exam Review.

Similar presentations


Presentation on theme: "Smoking is prohibited 1 CS 101 First Exam Review."— Presentation transcript:

1 Smoking is prohibited 1 CS 101 First Exam Review

2 Smoking is prohibited 2MC-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 Smoking is prohibited 3MC-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 Smoking is prohibited 4MC-2  Which of these following variable names are valid? 1.3set2.PAY DAY3.bin_2 4.cin5.num-5  a.1, 2 & 4  b.2, 3 & 5  c.2 & 5  d.3 & 4

5 Smoking is prohibited 5MC-2  Which of these following variable names are valid? 1.3set2.PAY DAY3.bin_2 4.cin5.num-5  a.1, 2 & 4  b.2, 3 & 5  c.2 & 5  d.3 & 4

6 Smoking is prohibited 6MC-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 Smoking is prohibited 7MC-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 Smoking is prohibited 8MC-4  The statement that correctly defines an integer called “sum” is  a.sum : integer;  b.integer sum;  c.int sum;  d.sum int;

9 Smoking is prohibited 9MC-4  The statement that correctly defines an integer called “sum” is  a.sum : integer;  b.integer sum;  c.int sum;  d.sum int;

10 Smoking is prohibited 10MC-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 Smoking is prohibited 11MC-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 Smoking is prohibited 12MC-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 Smoking is prohibited 13MC-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 Smoking is prohibited 14MC-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 Smoking is prohibited 15MC-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 Smoking is prohibited 16MC-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 Smoking is prohibited 17MC-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 Smoking is prohibited 18MC-9  How is the following expression is written in C++?  y = 3 x 2 – 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 Smoking is prohibited 19MC-9  How is the following expression is written in C++?  y = 3 x 2 – 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 Smoking is prohibited 20MC-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 Smoking is prohibited 21MC-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 Smoking is prohibited 22MC-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 Smoking is prohibited 23MC-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 Smoking is prohibited 24MC-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 Smoking is prohibited 25MC-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 Smoking is prohibited 26MC-13  In C++, the expression  1 / 2 - 1 % 3 * 2 + 3 =  a.1  b.1.5  c.5  d.-1

27 Smoking is prohibited 27MC-13  In C++, the expression  1 / 2 - 1 % 3 * 2 + 3 =  a.1  b.1.5  c.5  d.-1

28 Smoking is prohibited 28MC-14  Statements that the compiler ignore are  a.Selection Statements  b.Loop Statements  c.Include statements  d.Comments

29 Smoking is prohibited 29MC-14  Statements that the compiler ignore are  a.Selection Statements  b.Loop Statements  c.Include statements  d.Comments

30 Smoking is prohibited 30MC-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 Smoking is prohibited 31MC-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 Smoking is prohibited 32MC-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 Smoking is prohibited 33MC-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 Smoking is prohibited 34MC-17  Find the errors in the following program?  1.include  1.include  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 Smoking is prohibited 35MC-17  Find the errors in the following program?  1.include  1.include  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 Smoking is prohibited 36MC-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 Smoking is prohibited 37MC-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 Smoking is prohibited 38MC-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 Smoking is prohibited 39MC-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 Smoking is prohibited 40MC-20  What is the output of the following statement? int num = 26; 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 Smoking is prohibited 41MC-20  What is the output of the following statement? int num = 26; 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 Smoking is prohibited 42MC-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 Smoking is prohibited 43MC-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 Smoking is prohibited 44MC-22   What is the result of the following code: int a = 53; int b = 6; cout << a / b;   a.8.833   b9   c.8   d.5

45 Smoking is prohibited 45MC-22   What is the result of the following code: int a = 53; int b = 6; cout << a / b;   a.8.833   b9   c.8   d.5

46 Smoking is prohibited 46MC-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 Smoking is prohibited 47MC-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 Smoking is prohibited 48MC-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 Smoking is prohibited 49MC-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 Smoking is prohibited 50MC-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 Smoking is prohibited 51MC-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 Smoking is prohibited 52MC-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 Smoking is prohibited 53MC-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 Smoking is prohibited 54MC-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 Smoking is prohibited 55MC-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 Smoking is prohibited 56MC-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 Smoking is prohibited 57MC-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 Smoking is prohibited 58MC-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 Smoking is prohibited 59MC-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 Smoking is prohibited 60MC-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 Smoking is prohibited 61MC-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 Smoking is prohibited 62MC-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;   elsef = 1;   c.if ((f = 1) && (c != 'X'))f = 0;   elsef = 1;

63 Smoking is prohibited 63MC-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;   elsef = 1;   c.if ((f = 1) && (c != 'X'))f = 0;   elsef = 1;

64 Smoking is prohibited 64MC-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 Smoking is prohibited 65MC-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 Smoking is prohibited 66MC-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 Smoking is prohibited 67MC-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 Smoking is prohibited 68MC-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 Smoking is prohibited 69MC-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 Smoking is prohibited 70MC-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 Smoking is prohibited 71MC-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


Download ppt "Smoking is prohibited 1 CS 101 First Exam Review."

Similar presentations


Ads by Google