CS 1336 EXAM 1 CHAPTER 4

¡Supera tus tareas y exámenes ahora con Quizwiz!

When a relational expression is false, it has the value

0

What is assigned to the variable resultgiven the statement below with the following assumptions:x = 10, y = 7, andx, result,andyare all int variables. result = x >= y;

1

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

1

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

12

After the following code executes, what is the value of my_valueif the user enters 0? cin >> my_value; if (my_value > 5) my_value = my_value + 5; else if (my_value > 2) my_value = my_value + 10; else my_value = my_value + 15;

15

The __________ is an equality (or comparison) operator.

==

The conditional operator takes two operands.

False

The defaultsection is required in a switchstatement.

False

The following code correctly determines whether xcontains a value in the range of 0through 100, inclusive. if (x > 0 && <= 100)

False

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

This is true! That's all folks

An expression that has any value other than 0is considered trueby an if statement.

True

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

True

If the expression on the left side of the following is false, the expression on the right side will not be checked. (a > = b) && (c == d)

True

If the expression on the left side of the following is true, the expression on the right side will not be checked. (a > = b) || (c == d)

True

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

True

What is the output of the following code segment if the user enters 90for the score? cout << "Enter your test score: "; cin >> test_score; if (test_score < 60) cout << "You failed the test." << endl; if (test_score > 60) cout <<"You passed the test." else cout << "You need to study harder next time." << endl;

You passed the test

Input values should always be checked for

a. an appropriate range b. reasonableness c. division by zero, if division is taking place

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

break

Relational operators allow you to __________ numbers.

compare

After the following code executes, what is the output if user enters 0? int x = -1; cout << "Enter a 0 or 1: "; cin >> x; if (c)cout << "true" << endl; elsecout << "false" << endl;

false

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

false

A variable, usually a bool or an int, that signals when a condition exists is known as a(n)

flag

When a 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

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

nesting

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

relational expression

This statement uses the value of a variable or expression to 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

The defaultsection of a switchstatement performs a similar task similar to the __________ portion of an if/elseifstatement.

trailing else

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

true

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

true

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

true

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

x <= y

This operator represents the logical OR:

||

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

!

Which of the following is evaluated first, given the expression: A && B || C && !D

!D

This operator represents the logical AND:

&&


Conjuntos de estudio relacionados

Bio 142 - Exam 6 (Chapter 28 - Reproductive System)

View Set

Chapter 1.1 - Points, Lines, Planes, Rays and Line Segments

View Set

History of Graphic Design Unit 2

View Set

MLBT1080 Important Professionalism Topics Assignment

View Set

Chapter 15.4 - Countries of Central America

View Set

Marketing Research Chapters 1-5 Exam

View Set

Chapter 6: The acquisition of memories and the working-memory system

View Set

Security Operations and Monitoring

View Set