CH 1 Number System and Numerical Error Analysis
CH 1 Number System and Numerical Error Analysis
1) All of the following are examples of integral data types EXCEPT ______.
o A Double
o B Char
o C Short
o D Int
2) After the execution of the following code, what will be the value of numb if the input value is 5?
o A 0
o B 5
o C 25
o D 15
3) What type of C++ statement(s) stores a value in a variable?
o A both input and assignments
o B assignments
o C output
o D input
1. int n = 0;
2. cout << ((n) ? n++ : ++n);
o A 0
o B 1
o C None of these
o D 2
Page 1 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
o A 11
o B 10
o C None of these
o D 12
7) What is the output of the following code?
1. if ( 6 > 8)
2. {
3. cout << " ** " << endl ;
4. cout << "****" << endl;
5. }
6. else if (9 == 4)
7. cout << "***" << endl;
8. else
9. cout << "*" << endl;
o A ****
o B ***
o C *
o D **
8) Which of these is a valid reserved word in C++?
o A Char B Include C Double D Const
o E None of these
9) Suppose that x, y, z, and w are int variables. The expression x(y+z)/w in C++ is written as
o A x * (y + z) / w
o B x*y+z/w
o C x*y+x*z/w
o D x (y + z) / w
10) The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____.
o A 14
o B 14.8
o C 13
o D 15
Page 2 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
11) Suppose that ch1, ch2, and ch3 are variables of the type char and the input is:
AB
C
**What is the value of ch3 after the following statements execute?
1. cin.get(ch1);
2. cin.get(ch2);
o cin.get(ch3);
o A 'B'
o B 'C'
o C 'A'
o D '\n'
12) Suppose x and y are int variables. Consider the following statements:
1. if (x > 5)
2. y = 1;
3. else if (x < 5)
4. {
5. if (x < 3)
6. y = 2;
7. else
8. y = 3;
9. }
10. else
11. y = 4;
o A 3
o B 1
o C 2
o D 4
Page 3 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
14) Suppose that x is an int variable, ch is a char variable, and the input is: 276.
**Choose the values after the following statement executes: cin >> ch >> x;
o A ch = '2', x = 76
o B ch = '2', x = 276
o C ch = ' ', x = 276
o D Input Failure
1. x = 6;
2. if (x > 10)
3. cout << "One ";
4. cout << "Two ";
o A One
o B Two
o C One Two
o D Two One
Page 4 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
1. int x = 1;
2. while (--x)
3. cout<< x;
o A 0
o B 1
o C No output
o D Infinite loop
18) Which of the following operators has the highest precedence?
o A * B ! C % D =
1. int n = 0;
2. cout << ((n) ? n++ : ++n);
o A 1
o B 0
o C None of these
o D 2
Page 5 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
21) After the execution of the following code, what is the value of sum?
1. int sum = 0;
2. int num = 10;
3. if (num > 0)
4. sum = sum + 10;
5. else if (num > 5)
6. sum = num + 15;
o A 20
o B 10
o C 25
o D 0
22) Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression:
z = (y / x > 0) ? x : y;
o A 2
o B 3
o C 6
o D 4
o A 16
o B 16.5
o C None of these
o D 17
o E 17.5
Page 6 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
o A Char
o B include
o C void
o D duble
o A None of these
o B pop_
o C _D3
o D 1b
o E _sum3
o A 1program
o B program_1
o C program 1
o D program!
Page 7 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
1. int i = 4, j = 6, k = 7, n = 3;
2. cout << i + j*k - k%n << endl;
3. cout << i / k << endl;
o A 45
0.66667
o B None of these
o C 0
0
o D 45
0
1. int x = 5;
2. if (x-- == 4)
3. cout << "One" << endl;
4. cout << x << endl;
5. cout << "Two";
o A 5
Two
o B One
Two
o C One
5 Two
o D 4
Two
o E One
4 Two
Page 8 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
o A 1
o B 2
o C 3
o D 4
1. if (15 % 5)
2. cout << "Two";
3. else cout << "One";
o A One
o B None of these
o C Two
o D Two
One
o A '\r'
o B '/n'
o C '\n'
o D '/r'
33) Which of the following expressions correctly determines that x is greater than 10 and less than 20?
o A 10 < x < 20
o B (10 < x < 20)
o C 10 < x && x < 20
o D 10 < x || x < 20
Page 9 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
1. if (1 == 4 >= 1)
2. cout << "One";
3. else
4. cout << "Two";
o A OneTwo
o B One
o C Two
o D None of thes
1. int x = 10;
2. if (x > 15)
3. x = 0;
4. cout << x << endl;
5. else
6. cout << x + 5;
o A 5
o B 10
o C 0
o D None of these
Page 10 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
37) Suppose x and y are int variables. Consider the following statements:
1. if (x > 5)
2. y = 1;
3. else if (x < 5)
4. {
5. if (x < 3)
6. y = 2;
7. else
8. y = 3;
9. }
10. else
11. y = 4;
o A 1
o B 3
o C 2
o D 4
1. int n = 1;
2. cout << ((n) ? n++ : ++n);
o A 3
o B 1
o C 2
o D None of these
Page 11 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
1. const int c = 9;
o A c = c+1;
o B cout<< c*3;
o C c = 20;
o D None of these
oE cin>>c;
40) Which of the following is a relational operator?
o A ==
o B &&
o C =
o D !
41) Suppose that x and y are int variables, z is a double variable, and the input is:
28
32.6 12
Page 12 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
42) Suppose that alpha and beta are int variables. The statement alpha = beta-- ; is equivalent to
the statement(s)
o A alpha = beta - 1;
beta--;
o B alpha = 1 - beta;
beta--;
o C None of these
o D alpha = beta;
beta = beta - 1;
o A 3
o B 2
o C 7
o D 9
44) Which of the following will cause a semantic error, if you are trying to compare x to 5?
o A if (x = 5)
o B if (x >= 5)
o C if (x == 5)
o D if (x <= 5)
Page 13 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
1. int x;
2. x = (5 <= 3 && 'A' < 'F') ? 3 : 4;
o A 2
o B 3
o C 5
o D 4
46) In a ____ control structure, the computer executes particular statements depending on some condition(s).
o A repetition
o B looping
o C selection
o D sequence
47) What is the output of the following C++ code?
1. int x = 55, y = 5;
2. switch (x % 7)
3. { case 0: case 1: y++;
4. case 2: case 3: y = y + 2;
5. case 4: break;
6. case 5: case 6: y = y – 3;}
7. cout << y << endl;
o A 2 B 5
o C 8 D None of these
o A 2
o B 3
o C 7
o D 9
Page 14 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
49) A(n) ____ statement causes an immediate exit from the switch structure.
o A break
o B endl
o C default
o D exit
50) After the execution of the following code, what is the value of sum?
1. int sum = 0;
2. int num = 10;
3. if (num > 0)
4. sum = sum + 10;
5. else if (num > 5)
6. sum = num + 15;
o A 20
o B 10
o C 25
o D 0
o A EOF-controlled
o B counter-controlled
o C sentinel-controlled
o D None of answers.
Page 15 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
52) Assume all variables are properly declared. What is the output of the following C++ code?
1. num = 100;
2. while (num <= 150)
3. num = num + 5;
4. cout << num << endl;
o A 160
o B 150
o C 145
o D 155
53) What is the output?
1. int x = 5;
2. cout<< (x++)+x<<endl;
o A 10 B 12
o C None of these D 11
o A 60 55 B 46 27
o C 60 55 50 D 60 55 50 45
Page 16 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
1. count = 1;
2. num = 25;
3. while (count < 25)
4. { num = num - 1;
5. count++;}
6. cout << count << " " << num << endl;
o A 25 1
o B 24 1
o C 24 0
o D 25 0
57) In ____ structures, the computer repeats particular statements a certain number of times depending on some
condition(s).
o A looping
o B branching
o C sequence
o D selection
58) What is the output of the following C++ code?
1. num = 0;
2. while (num < 5)
3. { cout << num << " ";
4. num = num + 1; }
o A 012345 B 01234
o C 12345 D 12340
Page 17 of 18
#NASHAMA_BAU @NashamaBAU
C++ Final Exam 2017/2018
59) Suppose sum and num are int variables, and the input is 18 25 61 6 -A What is the
output of the following code?
1. sum = 0;
2. cin >> num;
3. while (num != -1)
4. {
5. sum = sum + num;
6. cin >> num;
7. }
8. cout << sum << endl;
o A 110
o B 92
o C 109
o D 111
Page 18 of 18
#NASHAMA_BAU @NashamaBAU