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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include <iostream>
using namespace std;
class Rocket{
public:
// default constructure
Rocket() {}
// prototype of constructor for class Rocket
// initialized data members
Rocket(double, double, double, double, double);
double velocity();
double altitude();
private:
double rocketmass; // mass of rocket in grams
double enginemass; // mass of engine in grams
double propemass; // mass of propellant in grams
double avgthrust; // average thrust in newtons
double thrustdura; // thrust duration in seconds
}
Rocket::Rocket(double rmass, double emass, double pmass, double avgth, double thdur)
{
rocketmass = rmass;
enginemass = emass;
propemass = pmass;
avgthrust = avgth;
thrustdura = thdur;
}
// calculates the max velocity of the rocket
double Rocket :: velocity()
{
double avgmass, // average mass
acceleration, // acceleration of rocket
maxvelocity; // max velocity of rocket
// calculates the average mass
avgmass = ((rocketmass + enginemass + rocketmass + enginemass - propemass)/ 2)/ 1000;
// calculates the acceleration of rocket
acceleration = (avgthrust / avgmass) - 9.8;
// calculates the max velocity
maxvelocity = acceleration * thrustdura;
return(maxvelocity);
}
// calculates max altitude of rocket
double Rocket :: altitude()
{
double height1,
height2,
maxaltitude,
avgmass,
acceleration;
// calculates the average mass
avgmass = ((rocketmass + enginemass + rocketmass + enginemass - propemass)/ 2)/ 1000;
// calculates the acceleration of rocket
acceleration = (avgthrust / avgmass) - 9.8;
// calculates the altitude of power flight
height1 = (velocity() * velocity()) / (2 * 9.8);
// calculates the altitude of non-powered flight
height2 = 0.5 * acceleration * thrustdura * thrustdura;
// calculates the maximum altitude of rocket
maxaltitude = height1 + height2;
return(maxaltitude);
}
// Main Program
int main( )
{
Rocket rmass, //
emass, //
pmass, // not sure about this part of program!!!???
avgth, //
thdur; //
// Output Identification
system("CLS");
cout << "In Class #10 by - "
<< "Rocket Structure\n\n";
// ask user to enter mass of rocket in grams
cout << "Enter the mass of rocket: ";
cin >> rmass;
// ask user to enter mass of engine of rocket in grams
cout << "Enter the mass of the engine: ";
cin >> emass;
// ask user to enter mass of propellant of rocket in grams
cout << "Enter the mass of the propellant: ";
cin >> pmass;
// ask user to enter average thrust of rocket in newtons
cout << "Enter the average thrust of the engine: ";
cin >> avgth;
// aks user to enter thrust duration of rocket in seconds
cout << "Enter the burn duration of the engine: ";
cin >> thdur;
return 0;
}
|