CS Unit 2

Ace your homework & exams now with Quizwiz!

How many times will the following loop display "Hello"? For ( int i = 20; i > 0; i—) Cout << "Hello!" << endl;

20

How many times will the following loop display "Hello"? for ( int I =0; I <= 20; I++) cout << "Hello!" << endl;

21

What will the following code display? int number = 40; number++; cout << ++number << endl;

42

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

scope

What is the output of the following code segment? n=1; while (n != 5) cout << n << ' '; n++;

1 1 1 1 1 1 1...

How many times will the following loop display "Hello"? for (int I = 0; I < 20; I++) cout << "Hello!" << endl;

20

What will the following code display? int number = 42; cout << number++ << endl;

42

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;

1 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 the following code display? int x =0; for (int count =0; count <= 5; count ++) { x += count; } cout << x << endl;

15

What will the following code display? int number = 42; cout << ++number << endl;

43

What is the output of the following segment of code if 4 is input by the user when asked to enter a number?

9

Type the operator that performs the "less than" comparison

<

Type the operator that performs the pleas than or equal to" comparison

<=

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

Consider the following code: int x = 5; int y = 6; int z = 8; Is the following expression true or false? x >= 0 && x <= y

False

Consider the following code: int x = 5; int y = 6; int z = 8; Is the following expression true or false? 7 <= x && z > 4

False

The body of a while loop will be executed at least once

False

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

False

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

You may not use the break statement in a nested loop

False

A loop that has no way of stopping is a/an

Infinite loop

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

Input validation

A loop in which the body is executed at least once is a/an

Post-test loop

A loop in which the test expression is evaluated after each repetition is a/an

Post-test loop

The while loop is considered to be a/an

Pre test loop

The for loop is considered to be a/an

Pre-test loop

The for-loop is considered to be a/an

Pre-test loop

The while loop is an example of a/an

Pre-test loop

When a continue statement is encountered in a for loop, control is transferred to

The loop update block

When the break statement is encountered in a for loop, control is transferred to

The statement following the end of the for loop

int x == 5; if (x == 2) cout << "This is true!" << endl; Else cout << "This is false!" << endl;

This is false!

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

This is true!

A do/while loops body can contain multiple statements, as long as they are enclosed in braces.

True

A for loops body can contain multiple statements, as long as they are enclosed in braces

True

A while loop's body can contain multiple statements, as long as they are enclosed in braces.

True

An expression that has any value other than 0 is considered true by an if statement

True

An initialization expression may be omitted from the for loop if no initialization is required.

True

An output file is a file that data is written to.

True

As a rule of style, when writing an if statement you should indent the conditionally- executed statements, and enclose those statements in curly braces.

True

Consider the following code: int x = 5; int y = 6; int z = 8; Is the following expression true or false? x == 5 || y > 3

True

Consider the following code: int x = 5; int y = 6; int z = 8; Is the following expression true or false? x >= 0 && x <= y

True

Consider the following code: int x = 5; int y = 6; int z = 8; Is the following expression true or false? 2 != y && z != 4

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

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

True

If you want to stop a loop before it goes through all it's iterations, the break statement may be used

True

It is possible to define a file stream object and open the file in one statement

True

The body of a do/while loop will be executed one or more times

True

The scope of a variable declared in a for loop's initialization expression is limited to the body of the loop.

True

What is the outcome of the following expression? Your choices are true, false, 0, 1 or error ( 6 > 5) || ( 2 / 0)

True

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

True

You should not use the equality operator == to compare gloating point values.

True

x != y is the same as (x > y || x < y)

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

You failed the test! You passed the test!

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.

Which of these is a post test loop?

do/while

Single line if statement about grade invalid

if ( grade < 0 || grade > 100) cout << "This grade is invalid!" << endl;

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

A programmer must add 1 to the value stored in the int variable sum. One way is given to get you started. Write two more distinct ways to add 1 to the value stored in sum sum = sum + 1; // adding 1 to the sum

sum += 1; sum++;

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

x <= y

When a relational expression is false, it has the value ________.

zero

What 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 not acceptable.\n";

All of these

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 not acceptable. \n";

All of these

Which of these are pretest loops?

For, while

While (true) { . . . } is one way to deliberately write a/an

Infinite loop

The do / while loop is considered to be a/an

Post-test loop

The do/while loop is an example of a/an

Post-test loop

When the break statement is encountered in a do/while loop, control is transferred to

The statement following the end of the do/while loop

What is the outcome of the following expression? Your choices are true, false, 0, 1, or error -5 + -1 == -(2*3)

True

What is the outcome of the following expression? Your choices are true, false, 0, 1, or error 12 > 1

True

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

True

What is the value of the following expression? true && ( false || true )

True


Related study sets

The Fourteenth Amendment / Instruction / Assignment

View Set

Chapter 19: Implementing Nursing Care

View Set

Chapter 17: Troubleshooting Operating Systems

View Set

Tissues and their structures / locations

View Set

FORD CH35: Antianginal and Vasodilating Drugs

View Set

Florida statutes, rules, and regulations

View Set

US Government and Civics - Khan Academy

View Set

Research Methods in Psychology Ch 6 Exam

View Set

Chapter 3: The Relational Database Model

View Set