Computer Programming: Chapter 4

Ace your homework & exams now with Quizwiz!

This operator performs a logical NOT operation.

!

This operator represents the logical AND.

&&

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

0 1 1 0

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

12

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;

13

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

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)

3 and 4 are False

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

What will the following segment of code output if 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << " is "; cout << "fun" << endl;

C++ is fun

The default section is required in a switch statement.

False

What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;

False

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

Relational expression

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

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

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

True

Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer = " << (x || !y && z) << endl;

answer = 1

In C++ the = operator indicates

assignment

Relational operators allow you to ____________ numbers.

compare

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

false

What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl;

false

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

flag

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?

if (code == 'C') cout << "This is a check\n";

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

input validation

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

switch

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

true


Related study sets

Quiz: Administering a Tube feeding

View Set

Exam 2 WE-1-DP Electricity 120102b

View Set

A&P-Musculoskeletal and Integumentary Systems

View Set

Unit 3: Membrane Structure and Function

View Set

Microbiology Ch. 1: The Main Themes of Microbiology

View Set