Name_______________________ Login___________________SID________

 

CS 010: Introduction to Computer Science I

Quiz 2: 10 minutes

 

  1. What is output by the following statement provided all needed libraries were included?

cout << fixed << setprecision(2) << 20 / 8;

a.       2.5

b.      2.50

c.       2

d.      2.0

e.       4

f.        there is a syntax error

 

  1. What is output by the following statement provided all needed libraries were included?

cout << fixed << setprecision(2) << 20 % 8;

a.       2.5

b.      2.50

c.       2

d.      2.0

e.       4

f.        there is a syntax error

 

  1. What is output by the following statement provided all needed libraries were included?

cout << fixed << setprecision(2) << 20.0 / 8;

a.       2.5

b.      2.50

c.       2

d.      2.0

e.       4

f.        there is a syntax error

 

  1. What is output by the following statement provided all needed libraries were included?

cout << fixed << setprecision(2) << 20.0 % 8;

a.       2.5

b.      2.50

c.       2

d.      2.0

e.       4

f.        there is a syntax or compile-time error

 

  1. Strings are a built-in or fundamental data type of C++.
    1. TRUE
    2. FALSE

 

 

 

 

  1. What is output by the following statements?

int x = 10;

20 = x;

cout << x;

 

    1. 10
    2. 20
    3. x
    4. 10.0
    5. 20.0
    6. there is a syntax error

 

  1. Which C++ expression below is a valid translation of the following algebraic expression?

 

 

 

 


    1. a^2 (b – 1) / (b + 1) – (c / d)
    2. a^2 * ((b – 1) / (b + 1)) – (c / d)
    3. a * a * b – 1 / b + 1 – c / d
    4. a * a * (b – 1) / (b + 1) – c / d
    5. B and D
    6. None of the above.

 

  1. What is output by the following statements?

string str1 = “hello!”;

string str2 = “jumble”;

cout << str2.substr(0,1) << str1.substr(5,1);

    1. jello!
    2. humble
    3. j!
    4. ello!
    5. jumblehello!
    6. none of the above

 

  1. What is the value of x after the following statements?

double x = 4.5678

cout << fixed << setprecision(2);

 

    1. 4.5678
    2. 4.56
    3. 4.57
    4. 4.5
    5. 4.6
    6. none of the above

 

  1. Any sequence or combination of space and newline characters are considered white space in C++.

 

    1. TRUE
    2. FALSE