Name_______________________ Login___________________SID________

 

CS 010: Introduction to Computer Science I

Quiz 4: 10 minutes

 

  1. Which statement would use the following coordinate system?

 

    1. cwin.coord(40, 10, -20, 50);
    2. cwin.coord(-20, 40, 10, 50);
    3. cwin.coord(-20, 50, 10, 40);
    4. cwin.coord(10, 40, -20, 50);
    5. cwin.coord(-20, 40, 50, 10);

 

  1. The following is a valid statement.

cwin << Point(0, cwin.get_int(“What is your favorite number?”));

 

    1. TRUE
    2. FALSE

 

  1. If the condition in an if  structure is FALSE, the program will end.
    1. TRUE
    2. FALSE

 

  1. Using an assignment operator in the condition of an if structure will result in a syntax error.
    1. TRUE
    2. FALSE

 

  1. Given the format of the if-else structure below, one and only one of the statement sets inside of the bodies of the if and else will be executed.

if (------)

{

            stmt set 1;

}

else

{

            stmt set 2;

}

 

    1. TRUE
    2. FALSE

 

  1. Given the following code, what will be the output, assuming the user enters 14.25.

int num;

cout << “Enter an integer: “;

cin >> num;

if (cin.fail())

{

            cout << “Output 1\n”;

}

else

{

            cout << “Output 2\n”;

}

    1. Output 1
    2. Output 2

 

  1. Given the code from the above question, what will be the output, assuming the user enters  .11.
    1. Output 1
    2. Output 2

 

  1. Given the following code, and that the user entered the string “Goodbye”, what will be the output?

string str = “Hello”;

string word;

cout << “Enter a word:  “;

cin >> word;

if (word < str)

{

            str = word;

}

cout << str;

 

    1. Hello
    2. Goodbye
    3. None of the above

 

  1. Given the following code, what will be the output?

int x = 1;

int y = 2;

if (x < y)

{

      cout << x;

}

cout << y;

 

    1. 1
    2. 2
    3. x
    4. y
    5. 12

 

  1. What will be the output of the following code segment?

int x = 0;

int y = 3;

if (x < 1)

{

            cout << "stmt 1  ";

            x = y;

}

if (x > 1)

{

            cout << "stmt 2  ";

}

else

{

            cout << "stmt 3  ";

}

 

a.       stmt 1

b.      stmt 2

c.       stmt 1  stmt 2

d.      stmt 1  stmt 2  stmt 3

e.       stmt 1  stmt 3