LITTLE HELP PLEASE!



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
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;


// This funtion computes the burnout altitude and the
// coast altitude of a model rocket.
// The first 6 parameter are the input data
// to the function. Parameter 7 and 8 return the results
void computeA	(double massR,	// Rocket Mass (g)
				 double massE,	// Engine Mass (g)
				 double massP,	// Propellant Mass (g)
				 double dia,	// Diameter of Rocket (mm)
				 double advTh,	// Avg thrust of Engine (N)
				 double burnD,	// Burn Duration (s)
				 double& altB,	// Burnout Altitude (m)
				 double& altC);	// Coast Altitude (m)

const double density = 1.2;		// kg/m^3
const double cd = .75;			// drag coefficient of stndrd rocket
const double gravity = 9.8;		// gravity on earty
const double pi = 3.14;			// constant variable for PI



// Main Program
int main()
{
	// constants


	// Variable Declarations

	double massR;					// the mass of the rocket in grams
	double massE;					// the mass of the engine in grams
	double massP;					// mass of the propelland in grams
	double avgTh;					// Thrust of engine in Newtons
	double burnD;					// burn duration of the engine
	double dia;						// diameter of rocket in mmt
	char good;						// loop input answer

	double avg_mass;				// average mass during boost phase of rocket
	double k;						// half atmospher density*drag coeff*area
	double vb;						// burnout velocity
	double avgTh;					// Thrust of engine in Newtons
	double coastmass;
	double area;

	double altB;
	double altC;

									// Output Identification

	system("CLS");
	cout << "In Class #7 by Kyle Alberti - "
		<< "Rocket Burnout Velocity\n\n";



	// This funtion computes the burnout altitude and the
	// coast altitude of a model rocket.
	// The first 6 parameter are the input data
	// to the function. Parameter 7 and 8 return the results
	
	
	do {
	//
	// Get rocket sample data
	//

	cout << "Enter the mass of the rocket (grams) => ";
	cin >> massR;
	cout << "Enter the mass of the engine (grams) => ";
	cin >> massE;
	cout << "Enter the mass of the propellant (grams) => ";
	cin >> massP;
	cout << "Enter the diameter of the rocket (in millimeters) => ";
	cin >> dia;
	cout << "Enter the average thrust of the engine (Newtons) => ";
	cin >> avgTh;
	cout << "Enter the burn duration of the engine (seconds) => ";
	cin >> burnD;

	// Calculation conversions

	massR = massR / 1000;		// convert grams to kg
	massE = massE / 1000;		// convert grams to kg 
	massP = massP / 1000;		// convert grams to kg
	dia = dia / 1000;			// convert mm to m
	dia = (dia / 2);
	avg_mass = massR + massE - (massP * .5);
	coastmass = massR + massE - massP;
	area = pi * (dia*dia);
	k = ((.5 * 1.2) * .75 * area);
	vb = sqrt((avgTh - (avg_mass*gravity)) / k) * tanh((burnD / avg_mass)
		* sqrt(k * (avgTh - avg_mass*gravity)));

	computeA(massR, massE, massP, dia, avgTh, burnD, altB, altC);

cout << fixed << setprecision(1) << endl;
cout << endl;
cout << "The burnout altitude is " << altB << " meters/second." << endl;
cout << "The coast altitude is " << altC << " meters/second." << endl;
cout << "Would you like to run the program again (Y or N)? ";
cin >> good;
cout << endl;
cout << endl;
	} while (good == 'y');


cout << "\n\nEnd Program.\n";

	return 0;
}
void computeA(double massR,	// Rocket Mass (g)
	double massE,	// Engine Mass (g)
	double massP,	// Propellant Mass (g)
	double dia,	// Diameter of Rocket (mm)
	double avgTh,	// Avg thrust of Engine (N)
	double burnD,	// Burn Duration (s)
	double& altB,	// Burnout Altitude (m)
	double& altC)	// Coast Altitude (m)
{
	altB = (avg_mass / k) * log(cosh((burnD / avg_mass)*sqrt(k*(avgTh - avg_mass*area))));
	altC = (coastmass / (2 * k))*log(((k*(vb*vb)) / (coastmass*area)) + 1);
}
Last edited on
Why do you have global variables? The global constants make sense, but variables ...

For example, on line 33 is 'avgTh'. Uninitialized. You do use it on lines 124-125.

The main() has a 'avgTh' too, but it is local to function scope (i.e. shadows the global variable).
I have edited the code above like you said. But then some identifiers under my function that calculate altB and altC say "undefined". For instance the first one to say undefined is vb under altC calculation, although it doesn't like avgTh or area from altB calulation. That is why I initially put them in the global area.
Last edited on
Line 41, 50: You're defining avgTh twice.

Line 115: Where is avg_mass defined? I see it defined in main(), but that is not visible in computeA(). You need to pass it as an argument to computeA().

Line 115-116: ditto for k.

line 115: ditto for area.

line 116: ditto for coastmass.

line 116: ditto for vb.

Line 115: avgTh is undefined. Did you misspell it on line 110?




Last edited on
I fixed the lines on 41/50 and 115.

Pass it as an argument? how do I do that?
Pass it as an argument? how do I do that?

Line 106: You're already passing 8 arguments. Just add them to the list.

Don't forget to add them to your function prototype at line 14.

Note: k, vb, area, avgTh, avg_mass, coastmass are all uninitialized variables in main(). If you're going to pass them to ComputeA() and used them in your calculation, they should have meaningful values.
Last edited on
Oh dear, you do already "pass" 8 arguments to function computeA() without knowing how to do that? Luckily that is not necessary.

Remove lines 46-51.

Create the necessary variables within function computeA. Between lines 114 and 115.
You have to set to them correct values too, before line 115.
Yes, but i have to use this specific function prototype without change, thats part of the context of the assignment.
ok, so you need a little rocket science.... pun intended ;)

How do you calculate
  a) the coefficient k,
  b) the rocket area,
  c) the burnout velocity,
  d) the average boost mass, and
  e) the coast mass?

You need those for the function computeA()...
I accidentally deleted those calculations when i copied and pasted it. I have updated it above. Is that where I want the calculations though? Because the function cant access the values to variables like avg_mass and vb.

Please keep in mind the instructions say:

Your program WILL use the following function prototype WITHOUT modification:

// This function computes the burnout altitude and the
// coast altitude of a model rocket.
// The first 6 parameter are the input data
// to the function. Parameter 7 and 8 return the results

void computeA (double massR, // Rocket Mass (g)
double massE, // Engine Mass (g)
double massP, // Propellant Mass (g)
double dia, // Diameter of Rocket (mm)
double advTh, // Avg thrust of Engine (N)
double burnD, // Burn Duration (s)
double& altB, // Burnout Altitude (m)
double& altC); // Coast Altitude (m)
Last edited on
You obviously should do those calculations within the function.
So I would need to make the following variables global then?

avg_mass
coastmass
area
k
vb
Last edited on
No. Make them local. Local to function computeA().
Global variables are evil and should be avoided.

I see no reason lines 92-99 can't be moved into computeA.

Thanks a lot, I have the program working now. Though my calculations are not currently correct for altB and altC.
Topic archived. No new replies allowed.