CH 2

25 July 2022
4.7 (114 reviews)
60 test answers

Unlock all answers in this set

Unlock answers (56)
question
what do // mark the beginning of?
answer
a comment
question
Comments are generally added to programs because
answer
many programs are complicated and comments help explain what is going on
question
the line in the program that begins with a # is called a
answer
preprocessor directive
question
Reads your program before it is compiled and only executes those lines beginning with the # symbol
answer
prepocessor directive
question
"sets up" your source code for the compiler
answer
preprocessor directive
question
C++ uses ___ to organize the names of program entities.
answer
namespaces
question
A group of one or more programming statements that collectively has a name
answer
function
question
The character escape sequence to force the cursor to go to the next line is:
answer
n
question
The character escape sequence to force the cursor to advance forward to the next tab setting is:
answer
t
question
The character escape sequence to represent a single quote is:
answer
'
question
The character escape sequence to represent a double quote is:
answer
"
question
How many spaces printed out by this statement: cout << "abcndeftghinjkl" << endl << endl << "mnonnpqrn";
answer
6
question
How many bytes are needed to store: 'n' ?
answer
1
question
How many bytes are needed to store: "n" ?
answer
2
question
How many bytes are needed to store: 'n' ?
answer
1
question
How many bytes are needed to store: "n", ?
answer
2
question
How many bytes are needed to store: "n" ?
answer
3
question
How many bytes are needed to store: "" ?
answer
1
question
What's the difference in UNICODE value between 'E' and 'A'? (consult a table of UNICODE values):
answer
4
question
What's the difference in UNICODE value between 'e' and 'a'? (consult a table of UNICODE values):
answer
4
question
What's the difference in UNICODE value between '3' and '0'? (consult a table of UNICODE values):
answer
3
question
What's the difference in UNICODE value between '6' and '0'? (consult a table of UNICODE values):
answer
6
question
Does this line contain a valid comment? int twoPi = 3.14459; /* holds the value of two times pi */
answer
Yes
question
Does this line contain a valid comment? /* This is a //*// First Rate Program //*//
answer
No
question
Write a character literal representing the (upper case) letter A .
answer
'A'
question
Write a character literal representing a comma.
answer
','
question
Write a character literal representing the digit 1 .
answer
'1'
question
Write a literal representing the character whose ASCII value is 65 .
answer
65
question
Write a literal representing the largest character value . Suppose we are using unsigned one-byte characters .
answer
255
question
Declare a character variable named c .
answer
char c;
question
Write the necessary preprocessor directive to enable the use of the C++ string class .
answer
#include
question
Declare a string variable named mailingAddress .
answer
string mailingAddress;
question
Declare 3 string variables named winner , placed and show .
answer
string winner, placed, show;
question
Declare a string variable named empty and initialize it to the empty string .
answer
string empty;
question
Declare a string variable named oneSpace and initialize it to a string consisting of a single space.
answer
string oneSpace; oneSpace = " ";
question
Assume that message is a string variable . Write a statement to display its value on standard output .
answer
cout << message ;
question
Assume that word is a string variable . Write a statement to display the message "Today's Word-Of-The-Day is: " followed by the value of word on standard output .
answer
cout << "Today's Word-Of-The-Day is: " << word ;
question
Expressions that have a true or false value
answer
Boolean expressions
question
Write a literal representing the false value in C++.
answer
false
question
Write a literal representing the true value .
answer
true
question
Declare a variable isACustomer , suitable for representing a true or false value .
answer
bool isACustomer;
question
Declare a variable hasPassedTest , and initialize it to true .
answer
bool hasPassedTest; hasPassedTest = true;
question
useful for evaluating conditions that are either true or false
answer
bool variables
question
Declare and initialize the following variables : A variable monthOfYear , initialized to the value 11 A variable companyRevenue , initialized to the value 5666777 A variable firstClassTicketPrice , initialized to the value 6000 A variable totalPopulation , initialized to the value 1222333
answer
int monthOfYear = 11, companyRevenue = 5666777, firstClassTicketPrice = 6000, totalPopulation = 1222333;
question
How is a value stored in a variable?
answer
assignment statement
question
perform operations on data
answer
assignment operator
question
the data that operators work with
answer
operands
question
assign values to variables as part of the definition
answer
initialization
question
Declare an integer variable cardsInHand and initialize it to 13.
answer
int cardsInHand = 13;
question
Declare a variable temperature and initialize it to 98.6.
answer
float temperature = 98.6;
question
the part of the program that has access to the variable
answer
scope
question
Used to define variable that can hold real numbers; a data type that allows fractional values
answer
floating-point data types
question
3 data types that can represent floating point numbers
answer
float or single precision (4 bytes) double or double precision (8 bytes) long double or long double precision (8 bytes)
question
Declare a numerical variable precise and initialize it to the value 1.09388641.
answer
double precise = 1.09388641;
question
Declare a string variable named str and initialize it to Hello .
answer
string str; str = "Hello";
question
Write a declaration of an int variable year and initialize it to 365.
answer
int year = 365;
question
Write a statement that declares an int variable presidentialTerm and initializes it to 4.
answer
int presidentialTerm = 4;
question
Write a statement to set the value of num to 4 (num is a variable that has already been declared ).
answer
num = 4;
question
Given two double variables , bestValue and secondBestValue , write some code that swaps their values . Declare any additional variables as necessary.
answer
double temp; temp = bestValue; bestValue = secondBestValue; secondBestValue = temp;
question
...
answer
int temp; temp=firstPlaceWinner; firstPlaceWinner=secondPlaceWinner; secondPlaceWinner=temp;