< 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:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
17 13
7 3 24 6
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
and this input statement:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> int1 >> int2 >> int3;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. What is the value of each variable after the statement is executed?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. What happens to any leftover data values in the input stream?
3. The newline character signals the end of a line.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. How do you generate a newline character from the keyboard?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
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:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
14 21 64
19 67 91
73 89 27
23 96 47
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
What are the values of the int variables a, b, c, and d after the following program segment is executed?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> a;
cin.ignore(200, \n);
cin >> b >> c;
cin.ignore(200, \n);
cin >> d;
8. Given the input data
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
123W 56
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
what is printed by the output statement when the following code segment is executed?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int1 = 98;
int2 = 147;
cin >> int1 >> int2;
cout << int1 <<   << int2;

 
< previous page page_179 next page >