You are on page 1of 2

Review

Questions and Exercises

Fill-in-the-Blank and Short Answer

1. Every complete C++ statement ends with a .


2. To use cout statements you must include the header file in your program.
3. Every C++ program must have a function named .
4. Preprocessor directives begin with a .
5. A group of statements, such as the body of a function, must be enclosed in .
6. 72 , 'A' , and "Hello World" are all examples of .
7. 978.65×1012 would be written in E notation as .
8. The character literal 'A' requires byte(s) of memory, whereas the string literal "A"
requires byte(s).
9. Indicate if each of the following assignment statements is valid or invalid. Assume that total ,
yourAge , and myAge are int variables and herAge is a string variable.
A. total = 9;
B. 72 = total;
C. yourAge = myAge;
D. herAge = "19";

10. If the variables letter and w have been defined as character variables, indicate if each of the
following assignment statements is valid or invalid.
A. letter = w;
B. letter = 'w';
C. letter = 'wow';
D. letter = "w";

11. Indicate if each of the following assignment statements is valid or invalid. Assume that total ,
sum1 , and sum2 are all integer variables.
A. total = 15;
B. total = 12 + 3;
C. total = 24 / 2;
D. total = sum1 + sum2;

12. Indicate if each of the following variable definition and initialization statements is valid or invalid.
A. char name = "Tom";
B. char name = 'Tom';
C. bool answer = "true";
D. auto miles = 2.9;

13. Indicate if each of the following cout statements is valid or invalid.


A. cout << "Hello" << endl;
B. cout << "Hello" << \n;
C. cout << "Hello \n";
D. cout << Hello;

14. Indicate if each of the following cout statements is valid or invalid.


A. cout << "Hello world";
B. cout << Hello world;
C. cout << "Hello" << "world";

15. Assume that variables x , y , and result are all integers and that x = 4 and y = 7 . What value
will be stored in result by each of the following statements?
A. result = x + y;
B. result = y * 2;
C. result = y / 2;
D. result = y / 2.0;

16. Assume that x and result are both double variables, that y is an int variable, and that x = 2.5
and y = 7 . What value will be stored in result by each of the following statements?
A. result = x + y;
B. result = y * 2;
C. result = y / 4;
D. result = y / 4.0;

17. Write a C++ statement that defines the double variables temp , weight , and height all in the
same statement.
18. Write a C++ statement that defines the int variables months , days , and years all in the same
statement, with months initialized to 2 and years initialized to 3.
19. Write assignment statements that perform the following operations with int variable i , double
variables d1 and d2 , and char variable c .
A. Add 2 to d1 and store the result in d2 .
B. Multiply d2 times 4 and store the result in d1 .
C. Store the character 'K' in c .
D. Store the ASCII code for the character 'K' in i .
E. Subtract 1 from i and store the result back in i .

20. Write assignment statements that perform the following operations with int variable i , double
variables d1 and d2 , and char variable c .
A. Subtract 8.5 from d2 and store the result in d1 .
B. Divide d1 by 3.14 and store the result in d2 .
C. Store the ASCII code for the character 'F' in c .
D. Add 1 to i and store the new value back in i .
E. Add d1 to the current value of d2 and store the result back in d2 as its new value.

21. Modify the following program segment so it prints two blank lines between each line of text.

cout << "Two mandolins like creatures in the";


cout << "dark";
cout << "Creating the agony of ecstasy.";
cout << " - George Barker";

22. Rewrite the follow statement to use the newline escape character, instead of an endl , each time
subsequent output is to be displayed on a new line.

cout << "L" << endl


<< "E" << endl
<< "A" << endl

You might also like