Define a class called Rocket

problem description:

Write a program that defines a class called Rocket that represents a rocket. The class should contain the rocket's mass (in grams), the mass of engine (grams), the mass of the propellant (grams), the average thrust(newtons), and the thrust duration (seconds). The variables must be made private. The class should have a member function that prints out the class data. The class should also define two member functions that calculate and return the max altitude and max speed of the rocket. The calculation function should NOT print anything. Assume that the flight is straight up, no atmospheric drag, and the mass during powered flight is an average value. The program should read in the data and create and object of class Rocket to store the data. The program should the call the member functions and print out the results of the calculations.

Example output:

enter the mass of the rocket: 23
enter the mass of engine: 16.2
enter the mass of propellant; 3.12
enter the average thrust of the engine: 8
enter the burn duration of the engine: .5

The rockets max velocity is 101.37
The rockets max altitude is 549.621


This is my first assignment of objects as a beginner in c++. I have a hard time understanding the design of a class that's why I'm asking for help. So far for this program I only have the calculations of the max velocity and altitude. Would like help on how to start the design of the program. Thank you in advance!!

Last edited on
What have you written so far? Make sure any code you post is [code]between code tags[/code] so that it has syntax highlighting and line numbers, as well as proper indentation.
This is what i have so far but there are parts that are wrong and unfinished.

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;
}  


Last edited on
On lines 87-91, you create several rockets - you probably wanted to just create one.

I recommend asking the user for all the information first before you actually create the rocket.
Last edited on
Instead of rockets, I think those are supposed to be doubles.
Topic archived. No new replies allowed.