< previous page page_a49 next page >

Page A49
4. discriminant = sqrt (b * b - 4.0 * a * c);
   denominator = 2.0 * a;
   solution1 = (-b + discriminant) / denominator;
   solution2 = (-b - discriminant) / denominator;
Chapter 3
Case Study Follow-Up
1. Declare a constant ROUND_FACTOR (defined to be equal to the desired rounding factor, such as 100.0 for hundredths) and replace every occurrence of 10.0 with ROUND_FACTOR.
Chapter 4
Exam Preparation Exercises
2. a. int1 contains 17, int2 contains 13, and int3 contains 7.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. The leftover values remain waiting in the input stream. These values will be read by subsequent input statements (or they will be ignored if no more input statements are executed).
6. True
8. 123 147
11. Errors in the program are as follows:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
The declaration of outData is missing:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
ofstream outData;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
The opening of the input file is missing:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
inData.open(myfile.dat);
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
The statement
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin >> n;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
does not read from the input file. Change cin to inData.
12. With the corrected version of the program in Exercise 11, file inData will still contain the 144 after the program is executed. File outData will contain 144, followed by a newline character.
Chapter 4
Programming Warm-Up Exercises
1. cin >> ch1 >> ch2 >> ch3;
3. cin >> length1 >> height1 >> length2 >> height2;
4. In the following, the value 100 is arbitrary. Any value greater than 4 will work.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cin.get(chr1);
cin.ignore(100, \n);
cin.get(chr2);

 
< previous page page_a49 next page >