Test Bank for Starting Out with C++ from Control Structures to Objects, 9th Edition
Preview Extract
Starting Out with C++ from Control Structures to Objects, 9e (Gaddis)
Chapter 2 Introduction to C++
TRUE/FALSE
1. The preprocessor reads a program before it is compiled and only executes those lines beginning with #
symbol.
ANS: T
2. Because C++ is case-sensitive, all programs must have a function called main or Main.
ANS: F
3. In programming, the terms “line” and “statement” always mean the same thing.
ANS: F
4. In C++, key words are written in all lowercase letters.
ANS: T
5. The preprocessor executes after the compiler.
ANS: F
6. A value is stored in a variable with an assignment statement.
ANS: T
7. Programming style refers to the way a programmer uses elements such as identifiers, spaces, and blank
lines.
ANS: T
8. When typing your source code into the computer, you should be careful since most of your C++
instructions, header files, and variable names are case sensitive.
ANS: T
9. In C++ you are required to name your variables so they indicate the purpose they will be used for.
ANS: F
10. Escape sequences are always stored internally as a single character.
ANS: T
11. Floating point constants are normally stored in memory as doubles.
ANS: T
12. C++ does not have a built-in data type for storing strings of data.
ANS: T
13. A named constant is like a variable, but it its content cannot be changed while the program is running.
ANS: T
14. C++ 11 introduced an alternative way to define variables, using the template key word and an
initialization value.
ANS: F
MULTIPLE CHOICE
1. In a C++ program, two slash marks (//) indicate
a.
b.
c.
d.
e.
the end of a statement
the beginning of a comment
the end of a program
the beginning of a block of code
None of these
ANS: B
2. A statement that starts with a hashtag (or pound) symbol (#) is called a
a.
b.
c.
d.
e.
comment
function
preprocessor directive
header file
None of these
ANS: C
3. For every opening brace ({) in a C++ program, there must be a
a.
b.
c.
d.
e.
string literal
function
comment
closing brace
None of these
ANS: D
4. The __________ is(are) used to display information on the computer’s screen.
a. opening and closing braces
b. opening and closing quotation marks
c. cout object
d. backslash
e. None of these
ANS: C
5. In the following statement, the characters Hello! are a(n)
cout << "Hello!";
a.
b.
c.
d.
e.
variable
string literal
comment
object
None of these
ANS: B
6. The __________ causes the content of another file to be inserted into a program.
a.
b.
c.
d.
e.
cout object
double slash (//)
#include directive
semicolon (;)
None of these
ANS: C
7. Which of the following must be included in any program that uses the cout object?
a.
b.
c.
d.
e.
opening and closing braces
the header file iostream
comments
a namespace
None of these
ANS: B
8. Character constants in C++ are always enclosed in
a.
b.
c.
d.
e.
brackets ( )
braces ( { } )
single quotation marks ( ‘ ‘ )
pound sign and semicolon ( # ; )
Any of these
ANS: C
9. Every complete C++ program must have a
a.
b.
c.
d.
e.
comment
function named main
symbolic constant
cout statement
None of these
ANS: B
10. In a cout statement, which of the following will advance the output position to the beginning of the
next line?
a.
b.
c.
d.
e.
endl or n
end1 or /n
n or t
t or b
\ or ‘
ANS: A
11. What will the following code display?
cout << "Monday";
cout << "Tuesday";
cout << "Wednesday";
a. Monday
Tuesday
Wednesday
b. Monday Tuesday Wednesday
c. MondayTuesdayWednesday
d. "Monday"
"Tuesday"
"Wednesday"
e. "Monday" "Tuesday" "Wednesday"
ANS: C
12. What will the following code display?
int number = 23;
cout << "The number is " << "number" << endl;
a.
b.
c.
d.
e.
The number is 23
The number is23
The number is number
The number is null
The number is
ANS: C
13. What will the following code display?
cout << "Fourn" << "scoren";
cout << "and" << "nseven";
cout << "nyears" << " ago" << endl;
a. Four
score
and
seven
years ago
b. Four score and seven
years ago
c. Four
score
and seven
years ago
d. Four score
and seven
years ago
ANS: A
14. What will the following code display?
cout << "Roses " << "are red";
cout << "and " << "violets/n"
cout << "are" << "blue" << endl;
a. Roses are red
and violets
are blue
b. Roses are red and violets/nare blue
c. Roses are redand violets/nareblue
d. Roses are red and violets/n are blue
ANS: C
15. Which control sequence is used to skip over to the next horizontal tab stop?
a.
b.
c.
d.
e.
n
end1
t
b
'
ANS: C
16. A(n) __________ represents a storage location in the computer's memory.
a.
b.
c.
d.
e.
literal
variable
comment
integer
None of these
ANS: B
17. Data items whose values do not change while the program is running are
a.
b.
c.
d.
e.
literals
variables
characters
integers
None of these
ANS: A
18. A variable definition tells the computer
a.
b.
c.
d.
the variable's name and its value
the variable's data type and its value
the variable's name and the type of data it will hold
whether the variable is an integer or a floating-point number
e. None of these
ANS: C
19. You must have a _____________ for every variable you intend to use in a program.
a.
b.
c.
d.
e.
purpose
variable definition
memory space
literal value
None of these
ANS: B
20. Which of the following is not a valid C++ identifier?
a.
b.
c.
d.
e.
April2018
employee_number
_1user
1user
theLittleBrownFoxWhoRanAway
ANS: D
21. What will the following code display?
int x = 23, y = 34, z = 45;
cout << x << y << z << endl;
a. 23 34 45
b. 23
34
45
c. xyz
d. 233445
ANS: D
22. The numeric data types in C++ can be broken into two general categories which are
a.
b.
c.
d.
e.
numbers and characters
singles and doubles
integers and floating-point numbers
real and unreal numbers
numbers and literals
ANS: C
23. Besides the decimal number system that is most common (base 10), two other number systems that can
be used in C++ programs are
a.
b.
c.
d.
e.
octal and fractal
octal and hexadecimal
base 2 and base 4
base 2 and binary
None of these
ANS: B
24. A character literal is __________, whereas a string literal is __________
a.
b.
c.
d.
e.
enclosed in quotation marks, enclosed in brackets
enclosed in brackets, enclosed in quotation marks
enclosed in double quotation marks, enclosed in single quotation marks
enclosed in single quotation marks, enclosed in double quotation marks
None of these
ANS: D
25. Which data type typically requires only one byte of storage?
a.
b.
c.
d.
e.
short
int
float
char
string
ANS: D
26. In C++11, if you want an integer literal to be treated as a long long int, you can append
__________ at the end of the number.
a.
b.
c.
d.
e.
L
LONG LONG
LL
ANS: D
27. The data type used to declare variables that can hold real numbers is
a.
b.
c.
d.
e.
short
int
float
char
double
ANS: C
28. The float data type is considered ___________ precision and the double data type is considered
__________ precision.
a.
b.
c.
d.
e.
single, double
double, single
floating-point, double
floating-point, integer
None of these
ANS: A
29. Which of the following statements correctly assigns the character M to the variable named letter?
a.
b.
c.
d.
letter = M
letter = “M”;
letter = ‘M’;
letter = (M);
e. letter = M;
ANS: C
30. Which of the following lines must be included in a program that has string variables?
a.
b.
c.
d.
e.
#include (string class)
#include namespace std;
#include
string var;
None of these
ANS: C
31. Assuming that a program has the following string object definition, which statement correctly
assigns the string literal “Jane” to the string object?
string name;
a.
b.
c.
d.
e.
name = Jane;
name = ‘Jane’;
name = “Jane”;
name = ;
string name = {Jane};
ANS: C
32. In memory, C++ automatically places a(n) __________ at the end of string literals which __________.
a.
b.
c.
d.
e.
semicolon, indicates the end of the statement
n, indicates an escape sequence
null terminator, marks the end of the string
bracket, marks the end of the string
None of these
ANS: C
33. Which of the following defines a double-precision floating-point variable named payCheck?
a.
b.
c.
d.
float payCheck;
double payCheck;
payCheck double;
Double payCheck;
ANS: B
34. The data type of a variable whose value can be either true or false is
a.
b.
c.
d.
e.
int
binary
bool
Boolean
T/F
ANS: C
35. What will be the output after the following lines of code execute?
bool choice;
choice = true;
cout << "Your choice is " << choice << endl;
a.
b.
c.
d.
e.
true
Your choice is true
Your choice is 1
Your choice is choice
None of these
ANS: C
36. Using C++11: What data type does the compiler determine for the variable cost in the following
statement?
auto cost = 14.95;
a.
b.
c.
d.
e.
int
double
bool
char
string
ANS: B
37. A variable's __________ is the part of the program that has access to the variable.
a.
b.
c.
d.
e.
data type
value
scope
assignment
None of these
ANS: C
38. What is the value stored in the variable myNum after the following assignment statement executes?
myNum = 23 % 5
a.
b.
c.
d.
e.
3
4
4.6
115
None of these
ANS: A
39. What is the value of cookies after the following statements execute?
int number = 38, children = 4, cookies;
cookies = number % children;
a.
b.
c.
d.
e.
2
4
9
9.5
.5
ANS: A
40. What is the value of number after the following statements execute?
int number;
number = 18 / 4;
a.
b.
c.
d.
e.
4.5
4
2
0
unknown
ANS: B
41. What is the value of number after the following statements execute?
int number;
number = 18 % 4 + 2;
a.
b.
c.
d.
e.
3
4
6.5
0
unknown
ANS: B
42. What is output of the following statement?
cout << 4 * (15 / (1 + 3)) << endl;
a.
b.
c.
d.
e.
15
12
63
72
None of these
ANS: B
43. Which part of the following line is ignored by the compiler?
double userName = "janedoe";
a.
b.
c.
d.
e.
// user's name is janedoe
"janedoe"
user's name is
user's name is janedoe
//
None of these
ANS: C
44. A multi-line comment
a.
b.
c.
d.
begins with /* and ends with */
can be used to mark as many lines as desired as comments
allows everything in the selected lines to be ignored
All of these are true
ANS: D
45. Which of the following statements correctly defines a named constant named TAX_RATE that holds
the value 0.075?
a. double TAX_RATE = 0.075;
b. const TAX_RATE;
double TAX_RATE = 0.075;
c. const double TAX_RATE = 0.075;
d. double TAX_RATE;
const TAX_RATE = 0.075;
e. const TAX_RATE = 0.075;
ANS: C
46. Given the following program, which line(s) cause(s) output to be displayed on the screen?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
a.
b.
c.
d.
e.
// This program displays my gross wages.
// I worked 40 hours and I make $20.00 per hour.
#include
using namespace std;
int main()
{
int hours;
double payRate, grossPay;
hours = 40;
payRate = 20.0;
grossPay = hours * payRate;
cout << "My gross pay is $" << grossPay << endl;
return 0;
}
lines 13 and 14
lines 8 and 9
line 14
lines 14 and 15
line 15
ANS: C
MULTIPLE RESPONSE
1. Select all that apply. Which of the following statements is(are) true about named constants?
a.
b.
c.
d.
e.
A named constant must be all uppercase.
The content of a named constant is read-only.
The value of a named constant cannot be changed while the program is running.
A named constant is defined using the const qualifier.
None of these
ANS: B, C, D
2. Select all that apply. Using C++11: Which of the following can be used to initialize an integer variable
named dozen with the value of 12?
a. int dozen = 12;
b. int dozen(12);
c. int dozen = {12};
d. int dozen = (12);
e. int dozen {12};
ANS: A, B, E
Document Preview (12 of 163 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.
-37%
Test Bank for Starting Out with C++ from Control Structures to Objects, 9th Edition
$18.99 $29.99Save:$11.00(37%)
24/7 Live Chat
Instant Download
100% Confidential
Store
Sophia Williams
0 (0 Reviews)
Best Selling
The World Of Customer Service, 3rd Edition Test Bank
$18.99 $29.99Save:$11.00(37%)
Chemistry: Principles And Reactions, 7th Edition Test Bank
$18.99 $29.99Save:$11.00(37%)
Test Bank for Hospitality Facilities Management and Design, 4th Edition
$18.99 $29.99Save:$11.00(37%)
Solution Manual for Designing the User Interface: Strategies for Effective Human-Computer Interaction, 6th Edition
$18.99 $29.99Save:$11.00(37%)
Data Structures and Other Objects Using C++ 4th Edition Solution Manual
$18.99 $29.99Save:$11.00(37%)
2023-2024 ATI Pediatrics Proctored Exam with Answers (139 Solved Questions)
$18.99 $29.99Save:$11.00(37%)