ITSC Chapter 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

This operator performs a logical NOT operation:

!

This operator takes an operand and reverses its truth or falsehood:

!

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

0

What will the following program display? #include <iostream> 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 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;

1

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 the value 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;

28

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;

3

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

Input values should always be checked for:

Appropriate range, reasonableness, division by 0.

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;

C++ is fun

Relational operators allow you to _______ numbers.

Compare

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

answer = 1

True/false: The default section is required in a switch statement

false The default section is *OPTIONAL* in a switch statement

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

True/false: Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0.15; if (sales > 10000) commissionRate = 0.15;

true

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

true

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

true

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

true

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

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

Nesting

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

Relational expression

True/false: If the sub-expression of the left side of the || operator is true, the expression on the right side will not be checked.

True

In C++ the = operator indicates:

assignment

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

break

This operator represents the logical AND:

&&

Which line in the following program will cause a compiler error? #include <iostream> using namespace std; int main( ) { int number = 5; if (number >=0 && <= 100) cout << "passed.\n"; else cout << "failed.\n"; return 0; }

8

Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable. \n"; else cout << "That number is acceptable. \n";

99 (since it's between 11 and 99)

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

Curly braces { }

This is a variable, usually a bool or an int, that signals when a condition exists.

Flag

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

The compiler will intercept the semicolon as a null statement

True/false: An expression that has any value other than 0 is considered true by an if statement.

True

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

You failed the test! You passed the test!

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

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

input validation

These operators connect two or more relational expressions into one, or reverse the logic of an expression:

logical

This statement used the value of a variable or expression to determine where the program will branch to:

switch

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

trailing else

Which of the following expressions will determine whether x is less than or equal to y?

x <= y

This operator is known as the logical OR operator:

||

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

15

This operator is used in C++ to represent equality

==

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;

That's a high score This is a test question!

What is the output of the following code segment? int x = 5; if (x = 2) cout << "This is true" << endl; else cout << "This is flase!" << endl; cout << "This is all folks!" << endl;

This is true! This is all folks!

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

scope


Kaugnay na mga set ng pag-aaral

Reading Guides 26.2 and 26.3 - Economies

View Set

Chapter 21 Respiratory Emergencies PrepU

View Set

Descriptive Statistics - Measures of Central Tendency & Dispersion

View Set

Chapter 10 - Organizational Change & Innovation

View Set

2.04 Quiz: Review of Equations 6

View Set

test yourself ch6 cont cont cont cont

View Set

Endocrine System (Addison's & Cushing's)

View Set

Student Success for Health Professionals Midterm Review Ch 1,2,4,5,6,9

View Set

C429 Healthcare Operations Management WGU

View Set

Unit 3 (Basics of P&C Insurance)

View Set