Name_______________________ Login___________________SID________

 

CS 010: Introduction to Computer Science I

Quiz 2: 10 minutes

 

  1. Which C++ expression is equivalent to the following math equation?

 

 

 

 


a.       a * a * (x + y) / (y + 1)

b.      a ^ 2 * (x + y) / y + 1

c.       (a * a * (x + y)) / (y + 1)

d.      A and C

e.       All of the above

f.        None of the above

 

  1. What is the value of the following expression if x is an integer variable and has a value that is odd (i.e., 1, 3, 5, 7, …)?

 

x % 2

 

a.       0

b.      1

c.       2

d.      cannot be determined from the given information

 

  1. What will be output by the following statements?

 

string greeting = "Hello World!\n";

cout << greeting.substr(6,2)

        << greeting.substr(6,1)

        << greeting.substr(11,1);

 

a.       Hello

b.      World!

c.       WoW!

d.         W

 


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

 

string first_name = “Kris”;

string last_name = “Miller”;

string s = first_name.substr(0,1) + last_name.substr(1,5);

 

a.       Kris Miller

b.      KrisMiller

c.       KMiller

d.      KrisM

e.       Killer

f.        None of the above

 

  1. Which expression has the value 10 given the following statements?

 

string s1 = “Hello”;

string s2 = “World”;

string s3 = s1 + “  “ + s2;

 

    1. s1.length()
    2. s2.length()
    3. s3.length()
    4. s1.length() + s2.length()
    5. C and D
    6. None of the above

 

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

 

double x = 5.66667;

cout << fixed << setprecision(3) << x;

 

    1. Output: 5.67, value of x: 5.67
    2. Output: 5.667, value of x: 5.667
    3. Output: 5.667, value of x: 5.66667
    4. Output: 5.66667, value of x: 5.667
    5. Output: 5.66667, value of x: 5.66667
    6. None of the above

 

  1. Which of the following is an example of a literal?
    1. 10
    2. 4.5
    3. “count”
    4. count
    5. All except D are examples of literals
    6. None of the above are examples of literals

 


  1. The following statement has what kind of error?

 

cout << “hello;

 

    1. Syntax or compile-time error
    2. Logic error
    3. Runtime error
    4. There is no error in this statement

 

  1. A description of steps to solve a problem that is unambiguous, executable, and terminating is called ___________________?

 

    1. a library
    2. an algorithm
    3. a statement
    4. an expression

 

  1. Pseudocode is a mixture of programming code and English used to describe the steps mentioned in question 9.

 

    1. TRUE
    2. FALSE