CMIS 102
Lab exercise 4
1. Write a small program that illustrates input stream failure.
This is similar to question 8 on page 194.
int i, j;
i = 98;
j = 147;
cin >> i >> j;
cout << "i=" << i << " j=" << j << endl;
Run the program and enter: 123 W 56
Run the program and enter: W 123 56
Understand what's happening.
2. Make the quadratic formula program that you wrote in class.
You can test it with these inputs for the three coefficients a, b, c:
2 4 2 which makes x be -1
1 4 0 which makes x be 0
0 2 3 which causes error because of divide by 0
1 1 1 another error because trying to square root of negative number
3. Download housecost.cpp from the web site. Run it and record the
cost per foot value it generates.
Modify the program so that it doesn't have the consts but instead has
appropriate variables and inputs all those values from the user. Test
your modified program with the same data that the original program used.
The test should produce the same cost per foot as the original
program.
Then further modify it so that outputs the gross footage, the cost per
gross foot, and the living footage.
4. Body Mass Index formulas:
BMI = (Weight in Pounds / (Height in inches x Height in inches)) x 703
BMI = Weight in Kilograms / (Height in Meters x Height in Meters)
Write a program that inputs weight and height in one or the other
system, or both, and outputs the BMI.