C++, Chpt 2, 3, 4

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

____ are executable statements that inform the user what to do.

prompt lines

Suppose that x is an int variable, y is a double variable, and z is an int variable. The input is: ​ 15 76.3 14 ​ Choose the values after the following statement executes: ​ cin >> x >> y >> z;

x = 15, y = 76.3, z = 14

Suppose that x and y are int variables, and z is a double variable. The input is: ​ 28 32.6 12 ​ Choose the values of x, y, and z after the following statement executes: ​ cin >> x >> y >> z;

x = 28, y = 32, z = 0.6

What is the output of the following C++ code? int x = 55; int y = 5; switch (x % 7) { case 0: case 1: y++; case 2: case 3: y = y + 2; case 4: break; case 5: case 6: y = y - 3; } cout << y << endl;

2

What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl;

35 45 10

In C++, && has a higher precedence than ||.

true

Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.

true

For a program to use the assert function, it must include which of the following?

#include <cassert>

____ is a valid char value.

'A'

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ What is the value of ch3 after the following statements execute? ​ cin.get(ch1); cin.get(ch2); cin.get(ch3);

'B'

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​ Choose the value of ch3 after the following statement executes: ​ cin >> ch1 >> ch2 >> ch3;

'C'

Suppose that x is an int variable. Which of the following expressions always evaluates to true?

(x > 0) || ( x <= 0)

Which of the following expressions correctly determines that x is greater than 10 and less than 20?

10 < x && x < 20

What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl;

12345678901234567890 ***18**Happy**Sleepy

What is the output of the following statements? cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl;

123456789012345678901234567890 ####Mickey Donald*****Goofy

The expression static_cast<int>(6.9) + static_cast<int>(7.9) evaluates to ____.

13

Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3) << x << ' '; cout << setprecision(4) << y << ' ' << setprecision(2) << z << endl

1565.683 85.7800 123.98

The length of the string "computer science" is ____.

16

Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;.

2

Suppose that count is an int variable and count = 1. After the statement count++; executes, the value of count is ____.

2

Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl;

25.67 356.88 7623.97

The value of the expression 17 % 7 is ____.

3

The value of the expression 33/10, assuming both values are integral data types, is ____.

3

Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120 200 210 220 300 310 320 What is the value of gamma after the following statements execute? cin >> alpha; cin.ignore(100, '\n'); cin >> beta; cin.ignore(100,'\n'); cin >> gamma;

300

What is the value of x after the following statements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4

4

____ is a valid int value.

46259

Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(3); cout << x << ' ' << y << ' ' << setprecision(2) << z << endl;

55.680 476.859 23.82

The expression static_cast<int>(9.9) evaluates to ____.

9

Which of the following operators has the lowest precedence?

=

Which of the following is a relational operator?

==

The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are int variables.) cin >> x; cin >> y;

FAlse

A mixed arithmetic expression contains all operands of the same type.

False

In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device.

False

In the statement cin >> x;, x can be a variable or an expression.

False

It is a good idea to redefine cin and cout in your programs.

False

The result of a logical expression cannot be assigned to an int variable, but it can be assigned to a bool variable.

False

The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.

False

You can use the function getline to read a string containing blanks.

True

Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl;

Sunny Day

Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x;

Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x;

Suppose that x and y are int variables, ch is a char variable, and the input is: 4 2 A 12 Choose the values of x, y, and ch after the following statement executes: cin >> x >> ch >> y;

This statement results in input failure

A control structure alters the normal sequential flow of execution in a program.

True

Entering a char value into an int variable causes serious errors, called input failure.

True

In C++, the operators != and == have the same order of precedence.

True

Suppose a = 5. After the execution of the statement ++a; the value of a is 6.

True

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin.get(ch1); cin.putback(ch1); cin >> ch2;

W

Suppose that ch1 and ch2 are char variables and the input is: WXYZ What is the value of ch2 after the following statements execute? cin >> ch1; ch2 = cin.peek(); cin >> ch2;

X

Which of the following is the newline character?

\n

Which of the following is the "not equal to" relational operator?

!=

Which of the following operators has the highest precedence?

!

You can disable assert statements by using which of the following?

#define NDEBUG

Suppose that x is an int variable, y is a double variable, and ch is a char variable. The input is: ​ 15A 73.2 ​ Choose the values after the following statement executes: ​ cin >> x >> ch >> y;

a. x = 15, ch = 'A', y = 73.2

Suppose that alpha is an int variable and ch is a char variable. The input is: ​ 17 A ​ What are the values after the following statements execute? ​ cin >> alpha; cin >> ch;

alpha = 17, ch = 'A'

Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____.

alpha = 50

Suppose that alpha and beta are int variables. The statement alpha = beta++; is equivalent to the statement(s) ____.

alpha = beta; beta = beta + 1;

Suppose that alpha and beta are int variables. The statement alpha = beta--; is equivalent to the statement(s) ____.

alpha = beta; beta = beta - 1

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.

ignore

Suppose that alpha and beta are int variables. The statement alpha = ++beta; is equivalent to the statement(s) ____.

beta = beta + 1; alpha = beta;

Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____.

beta = beta - 1; alpha = beta;

Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is: ​ A 18 ​ What are the values after the following statement executes? ​ cin.get(ch1); cin.get(ch2); cin >> alpha;

ch1 = 'A', ch2 = ' ', alpha = 18

Which of the following is a reserved word in C++?

char

Suppose that x and y are int variables. Which of the following is a valid input statement?

cin >> x >> y;

An example of a floating point data type is ____.

double

A comma is also called a statement terminator.

false

An operator that has only one operand is called a unique operator.

false

If input failure occurs in a C++ program, the program terminates immediately and displays an error message.

false

If the expression in an assert statement evaluates to true, the program terminates.

false

In C++, both ! and != are relational operators.

false

In C++, reserved words are the same as predefined identifiers.

false

The escape sequence \r moves the insertion point to the beginning of the next line.

false

The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100.

false

The operators !, &&, and || are called relational operators.

false

The memory allocated for a float value is ____ bytes.

four

Which of the following will cause a logical error if you are attempting to compare x to 5?

if (x = 5)

ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4?

inFile.open("progdata.dat");

The declaration int a, b, c; is equivalent to which of the following?

int a,b,c

You can use either a(n) ____ or a ____ to store the value of a logical expression.

int, bool

Manipulators without parameters are part of the ____ header file.

iostream

What does <= mean?

less than or equal to

​In C++, the dot is an operator called the ____ operator.

member access

When one control statement is located within another, it is said to be ____.

nested

In a C++ program, one and two are double variables and input values are 10.5 and 30.6. After the statement cin >> one >> two; executes, ____.

one = 10.5, two = 30.6

Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out. Which of the following statements opens the file outputData.out and associates outFile to the output file?

outFile.open("outputData.out");

Which of the following is a legal identifier?

program_1

What is the output of the following code? char lastInitial = 'S'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl;

section 5

In a ____ control structure, the computer executes particular statements depending on some condition(s).

selection

____ is a parameterized stream manipulator.

setfill

Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____.

sum = 15

The ____ rules of a programming language tell you which statements are legal, or accepted, by the programming language.

syntax

A compound statement functions as if it was a single statement.

true

If a C++ arithmetic expression has no parentheses, operators are evaluated from left to right.

true

Suppose we declare a variable sum as an int. The statement " sum += 7; " is equivalent to the statement " sum = sum + 7; " .

true

Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y)

true

The maximum number of significant digits in float values is up to 6 or 7.

true

The maximum number of significant digits in values of the double type is 15.

true

The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement.

true

When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character.

true

Suppose that x is an int variable and y is a double variable. The input is: ​ 10 20.7 ​ Choose the values after the following statement executes: cin >> x >> y;

x = 10, y = 2.7


Kaugnay na mga set ng pag-aaral

Accounting multiple choice chapter 10

View Set

Macroeconomics Long-Run Economic Growth Quiz

View Set