Chapter 02 Checkpoints Flashcards
"2.1 The following C++ program will not compile because the lines have been mixed up. int main() } // A crazy mixed up program return 0; #include cout
“2.1
// A crazy mixed up program #include using namespace std; int main() { cout
“2.2 The following C++ program will not compile because the lines have been mixed up.
cout
“2.2
// It's a mad, mad program #include using namespace std; int main() { cout
"2.3 Study the following program and show what it will print on the screen. // The Works of Wolfgang #include using namespace std; int main() { cout
“2.3
The works of Wolfgang
include the following
The Turkish March
and Symphony No. 40 in G minor.”
2.4 On paper, write a program that will display your name on the first line, your street address on the second line, your city, state, and ZIP code on the third line, and your telephone number on the fourth line. Place a comment with today’s date at the top of the program. Test your program by entering, compiling, and running it.
“2.4
// Today's Date: September 3, 2012 #include using namespace std; int main() { cout
"2.5 Examine the following program. // This program uses variables and literals. #include using namespace std; int main() { int little; int big; little = 2; big = 2000; cout
“2.5
Variables: little and big.
Constants: 2, 2000, “The little number is ”, “The big number is ””
“2.6 What will the following program display on the screen?
#include
using namespace std;
int main() { int number; number = 712; cout
2.6 The value is number
"2.7 Which of the following are illegal variable names, and why? x 99bottles july97 theSalesFigureForFiscalYear98 r&d grade_report"
“2.7
99bottles: Variable names cannot begin with a number.
r&d: Variable names may only use alphabetic letters, digits, or underscores”
2.8 Is the variable name Sales the same as sales? Why or why not?
2.8 No. Variable names are case sensitive.
“2.9 Refer to the data types listed in Table 2-6 for these questions.
A) If a variable needs to hold numbers in the range 32 to 6,000, what data type would be best?
B) If a variable needs to hold numbers in the range 40,000 to +40,000, what data type would be best?
C) Which of the following literals uses more memory? 20 or 20L”
“2.9
A) short, or unsigned short.
B) int
C) They both use the same amount of memory.”
2.10 On any computer, which data type uses more memory, an integer or an unsigned integer?
2.10 They both use the same amount of memory.
“2.11 What are the ASCII codes for the following characters? (Refer to Appendix B)
C
F
W”
“2.11
67, 70, 87”
“2.12 Which of the following is a character literal?
‘B’
““B”””
“2.12
‘B’”
"2.13 Assuming the char data type uses 1 byte of memory, how many bytes do the following literals use? 'Q' ""Q"" ""Sales"" '\n'"
“2.13
‘Q’ uses one byte
“Q” uses two bytes
“Sales” uses six bytes
‘\n’ uses one byte”
2.14 Write a program that has the following character variables: first, middle, and last. Store your initials in these variables and then display them on the screen.
“2.14
#include using namespace std; int main() { char first, middle, last; first = 'T'; middle = 'E'; last = 'G'; cout << first << "" "" << middle << "" "" << last << endl; return 0; }"
“2.15 What is wrong with the following program statement?
char letter = ““Z””;”
2.15 The string constant “Z” is being stored in the character variable letter.