C++ Ch.2 - 2.6
A preprocessor directive starts with what character or characters?
#
Write the include directive needed to allow use of the various I/O operators such as cout and cin
#include <iostream>
Rearrange the following code so that forms a correct program that prints out the letter Q:
#include <iostream> using namespace std; int main() { cout<<"Q"; return 0; }
Suppose your name was George Gershwin. Write a complete program that would print your last name, followed by a comma, followed by your first name. Do not print anything else (that includes blanks)
#include <iostream> using namespace std; int main() { cout << "Gershwin,Ggeorge" <<endl; return 0; }
Write a complete program that prints Hello World to the screen
#include <iostream> using namespace std; main() { cout<<Hello Word"; return 0; }
Write the include directive that allows use of the function headers in the file myFuncs.h.
#include<myFuncs.h>
A comment starts with what characters?
//
How many spaces printed out by this statement: cout << "how" << "now" << "brown" << "cow" << "?";
0
Write a literal representing the integer value zero
0
Write a hexadeciaml integer literal representing the value fifteen
0xf
Write a literal representing the long integer value twelve million
12000000L
Qualifying an integer declaration with "unsigned" essentially increases the maximum value of the variable by a factor of ___
2
Write a long integer literal that has the value thirty-seven
37L
How many lines are printed out by this statement: cout << "abc\ndef\tghi\njkl" << endl << endl << "mno\npqr\n";
6
Which of the following is NOT a legal identifier?
7thheaven
Which special of the following special characters does NOT need to be paired with another special character in C++
;
The world in the brackets of an include directive specifies
A file containing code that is copied into the program at the point
The text of a comment
Can be anything the programmer wants to write
Which of the following will not be recognized if iostream is not included in the program?
Cout
Preprocessor directive are carried out
Just before a program is processed by the compiler
Every C++ program must contain a ______ function
Main
Which of the following names in a program is equivalent to the name int?
None of the above
An identifier that cannot be used as a variable name is a _____________
Reserved Word
The names defined in iostream are associated with which namespace?
STD
The character escape sequence to represent a double quote is:
\"
The character escape sequence to represent a single quote is:
\'
The character escape sequence to represent a backslash is:
\\
The character escape sequence to force the cursor to go to the next line is:
\n
The character escape sequence to force the cursor to advance forward to the next tab setting is:
\t
Which of the following IS a legal identifier?
__________________
Write a statement that prints Hello World to the screen
cout<<"Hello World";
Suppose your name is Alan Turing. Write a statement that would print your last name, followed by a comma, followed by your first name. Do not print anything else (that includes blanks)
cout<<"Turing,Alan";
Write a statement that prints the following to standard output: i=
cout<<"i=";
Given an integer variable count, write a statement that write the value of count to standard output
cout<<count;
Given an integer variable drivingAge that has already been declared, write a statement that assigns the value 17 to drivingAge
drivingAge=17;
Of the following variable names, which is the best one for keeping track of whether a patient has a fever or not?
hasFever
Write a declaration for two integer variables, age and weight
int age; int weight;
Write a declaration of variable named count that can be used to hold numbers like 90000 and -1 and -406
int count;
Write a statement that declares an int variable named count
int count;
Declare an integer variable named degreesCelsius
int degreesCelsius;
Write a declaration for a variable hits that can hold the number of times a baseball player has hit the ball in a baseball game
int hits;
Write a declaration of a variable named numberOfWidgets that can be used to hold numbers like 57 and 981 and -4
int numberOfWidgets;
Write a declaration of a variable named number_of_children that can be used to hold the number of children in a family
int number_of_children;
Declare a variable populationChange, suitable for holding number like -593142 and 8930522
int populationChange;
Declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear
int profitStartOfQuarter; int cashFlowEndOfYear;
Declare a long integer variable named grossNationalProduct
long int grossNationalProduct;
Which of the following is NOT a C++ keyword?
main
Of the following variable names, which is the best one for keeping track of whether an integer might be prime or not?
mightBePrime
Which is the best identifier for a variable to represent the amount of money your boss pays you each month?
monthlyPay
Write a statement to set the value of num to 4 (num is a variale that has already been declared)
num=4;
Declare an unsigned integer variable named degreesKelvin
unsigned int degreesKelvin;