< previous page
page_179
next page >
Page 179
Exam Preparation Exercises
1. What is the main advantage of having a program input its data rather than writing all the data values as constants in the program?
2. Given these two lines of data:
17 13
7 3 24 6
and this input statement:
cin >> int1 >> int2 >> int3;
a. What is the value of each variable after the statement is executed?
b. What happens to any leftover data values in the input stream?
3. The newline character signals the end of a line.
a. How do you generate a newline character from the keyboard?
b. How do you generate a newline character in a program's output?
4. When reading
char
data from an input stream, what is the difference between using the >> operator and using the
get
function?
5. Integer data values can be read into
float
variables. (True or False?)
6. You may use either spaces or newlines to separate numeric data values being entered into a C++ program. (True or False?)
7. Consider this input data:
14 21 64
19 67 91
73 89 27
23 96 47
What are the values of the int variables a, b, c, and d after the following program segment is executed?
cin >> a;
cin.ignore(200, \n);
cin >> b >> c;
cin.ignore(200, \n);
cin >> d;
8. Given the input data
123W 56
what is printed by the output statement when the following code segment is executed?
int1 = 98;
int2 = 147;
cin >> int1 >> int2;
cout << int1 << << int2;
< previous page
page_179
next page >