COP2000 Quiz 4 Chapter 4

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

This operator performs a logical NOT operation A. -- B. >< C. None of these D. ! E. <>

!

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; }

0110

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; }

1

What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;

12

What will be the value of result after the following code has been executed? int a = 60; int b = 15; int result = 10; if (a = b) result *= 2;

20

What is the output of the following segment of code if 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 10: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl;

3

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 && <= 100) 9 cout << "passed.\n"; 10 else 11 cout << "failed.\n"; 12 return 0; 13 }

8

This is a variable, usually a boolean or an integer, that signals when a condition exists.

Flag

If you place a semicolon after the statement if (x < y)

The compiler will interpret the semicolon as a null statement.

As a rule of style, when writing an if statement you should indent the conditionally-executed statements.

True

If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked.

True

What will the following segment of code output? You can 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!";

You failed the test! You passed the test!

Relational operators allow you to ____________ numbers.

compare

The default section is required in a switch statement.

false

What is the value of the following expression? true && false

false

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

input validation

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

relational expression

This statement lets the value of a variable or expression determine where the program will branch to.

switch

If you place a semicolon after the statement if (x < y)

the compiler will interpret the semicolon as a null statement

What is the value of the following expression? true || true

true

You should be careful when using the equality operator to compare floating point values because of potential round-off errors.

true


संबंधित स्टडी सेट्स

1.02 - What is Environmental Science?

View Set

HESI Case Study: COPD with Pneumonia

View Set

PN Comprehensive Online Practice 2023 B

View Set

Chapter 21: The Lymphatic and Immune system

View Set

Meta Poetry: Poetry about Poetry (Assignment)

View Set

Developmental psych 10, 12, 14, 15, 17

View Set