Starting out with C++ From control Structures through Objects Ninth Edition - Chapter 1 - 4, Midterm test

Ace your homework & exams now with Quizwiz!

What is the value of donuts after the following code executes? 12 10 0 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 10 0 2

12

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; 0 1 2 3 None of these

3

A statement that starts with a # is called a comment True False

False

Floating point constants are normally stored in memory as doubles True False

True

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

True

when using the equality operator to compare integer values there will be potential round-off errors. True False

True

When a program lets the user know that an invalid choice has been made, this is known as: input validation output correction compiler criticism output validation None of these

input validation

When an if statement is placed within the conditionally-executed code of another if statement, this is known as: complexity overloading nesting validation None of these

nesting

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement. conditional break trailing else All of these None of these

trailing else

What is the value of the following expression? true && true true false -1 +1

true

When a relational expression is false, it has the value ________. one zero zero, one, or minus one less than zero None of these

zero

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; } 98 99 0 1

1

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; 7 15 0 0 10 10 1 1 None of these

1 1

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 100: "; 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; 0 3 13 28 None of these

13

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 10 25 0 5

15

What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2; 13 18 0 None of the above

18

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. x >= 8; 6. x >= 0; 7. x <= (y*2); 3, 4, 6, 7 are false. Only 5 is false. 3 and 4 are false. All are false. None of these

3 and 4 are false.

Which line in the following program will cause a compiler error? 1 #include <iostream> 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 } 6 8 10 9

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 not acceptable.\n"; 100 10 99 0 All of these

99

Input values should always be checked for: appropriate range reasonableness division by zero, if division is taking place All of these None of these

All of these

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 "; cour << "fun" << endl; C++ is fun Soccer is fun C++ C++fun Soccerfun

C++

If you use a C++ key word as an identifier, your program will compile, link, but not execute. True False

False

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

False

Which of the following is not one of the five major components of a computer system? Preprocessor CPU Main memory I/O devices Secondary Storage

Preprocessor

What will following segment of code output? int x = 5; if(x = 2) cout << "This is true!" << endl; esle cout << "This is false!" << endl; cout << "This is all folks!" << endl; This is true! This is false! This is true! This is false! This is true! This is all folks! None of these

This is true! This is all folks!

An example of a secondary storage device is a hard drive True False

True

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

True

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

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 False

True

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

True

The following code correctly determines whether x contains a value out of the range of 0 through 100. if (x < 0 || x> 100) True False

True

Variables need to be declared before they can be used. True False

True

_____________ represent storage locations in the computer's memory Literal Variable Comments Integers None of the above

Variable

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

answer = 1

In C++ the = operator indicates: equality assignment subtraction negation None of these

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 exit switch scope None of these

break

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; Nothing will be displayed. false x true

false

If you place a semicolon after the statement if (x < y) the code will not compile the compiler will interpret the semicolon as a null statement the if statement will always evaluate to false All of these None of these

the compiler will interpret the semicolon as a null statement

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

x <= y


Related study sets

Lung Cancer and Thoracic Surgery

View Set

american history (US imperialism)

View Set

Biology Chapter 1 Quiz: Exploring Life and Science

View Set