#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);
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.
a. 10.0 / 3.0 + 5 * 2
b. 10 % 3 + 5 % 2
c. 10 / 3 + 5 / 2
d. 12.5 + (2.5 / (6.2 / 3.1))
e. -4 * (-5 + 6)
f. 13 % 5 / 3
g. (10.0 / 3.0 % 2) / 3
2. What value is stored into the int variable result in each of the following?