Solution Manual for C++ How to Program: Late Objects Version, 7th Edition

Preview Extract
C++ How to Program, 7/e Multiple Choice Test Bank Chapter 2: Introduction to C++ Programming Section 2.2 First Program in C++: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using: a. Two forward slashes ( // ). b. Three forward slashes ( /// ). c. A slash and a star ( /* ). d. A slash and two stars ( /** ). ANS: a. Two forward slashes ( // ). 2.2 Q2: Which of the following statements does not cause a syntax error to be reported by the C++ compiler? a. Mismatched {}. b. Missing */ in a comment. c. Missing ; at the end of a statement. d. Extra blank lines. ANS: d. Extra blank lines. 2.2 Q3: Which of the following is not a syntax error? a. std::cout << 'Hello world! '; b. std::cout << "Hello world! "; c. std::cout << "Hello world! "; d. std::cout << Hello world!; ANS: c. std::cout << "Hello world! "; 2.2 Q4: The escape sequence for a newline is: a. n b. t c. r d. a ANS: a. n 2.2 Q5: Which of the following statements would display the phrase C++ is fun? a. std::cout << "Thisis funrC++ "; b. std::cout << '++ is fun'; c. std::cout << ""C++ is fun""; d. std::cout << C++ is fun; ANS: a. std::cout << "Thisis funrC++ "; Section 2.3 Modifying Our First C++ Program 2.3 Q1: Which of the following is not a valid C++ identifier? a. my Value b. _AAA1 c. width d. m_x ANS: a. my Value (Identifiers may not contain blanks) 2.3 Q2: Which is the output of the following statements? std::cout << "Hello "; std::cout << "World"; ยฉ Copyright 1992-2011 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved. 1 of 4 C++ How to Program, 7/e Multiple Choice Test Bank 2 of 4 a. b. c. Hello World World Hello Hello World d. World Hello ANS: a. Hello World 2.3 Q3: Which of the following is the escape character? a. * b. c. n d. โ€œ ANS: b. 2.3 Q4: Which of the following code segments prints a single line containing hello there with the words separated by a single space? a. std::cout << "hello "; std::cout << " there"; b. std::cout << "hello" , " there"; c. std::cout << "hello"; std::cout << "there"; d. std::cout << "hello"; std::cout << " there"; ANS: d. std::cout << "hello"; std::cout << " there"; Section 2.4 Another C++ Program: Adding Integers 2.4 Q1: Which of the following is a variable declaration statement? a. int total; b. #include c. int main() d. // first string entered by user ANS: a. int total; 2.4 Q2: The ________ object enables a program to read data from the user. a. std::cout. b. std::cin. c. std::cread. d. std::cget. ANS:b. std::cin. 2.4 Q3: The assignment operator ________ assigns the value of the expression on its right to the variable on its left. a. c. = d. # ANS: c. =. 2.4 Q4: The std::endl stream manipulator________. a. inputs a newline. b. flosses the output buffer. c. outputs a newline and flushes the output buffer. ยฉ Copyright 1992-2011 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved. C++ How to Program, 7/e Multiple Choice Test Bank d. terminates the program. ANS: c. outputs a newline and flushes the output buffer. Section 2.5 Memory Concepts 2.5 Q1: Which of the following statements does not overwrite a preexisting value stored in a memory location? a. int a; b. number = 12; c. y = y + 2; d. width = length; ANS: a. int a; 2.5 Q2: Which of the following statements could potentially change the value of number2? a. std::cin >> number2; b. sum = number1 + number2; c. number1 = number2; d. std::cout <> number2; Section 2.6 Arithmetic 2.6 Q1: What is the value of result after the following C++ statements execute? int a, b, c, d, result; a = 4; b = 12; c = 37; d = 51; result = d % a * c + a % b + a; a. 119 b. 51 c. 127 d. 59 ANS: a. 119. 2.6 Q2: In what order would the following operators be evaluated -, *, /, +, % Assume that if two operations have the same precedence, the one listed first will be evaluated first. a. +, -, /, *, % b. -, +, %, *, / c. -, *, %, +, / d. *, /, %, -, + ANS: d. *, /, %, -, + 2.6 Q3: Which of the following is not an arithmetic operator? a. + b. c. = d. % ANS: c. = ยฉ Copyright 1992-2011 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved. 3 of 4 C++ How to Program, 7/e Multiple Choice Test Bank Section 2.7 Decision Making: Equality and Relational Operators 2.7 Q1: What will be the output after the following C++ statements have been executed? int a, b, c, d; a = 4; b = 12; c = 37; d = 51; if ( a < b ) cout << "a < b" < b ) cout < b” << endl; if ( d <= c ) cout << "d <= c" << endl; if ( c != d ) cout << "c != d" << endl; a. a < b c != d b. a < b d b c != d d. a < b c < d a != b ANS: a. a < b c != d 2.7 Q2: Which of the following is a compilation error? a. Placing a space between the symbols in the <= operator. b. Using a triple equals sign instead of a double equals sign in the condition of an if statement. c. Omitting the left and right parentheses for the condition of an if statement. d. All of the above. ANS: d. All of the above. 2.7 Q3: Each of the following is a relational or equality operator except: a. ANS: b. =! ยฉ Copyright 1992-2011 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved. 4 of 4

Document Preview (4 of 24 Pages)

User generated content is uploaded by users for the purposes of learning and should be used following SchloarOn's honor code & terms of service.
You are viewing preview pages of the document. Purchase to get full access instantly.

Shop by Category See All


Shopping Cart (0)

Your bag is empty

Don't miss out on great deals! Start shopping or Sign in to view products added.

Shop What's New Sign in