< previous page page_125 next page >

Page 125
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
#include <iostream.h>
const int INT1=20;const int INT2=8;int main() { cout <
The sum of  < INT1 <  and 
< INT2 <  is  < INT1+INT2 < endl;cout
< Their product is  < INT1*INT2 < endl;return 0; }
Answers 1. The result is 3. 2. 9.0 / 5.0 * c + 32.0
3. a. someFloat = float(5 + someInt);
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. someInt = int(2.5 * float(someInt) / someFloat); 4. a. sqrt and fabs
b. math.h 5. someInt + 1 6. A value-returning function7. A void function 8. Two consecutive endl manipulators are necessary. 9. cout < setw(9) < setprecision(2) < pay;
10. //**************************************************************
    // SumProd program
    // This program computes the sum and product of two integers
    //**************************************************************
    #include <iostream.h>

    const int INT1 = 20;
    const int INT2 = 8;

    int main()
{
        cout < The sum of  < INT1 <  and  < INT2
             <  is  < INT1 + INT2 < endl;
        cout < Their product is  < INT1 * INT2 < endl;
        return 0;
}
Exam Preparation Exercises
1. Compute the value of each legal expression. Indicate whether the value is an integer or a floating point value. If the expression is not legal, explain why.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. 10.0 / 3.0 + 5 * 2
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. 10 % 3 + 5 % 2
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. 10 / 3 + 5 / 2
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. 12.5 + (2.5 / (6.2 / 3.1))
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
e. -4 * (-5 + 6)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
f. 13 % 5 / 3
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
g. (10.0 / 3.0 % 2) / 3
2. What value is stored into the int variable result in each of the following?
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. result = 15 % 4;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. result = 7 / 3 + 2;
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. result = 2 + 7 * 5;

 
< previous page page_125 next page >