Weight of tube: 23.049 lbs
Aluminum Shell Thickness: 0.130 inches
Stainless Shell Thickness: 0.046 inches
Press any key to continue
After you have entered the slightly modified program and run it to get the answers, print out your program. (You MUST do this printing using the Visual Studio programming environment, NOT a word processor; you do not need to print in color.) Then, do one of the following, depending on the last digit of your Banner ID number.
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. Omit the semicolon from tubeWeight = volume
* WEIGHT - BUOYANCY;
1. In the declaration of cosSquared,
double
tubeWeight;
change the 'W'
to lowercase, i.e., 's'.
2. In the line int main ()
change the right parenthesis to ]
3. Replace the first << with >> in
cout <<
fixed << showpoint << setprecision(2);
4. Omit the // on the line // Determine the
volume and weight of the tube
5. Change the declaration, const double
STAINLESS = 7.48;
to
const double STAINLESS;
6. Misspell EvaluateRoot as EvaluateRoute in the statement
EvaluateRoot
(thickness, first, second, thirdFE);
7. Misspell double in double
alpha; as doble.
8. Change // to /* in // Get intermediate
results
9. Replace the return 0; statement with
return "done";
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. You do not need to write repeated error messages; writing each error once is enough. You MUST do this part by hand - printouts of the errors will be marked wrong.
// **************************
//
// Project 1: Floating Tube
// This program computes the weight and thickness of
a hollow,
// capped, metal tube that is used for flotation.
Two thicknesses
// are calculated: one for aluminum, one for
stainless steel.
//
// Written by Jim Wolfe
Section: 099
// Due on 28 January 2008
// Input: none - tube specifications are constants
// Output: weight and thickness of the tube
// **************************
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI = 3.14159265359; // Accurate
version of Pi
const double RADIUS = 0.25;
// Radius of tube in feet
const double WEIGHT = 62.42;
// Weight of 1 cu ft of water
const double LENGTH = 8.0;
// Length of tube in feet
const double BUOYANCY = 75.0;
// Weight to be supported (lbs)
const double ALUMINUM = 2.7;
// Specific gravity of aluminum
const double STAINLESS = 7.48;
// Specific gravity of stainless steel
void EvaluateRoot (double &, double, double, double);
int main ()
{
double first;
// 1st coefficient of cubic equation
double second;
// 2nd coefficient
double thirdAL;
// 3rd coefficient for Aluminum
double thirdFE;
// 3rd coefficient for Stainless steel
double volume;
// Volume of tube
double tubeWeight;
// Weight of the tube
double thickness;
// Root of cubic eequation; shell thickness
cout << fixed << showpoint << setprecision(3);
// Determine
the volume and weight of the tube
first = - (4.0 * RADIUS + LENGTH) / 2.0;
second= RADIUS * (RADIUS + LENGTH);
volume = PI * RADIUS * RADIUS * LENGTH;
tubeWeight = volume * WEIGHT - BUOYANCY;
cout << endl << "Weight of
tube: " << tubeWeight << " lbs" << endl;
// Calculate
the thickness for Aluminum and Stainless steel
thirdAL = - (tubeWeight / (2.0 *
PI * ALUMINUM * WEIGHT));
EvaluateRoot (thickness, first, second,
thirdAL);
cout << "Aluminum Shell Thickness:
" << thickness * 12.0
<<
" inches" << endl;
thirdFE = - (tubeWeight / (2.0 *
PI * STAINLESS * WEIGHT));
EvaluateRoot (thickness, first, second,
thirdFE);
cout << "Stainless Shell Thickness:
" << thickness * 12.0
<<
" inches" << endl << endl;
return 0;
}
// EvaluateRoot - finds the root of a cubic equation, given the
// coefficients of the second, third and fourth term
// keyRoot is the "middle" root of the equation
void EvaluateRoot (double & keyRoot, // Root of equation
double first, // 1st Coefficient
double second, // 2nd Coefficient
double third) // 3rd Coefficient
{
double alpha;
// 1st intermediate result
double beta;
// 2nd intermediate result
double phi;
// Angle for the formula
// Get intermediate
results
alpha = (3.0 * second - first * first)
/ 3.0;
beta = (2.0 * first * first * first -
9.0 *
first * second + 27.0 * third) / 27.0;
phi = acos(-beta / 2.0 / sqrt(alpha *
alpha * alpha / (-27.0)));
keyRoot = (2.0 * sqrt(-alpha/3.0) * cos
(phi/3.0 + 2.0 * PI / 3.0)
- first / 3.0);
}