1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
class Rocket
{
public:
Rocket() {}
Rocket(double, double, double, double, double);
double velocity(double, double, double, double, double) const;
double altitude(double, double) const;
private:
double rocketmass;
double enginemass;
double propmass;
double thrust;
double burn;
};
Rocket :: Rocket(double rocketm, double rocketengine, double rocektprop, double rocketthrust, double rocketburn)
{
rocketmass = rocketm;
enginemass = rocketengine;
propmass = rocektprop;
thrust = rocketthrust;
burn = rocketburn;
}
double Rocket :: velocity(double thrust, double rocketmass, double enginemass, double propmass, double burn)const
{
double acceleration;
double averagemass;
averagemass = ((rocketmass + enginemass + propmass) + (rocketmass + enginemass)) / 2;
acceleration = thrust / averagemass;
return(acceleration * burn);
}
double Rocket:: altitude(double burn, double acceleration)const
{
return (.5 * acceleration * pow(burn, 2));
}
// Main Program
int main( )
{
// Variable Declarations
char answer;
double rocketmass;
double enginemass;
double propmass;
double thrust;
double burn;
//
do{
cout << "Enter the mass of the rocket: ";
cin >> rocketmass;
cout << "Enter the mass of the engine: ";
cin >> enginemass;
cout << "Enter the mass of the propellant: ";
cin >> propmass;
cout << "Enter the average thrust of the engine: ";
cin >> thrust;
cout << "Enter the burn duration of the engine: ";
cin >> burn;
cout << endl;
cout << "The rockets maximum velocity is " << Rocket.velocity << endl;
cout << "The rockets maximum altitude is " << Rocket.altitude << endl;
cout << "Would you like to run the program again (Y or N)? ";
cin >> answer;
}while(answer == 'Y');
//
cout << "\n\nEnd Program.\n";
return 0;
}
|