Quiz 4 Flashcards

1
Q

After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time?

 cin >> input_value;

 if (input_value > 5)

     input_value = input_value + 5;

 else if (input_value > 2)

     input_value = input_value + 10;

 else

     input_value = input_value + 15;
A

*A) 15

B) 10

C) 25

D) 0

E) 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables.

 a = x >= y;
A

A) 10

B) 7

C) The string “x >= y”

*D) 1

E) 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What will the following segment of code output?

Assume the user enters a grade of 90 from the keyboard.

  cout << "Enter a test score: ";

  cin >> test_score;

  if (test_score < 60);

      cout << "You failed the test!" << endl;

  if (test_score > 60)

      cout << "You passed the test!" << endl;

  else

      cout << "You need to study for the next test!";
A

A) You failed the test!
You Answered

B) You passed the test!

*C) You failed the test!

  You passed the test!

D) You failed the test!

  You did poorly on the test!

E) None of the above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When an if statement is placed within the conditionally-executed code of another if statement, this is known as:

A

A) complexity

You Answered

B) overloading

*C) nesting

D) validation

E) None of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What will the following segment of code output?

 score = 40;

 if (score > 95)

     cout << "Congratulations!\n";

     cout << "That's a high score!\n";

     cout << "This is a test question!" << endl;
A

A) This is a test question!

B) Congratulations!

  That's a high score!

  This is a test question!

*C) That’s a high score!

  This is a test question!

D) Congratulations!

  That's a high score!

E) None of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Assuming x is 5, y is 6, and z is 8, which of the following is false?

  1. x == 5;
  2. 7 <= (x + 2);
  3. z < = 4;
  4. (1 + x) != y;
  5. z >= 8;
  6. x >= 0;
  7. x <= (y * 2)
A

A) 3, 4, 6, 7 are false.

B) Only 5 is false.

*C) 3 and 4 are false.

D) All are false.

E) None of these.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Input values should always be checked for:

A

A) Appropriate range

B) Reasonableness

C) Division by zero, if division is taking place

*D) All of these

E) None of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Without this statement appearing in a switch construct, the program “falls through” all of the statements below the one with the matching case expression.

A
*A) break
  B) exit
  C) switch
  D) scope
  E) None of these
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Whereas < is called a relational operator, x < y is called a(n) ________.

A

A) Arithmetic operator
B) Relative operator
*C) Relational expression
D) Largeness test

E) None of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In C++ the = operator indicates:

A
A) equality 
  *B) assignment 
  C) subtraction 
  D) negation 
E) None of these
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If you intend to place a block of statements within an if statement, you must place these around the block.

A

A) Parentheses ( )
B) Square brackets [ ]
C) Angle brackets < >

*D) Curly braces { }
E) None of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What will the following segment of code output if the value 11 is entered at the keyboard?

 int number;

 cin >> number;

 if (number > 0)

     cout << "C++";

 else

     cout << "Soccer";

     cout << " is ";

     cout << "fun" << endl;
A

*A) C++ is fun

B) Soccer is fun

C) C++

D) C++fun

E) Soccerfun

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What will the following program segment display?

 int funny = 7, serious = 15;

 funny = serious % 2;

 if (funny != 1)

 {

     funny = 0;

     serious = 0;

 }

 else if (funny == 2)

 {

     funny = 10;

     serious = 10;

 }

 else

 {

     funny = 1;

     serious = 1;

 }

 cout << funny << "   " << serious << endl;
A

A) 7 15

B) 0 0

C) 10 10

*D) 1 1

E) None of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When a program lets the user know that an invalid choice has been made, this is known as:

A

*A) input validation

B) output correction

C) compiler criticism

D) output validation

E) None of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What will the following program display?

 #include  

 using namespace std;

 int main()

 {

     int a = 0, b = 2, x = 4, y = 0;

     cout << (a == b) << "  ";

     cout << (a != b) <<  "  ";

     cout << (b <=x) << "  ";

     cout << (y > a) << endl;

     return 0;

 }
A

*A) 0 1 1 0

B) 0 0 1 0

C) 1 1 0 1

D) 1 0 0 1

E) None of these

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

This operator is known as the logical OR operator.

A
A) --
  B) //
  C) #
  *D) ||  
E) None of these
17
Q

This operator performs a logical NOT operation.

A
A) --
  *B) !
  C) <>
  D) >< 
E) None of these
18
Q

Given the following code segment, what is output after “result = “?

 int x = 1, y  = 1, z = 1;

 y = y + z;

 x = x + y;

 cout << "result = "

      << (x < y ? y : x)

      << endl;
A

A) 0

B) 1

C) 2

*D) 3

E) None of these

19
Q

Which statement allows you to properly check the char variable code to determine whether it is equal to a “C” and then output “This is a check” and then advance to a new line?

A

A) if code is equal to C

 cout << "This is a check\n";

B) if (code = “C”)

 cout << "This is a check" << endl;   

*C) if (code == ‘C’)

 cout << "This is a check\n";

D) if (code == C)

    cout << "This is a check" << endl;
20
Q

The ________ of a variable is limited to the block in which it is declared.

A

A) precedence

B) associativity

*C) scope

D) branching ability

E) None of these

21
Q

Given that, x = 2, y = 1, and z = 0, what will the following cout statement display?

 cout << "answer = " << (x || !y &amp;&amp; z) << endl;
A

A) answer = 0
* B) answer = 1
C) answer = 2
D) None of these

22
Q

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement.

A

A) conditional

B) break
* C) trailing else

D) All of these

E) None of these

23
Q

What is the value of donuts after the following code executes?

 int donuts = 10;

 if (donuts != 10)

     donuts = 0;

 else

     donuts += 2;
A

*A) 12
B) 10
C) 0

D) 2

24
Q

What is the output of the following code?

 int w = 98;

 int x = 99;

 int y = 0;

 int z = 1;

 if (x >= 99)

 {

     if (x < 99)

         cout << y << endl;

     else

         cout << z << endl;

 }

 else

 {

     if (x == 99)

         cout << x << endl;

     else

         cout << w << endl;

 }
A

A) 98
B) 99
C) 0
*D) 1

25
Q

Which line in the following program will cause a compiler error?

  1  #include 

  2  using namespace std;

  3 

  4  int main()

  5  {

  6     int number = 5;

  7   

  8     if (number >= 0 &amp;&amp; <= 100)

  9         cout << "passed.\n";

            10     else

            11         cout << "failed.\n";

            12     return 0;

            13  }
A

A) 6

*B) 8

C) 10

D) 9