Presentation is loading. Please wait.

Presentation is loading. Please wait.

T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout << x + y / z – k << endl << ;

Similar presentations


Presentation on theme: "T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout << x + y / z – k << endl << ;"— Presentation transcript:

1

2 T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout << x + y / z – k << endl << ;

3 T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout << x + y / z – k << endl << ; // insertion symbol causes error

4 What does the following code print? cout << double(4 / 3) – 2 << endl;

5 What does the following code print? cout << double(4 / 3) – 2 << endl; // 1 - 2 // -1

6 What does the following code print int x = 5; x +=20; x = sqrt(x); x--; cout << x << endl;

7 What does the following code print int x = 5; x +=20; // 25 x = sqrt(x); // 5 x--; // 4 cout << x << endl; // 4

8 What does the following code print? int x = 5, y = 13; x *= 5; x ++; x /= 4; y = 100; cout << y << endl;

9 What does the following code print? int x = 5, y = 13; x *= 5; x ++; x /= 4; y = 100; cout << y << endl; // Prints 100

10 What does the following code print? int x = 4, y = 5, z = 6; x = (x + y) % z; x++; y++; x += y; cout << x << endl;

11 What does the following code print? int x = 4, y = 5, z = 6; x = (x + y) % z; //9 mod 6 = 3 x++; // x = 4 y++; // y = 6 x += y; // x = 10 cout << x << endl; // Prints 10

12 What does the following code print? double x = 1.5, y = 2.5, z = 3; cout << int (z)/int(y) + x << endl;

13 What does the following code print? double x = 1.5, y = 2.5, z = 3; cout << int (z)/int(y) + x << endl; // 1 + 1.5 // 2.5

14 What does the following code print? const double MYSTERY = 4.5; int x = 3, y = 4; cout << MYSTERY + 4; const MYSTERY2 = 3; cout << MYSTERY2 + 4;

15 What does the following code print? const double MYSTERY = 4.5; int x = 3, y = 4; cout << MYSTERY + 4; const MYSTERY2 = 3; // ERROR! cout << MYSTERY2 + 4;

16 What does the following code print? const int MYSTERY = 4; int y = 1, z = 2; cout << sqrt(MYSTERY) + pow(MYSTERY, z) * 1 << endl;

17 What does the following code print? const int MYSTERY = 4; int y = 1, z = 2; cout << sqrt(MYSTERY) + pow(MYSTERY, z) * 1 << endl; // 2 + 16 * 1 // 18

18 What does the following code print? double x = 0.5; int y = 20; cout << (y%5) * x << endl;

19 What does the following code print? double x = 0.5; int y = 20; cout << (y%5) * x << endl; // 0 * 0.5 // 0

20 int x =1, y = 2, z = 3, p = 4, q = 5; x ++; x+=y; x++; x+=z; x++; x+=p; cout << x << endl;

21 int x =1, y = 2, z = 3, p = 4, q = 5; x ++; // x = 2 x+=y; // x = 4 x++; // x = 5 x+=z; // x = 8 x++; // x = 9 x+=p; // x = 13 cout << x << endl;

22 double x = 0.5, y = 1.5; cout << int(x + x + x + x + y) << endl;

23 double x = 0.5, y = 1.5; cout << int(x + x + x + x + y) << endl; // 2 + 1.5 // 3

24 int x = 15, y = 2, z = 3; x = x + sqrt(pow(z, y) + 16); cout << x << endl;

25 int x = 15, y = 2, z = 3; x = x + sqrt(pow(z, y) + 16); // 15 + sqrt(9 + 16) // 15 + 5 // 20

26 int x, y, z; x = 15; z = y = x; cout << “ z = “ << z << endl; cout << “y = “ << y << endl; cout << “x = “ << x << endl;

27 int x, y = 5, z = 4; x = 15; z = y = x; cout << “ z = “ << z << endl; // z = 15 cout << “y = “ << y << endl; // y = 15 cout << “x = “ << x << endl; // x = 15

28 const double y = 55.5; y++; cout << y << endl;

29 const double y = 55.5; y++; // ERROR cout << y << endl;

30 double y = 5.5; cout << int(y) << endl; cout << y << endl;

31 double y = 5.5; cout << int(y) << endl; // 5 cout << y << endl; // 5.5

32 int y = 4, x = 5, z = 7; x = z; cout << “z = “ << z << endl; cout << “x = “ << x << endl;

33 int y = 4, x = 5, z = 7; x = z; cout << “z = “ << z << endl; // z= 7 cout << “x = “ << x << endl; // x = 7

34 cout << abs(int(5.9) * -1) << endl;

35 // abs( 5 * -1) // abs(-5) // 5

36 cout<< int(5) / double(2) << endl;

37 // 5 / 2.0 // 2.5

38 Type the symbol for the assignment operator.

39 // =

40 What is the difference between syntax and semantics?

41 // Syntax – Rules for creating statements // Semantics – How we interpret statements

42 True or false? bool x = true; int y = 5, z = 6; (y > z && x )

43 True or false? bool x = true; int y = 5, z = 6; (y > z && x ) // F

44 True or false? bool x = true, y = false, z = false (x && !y && !z)

45 True or false? bool x = true, y = false, z = false (x && !y && !z) True!

46 What does the code print? int x = 4, y = 2, z = 1; if(y ==2) if( z ==1) x += 6; else x =4; else x += 8; cout << x << endl;

47 What does the code print? int x = 4, y = 2, z = 1; if(y ==2) // True if( z ==1) // True x += 6; // x = 10 else x =4; else x += 8; cout << x << endl;

48 What does the code print? int x = 54; if(x>= 5 && x <= 100) x = 4; else x = 5; cout << x << endl;

49 What does the code print? int x = 54; if(x>= 5 && x <= 100) // True x = 4; // x = 4 else x = 5; cout << x << endl; // 4

50 What does the code print? int x = 14; if(x < 10) cout << “1”; if (x > 10) cout << “2”; if ( x >10 && x < 20) cout << “3”; if(x ==10 || x ==14) cout << “4”;

51 What does the code print? int x = 14; if(x < 10) // false cout << “1”; if (x > 10) // true cout << “2”; if ( x >10 && x < 20) // true cout << “3”; if(x ==10 || x ==14) // true cout << “4”; Prints: 234

52 const int RADIUS = 3.14; double num = 5.5; bool x = false; if(!x) RADIUS += 4; else num= 17; cout << num << endl;

53 const int RADIUS = 3.14; double num = 5.5; bool x = false; if(!x) RADIUS += 4; // ERROR! else num= 17; cout << num << endl;

54 int x = 4, y = 5; bool isWorking = false; if(x<y) if(isWorking) isWorking = false; else isWorking = true; else y = 20; cout << isWorking << endl;

55 int x = 4, y = 5; bool isWorking = false; if(x<y) if(isWorking) isWorking = false; else isWorking = true; else y = 20; cout << isWorking << endl; // Prints 1

56 What is the decimal equivalent of the following binary number? 110101

57 What is the decimal equivalent of the following binary number? 110101 53

58 Write 56 as a binary number.

59 111000 ** One more question

60 Write 56 as a hexadecimal number.

61 38

62 What does the code below print? for(int i = 0; i <= 3; i ++) cout << i;

63 What does the code below print? for(int i = 0; i <= 3; i ++) cout << i; //Prints: 0 1 2 3

64 What does the code below print? int x = 4; while(x < 10){ cout << x; x += 2; }

65 What does the code below print? int x = 4; while(x < 10){ cout << x; x += 2; } // Prints: 4 6 8

66 What does the code below print? for(int i = 0; i < 10; i *=2) cout << i;

67 What does the code below print? for(int i = 0; i < 10; i *=2) cout << i; // INFINITE LOOP

68 What does the code below print? int x = 5; while(x !=-1){ cout << x; x -= 2; }

69 What does the code below print? int x = 5; while(x !=-1){ cout << x; x -= 2; } // Prints: 5 3 1

70 Using interval notation, what range does the code below specify? rand() % 10 + 10

71 Using interval notation, what range does the code below specify? rand() % 10 + 10 [10,20)

72 Using interval notation, what range does the code below specify? rand() % 5+15

73 Using interval notation, what range does the code below specify? rand() % 5+15 [15,20)

74 Using interval notation, what range does the code below specify? rand() % 7+50

75 Using interval notation, what range does the code below specify? rand() % 7+50 [50,57)

76 Using rand(), write a statement that creates a random number from [15, 20]

77 rand() % 6 + 15

78 Using rand(), write a statement that creates a random number in the interval: [50, 100)

79 rand() % 50 + 50

80 What does the code below print? int x = 0; while(x <5){ if(x % 2 == 0) cout << “$”; else cout << “#”; x ++; }

81 What does the code below print? int x = 0; while(x <5){ if(x % 2 == 0) cout << “$”; else cout << “#”; x ++; } // $#$#

82 What does the code below print? int x = 5; while(x < 10){ if(x % 3 == 0) cout << “$”; else cout << “#”; x ++; }

83 What does the code below print? int x = 5; while(x < 10){ if(x % 3 == 0) cout << “$”; else cout << “#”; x ++; } //Prints: #$##$

84 What does the code below print? int x = 0; while (x <= 4){ x++; cout<< x; }

85 What does the code below print? int x = 0; while (x <= 4){ x++; cout<< x; }// Prints: 12345

86 True/False  A parameter of a function is a value that is passed into a function when the function is called.

87 Insert the correct line of code where indicated. void change (double); int main () { double amount; cout >amount; // Insert Code Here // return 0; }

88 Give me on possible answer!  The purpose of a function header is to....

89 True/False  The function that is called into use is called the called function.


Download ppt "T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout << x + y / z – k << endl << ;"

Similar presentations


Ads by Google