For a quantity of 2000.000 ml
The yard-of-ale lip diameter is 8.599 cm or 3.386 inches
Height of equivalent stein 10 cm in diameter is 25.465 cm or 10.026 inches
After you have entered the slightly modified program and run it to get the answers, print out a page with your program on it. (You MUST do this printing using the Visual Studio programming environment, NOT a word processor.) Then, do one of the following, depending on the last digit of your Banner ID nunber. Deliberately make one of the following mistakes in your program and then try to compile again - choose the mistake whose number matches the last digit of your Banner ID number. You should get one or more error or warning messages. By hand, write the last digit of your Banner ID number, and the error/warning message(s) you get on the bottom or back of your printout; then hand it in.
0. Remove the 0 from the return0;
statement.
1. Omit the semicolon from
lipDiameter
= -0.5 + discriminant;
2. In the declaration of lipDiameter,
double
lipDiameter;
omit the r in lipDiameter.
3. Omit the () after the word main.
4. Replace the << in cout
<< setprecision(3); with >>
5. Omit the // on the line
//
appropriate annotation
6. Change the declaration, const
double QUANTITY = 2000.0;
to
const double QUANTITY;
7. Misspell sqrt in
discriminant = sqrt(BOTTOM * BOTTOM -
4.0 * (0.25 - otherElements));
as squareroot.
8. Misspell double in
double inchHeight; as
doble.
9. Change // to /* in the comment
// Specify 3 decimal places
Do NOT save your program with the error
in it. Do NOT print out your program with the error in it. By hand, using
your best handwriting, write the error/warning message(s) on the printout
of the correct program. Be sure to look at the entire message window
to find all error/warning messages.
// **************************
//
// Project 1: A Yard of Ale
// This program computes the lip
diameter of a glass containing a yard
// of ale for a specified quantity
of liquid. The glass is assumed to be
// one yard (91.44 cm) high and have
a very small (1.0 cm) diameter at the
// bottom. The program also
computes the height of a stein that is 10
// centimeters in diameter and holds
the same amount of liquid.
// Author: Jim Wolfe
// Date: Due on 26 January 2005
// Data source: none - the quantity
is a constant
// Results: Output the lip diameter
of the yard glass and the height of
//
the stein for a given quantity
// Assumptions: None
//
// **************************
#include <iostream>
#include <iomanip>
// For formatting the output
#include <cmath>
// For the square root function
using namespace std;
const double PI = 3.14159265;
// Standard value of pi
const double QUANTITY = 2000.0;
// Quantity in milliliters
const double HEIGHT = 91.44;
// Height of the glass in centimeters
const double BOTTOM = 0.5;
// Radius of the bottom of the glass
const double CM_PER_INCH = 2.54;
// Centimeters per inch
const double STEIN_RADIUS = 5.0;
// Radius of equivalent stein
int main()
{
double otherElements;
// Parts of cone formula excluding radius
double discriminant;
// Portion of the quadratic formula
double lipDiameter;
// Diameter of the lip of the glass
double inchDiameter;
// Diameter in inches
double cylinderHeight;
// Height of equivalent cylinder
double inchHeight;
// Cylinder height in inches
cout.setf(ios::fixed, ios::floatfield);
// Set up for floating
cout.setf(ios::showpoint);
// point output formatting
// Calculate lipDiameter using
formula for a frustrum
// volume = pi * h *
(r1*r1 + r1*r2 + r2*r2) / 3
// where r1 and r2 are
the radii and r1 is 0.5
otherElements = QUANTITY / (PI * HEIGHT
/ 3.0);
discriminant = sqrt (BOTTOM * BOTTOM -
4.0 * (0.25 - otherElements));
lipDiameter = -0.5 + discriminant;
// Calculate height using formula
for a cylinder
// volume = pi * h *
r * r
cylinderHeight = QUANTITY / (PI * STEIN_RADIUS
* STEIN_RADIUS);
inchDiameter = lipDiameter / CM_PER_INCH;
inchHeight = cylinderHeight / CM_PER_INCH;
cout << setprecision(3); // Specify 3 decimal places
// Output lip diameter and height,
with reasonable field widths
// and appropriate annotation
cout << endl << "For a quantity
of " << QUANTITY << " ml "
<<
endl << endl;
cout << "The yard-of-ale lip diameter
is " << setw(6)
<<
lipDiameter << " cm or " << setw(6) << inchDiameter
<<
" inches" << endl << endl;
cout << "Height of equivalent stein
10 cm in diameter is " << setw(7)
<<
cylinderHeight << " cm or " << setw(6) << inchHeight
<<
" inches" << endl << endl;
return 0;
}