ch03

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

True/False: When a C++ expression is evaluated, binary operations are performed before unary operations.

FALSE

True/False: When an operator has two operands of different data types, C++ always converts them both to double before performing the operation.

FALSE

The ________ object causes data to be input from the keyboard. A) cin B) cout C) keyboard buffer D) standard input E) dataIn

A

The following 4 lines of C++ code, use strings. string firstName; // Define a string object char lastName[7]; // Define a C-string firstName = "Abraham"; // Assign a value to the string object lastName = "Lincoln"; // Assign a value to the C-string Which of the following statements is true? A) The string object is defined incorrectly because no size is given for it. B) The 2 string definitions are correct, but the 2 assignment statements are wrong. C) The string object is assigned a value correctly, but the C-string is not. D) The C-string is assigned a value correctly, but the string object is not. E) All 4 lines of code are correct.

C

To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program. A) iostream B) iomanip C) cmath D) algebra E) mathlib

C

When the final value of an expression is assigned to a variable, it will be converted to ________. A) the smallest possible data type B) the largest possible data type C) the data type of the variable D) the data type of the expression E) None of the above

C

In C++, a value can be raised to a power by using ________. A) the ^ operator B) the exp operator C) the power operator D) the pow function E) the square function

D

In any program that uses the cin object, you must #include ________. A) the iostream header file. B) the fstream header file. C) >> and << operators. D) named constants. E) None of the above.

A

Which of the following will allow an entire line of text to be read into a string object, even if it contains embedded blanks? A) getline() B) cin >> C) cin.get() D) cin.ignore() E) both A and B

A

When an arithmetic expression contains two or more different operators, such as * and +, the order in which the operations is done is determined by ________. A) left to right order B) operator precedence C) operator associativity D) the programmer E) the compiler

B

________ can be used to override the rules of operator precedence. A) Some operators B) Parentheses C) Operands D) Associativity E) Nothing

B

________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed. A) An input device B) The cin object C) The cout object D) A preprocessor E) Nothing

B

Operator associativity is either left to right or ________. A) top to bottom B) front to back C) right to left D) inside to outside E) nothing else; it is always left to right

C

The ________ operator always follows the cin object, and the ________ operator follows the cout object. A) input, endl B) getChar, printChar C) >> , << D) >> , >> E) << , >>

C

The ________ stream manipulator can be used to establish a field width for the value immediately following it. A) cin B) setField C) setw D) iomanip E) width

C

The cin object must be followed by ________. A) a single stream insertion (<<) operator B) one or more stream insertion operators (<<) C) a single stream extraction (>>) operator D) one or more stream extraction (>>) operators E) no operators.

D

To use stream manipulators, you should include the ________ header file. A) stream B) fstream C) format D) iomanip E) iostream

D

What does the following C++ expression evaluate to? 6 - 6 / 3 + 3 A) 0 B) 1 C) 3 D) 7 E) None of the above

D

When converting some algebraic expressions to C++, you may need to insert ________ and ________ that do not appear in the algebraic expression. A) values, exponents B) operators, calculations C) operators, operands D) operators, parentheses E) operands, parentheses

D

Program code that can be evaluated to a value is called a(n) ________. A) operation B) line C) evaluator D) result E) expression

E

The statement cout << setw(4) << num4 << " "; ________. A) outputs the value of num4 rounded to 4 decimal places. B) outputs "setw(4)" before the value in the variable num4. C) outputs the first 4 digits of the number stored in num4. D) outputs the value stored in num4 four times. E) does none of above.

E

Which of the following expressions will evaluate to 2.5? A) static_cast<double>(5 / 2) B) static_cast<double>(5) / 2 C) 5 / static_cast<double>(2) D) All three of the above E) Both B and C, but not A

E

Which of the following statements about named constants is/are true? A) A named constant must be initialized with a value at the time it is declared. B) The identifier name of a named constant can only contain capital letters and underscores. C) The initial value of a named constant, cannot be changed during the program execution. D) All 3 of the above statements are true. E) Statements A and C are true, but B is not.

E

Which of the following statements doubles the value stored in answer? A) answer += 2; B) answer *= 2; C) answer = answer * 2; D) All three of the above E) Both B and C, but not A

E

Before a program can read data from a file, which of the following must be true? A) The file must exist and data to be read from it must have been previously stored in it. B) There must be a #include <fstream> directive in the program. C) The program must define a file stream object to associate with the file. D) The file must be opened. E) All the above statements must be true.

E Chapter 3, Test 2

True/False: If the value of dollars is 5.0, the following statement will output 5.00 to the monitor: cout << fixed << showpoint << setprecision(4) << dollars << endl;

FALSE

True/False: In C++, the 5 basic arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).

FALSE

True/False: The cin object lets the user enter a string that contains embedded blanks.

FALSE

True/False: The following C++ statement will assign 1.5 to the result variable. int result = 3.0 / 2.0;

FALSE

True/False: The following pair of C++ statements is legal. const double taxRate; taxRate = .05;

FALSE

True/False: The following statement sets the value of total to -3. total -= 3;

FALSE

True/False: The following two C++ statements will cause 3.5 to be output. double number = 7 / 2; cout << number;

FALSE

True/False: The only difference between C-strings and string objects is how they are declared and internally stored. They are used exactly the same way.

FALSE

True/False: The setw manipulator is used to set the precision of a number.

FALSE

True/False: The cin object can be used to input more than one value in a single statement.

TRUE

True/False: The following statement sets sum1, sum2, and sum3 all to zero. sum1 = sum2 = sum3 = 0;

TRUE

True/False: The following two expressions evaluate to the same thing: c + a * b c + (a * b)

TRUE

True/False: The following two statements will assign the same value to answer. answer = a * b / c; answer = b / c * a;

TRUE

True/False: The following two statements will assign the same value to result. result = a + b * c; result = b * c + a;

TRUE

True/False: When an operator's operands are of different data types, such as int and double, C++ automatically converts one of them so that they are the same data type.

TRUE


Ensembles d'études connexes

Маймылдардың пайда болуы 11 кл.

View Set

History and Systems Exam 1 (Chapters 1-4)

View Set

NATIONAL QUIZ BANK "Forms of Ownership"

View Set

Questions and Vocabulary from Martin Luther King Jr.'s letter from Birmingham Jail

View Set

Econ Test 3 - Inflation, Unemployment, and Discretionary Fiscal Policy

View Set