CylinderType HW Programm

Okay I am having huge problems with the output and I think the math part of my program. I am going to put the problem that was assigned to me.
Look at Example 3.

https://books.google.com/books?id=WPOdCAAAQBAJ&pg=PA776&lpg=PA776&dq=chapter+10+define+the+class+circleType+to+implement&source=bl&ots=eQtNwj0OWE&sig=0wc1VLDr2lAzik1q2FAm-0f4aUM&hl=en&sa=X&ei=O-U-VZPDAYqFsAWw6ICwCw&ved=0CB4Q6AEwAA#v=onepage&q=chapter%2010%20define%20the%20class%20circleType%20to%20implement&f=false

I am going to put my code here so you can see the out put.
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// circleType.h
#ifndef H_CircleType
#define H_CircleType

#include "pointType.h"

using namespace std;

class circleType : public pointType
{

public:

	void setRadius(double cRadius);

	void print() const;

	double getRadius() const;

	double calcArea() const;

	double calcCir() const;

	double calcDia() const;

	circleType();

	circleType(double pointX, double pointY, double cRadius);

private:

	double radius;

};

#endif 
// cylinderType.h
#ifndef H_CylinderType
#define H_CylinderType

#include "circleType.h"

using namespace std;

class cylinderType : public circleType
{

public:

	void setHeight(double cHeight);

	void print() const;

	double getHeight() const;

	double calcVolume()const;

	double calcSurface() const;

	cylinderType();

	cylinderType(double cHeight);

private:

	double height;

};

#endif 
 // PointType.h
#ifndef H_PointType
#define H_PointType

using namespace std;

class pointType
{
public:

	void setPoints(double pointX, double pointY);

	void print() const;

	double getX() const;

	double getY() const;

	pointType();

	pointType(double pointX, double pointY);

private:

	double x, y;

};

#endif 

// circleType.cpp
#include "circleType.h"
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void circleType::setRadius(double cRadius)
{
	radius = cRadius;
}

void circleType::print() const
{
	cout << "The radius of the circle is: " << getRadius() << endl;
	cout << "The diameter of the circle is: " << calcDia() << endl;
	cout << "The area of the circle is: " << calcArea() << endl;
	cout << "The circumference of the circle is: " << calcCir() << endl;
	cout << fixed << setprecision(2) << "The x and y coordinates are: ";
	cout << getX() << "," << getY() << "." << endl;
}

double circleType::getRadius() const
{
	return radius;
}

double circleType::calcArea() const
{
	double pi = 3.14159;
	return (pi * (radius * radius));
}

double circleType::calcCir() const
{
	double pi = 3.14159;
	return (calcDia() * pi);
}

double circleType::calcDia() const
{
	return radius * 2;
}

circleType::circleType()     //Default construtor
{
	radius;
}

circleType::circleType(double pointX, double pointY, double cRadius)     //Constructor with parameters
{
	pointType::setPoints(pointX, pointY);
	radius = cRadius;
}
// cylinderType.cpp
#include "cylinderType.h"
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

void cylinderType::setHeight(double cHeight)
{
	height = cHeight;
}

void cylinderType::print() const
{
	cout << "The height of the cylinder is: " << getHeight() << endl;
	cout << "The radius of the cylinder base is: " << getRadius() << endl;
	cout << "The volume of the cylinder is: " << calcVolume() << endl;
	cout << "The surface area of the cylinder is: " << calcSurface() << endl;
	cout << fixed << setprecision(2) << "The x and y coordinates are: ";
	cout << getX() << "," << getY() << "." << endl;
}

double cylinderType::getHeight() const
{
	return height;
}

double cylinderType::calcVolume() const
{
	double pi = 3.14159;
	return (height * pi) * (getRadius() * getRadius());
}

double cylinderType::calcSurface() const
{
	double pi = 3.14159;
	return (2 * calcArea()) + (calcCir() * height);
}

cylinderType::cylinderType()
{
	height;
}

cylinderType::cylinderType(double cHeight)
{
	height = cHeight;
}
// baseclass.cpp
#include "pointType.h"
#include <iostream>
#include <iomanip>

using namespace std;

void pointType::setPoints(double pointX, double pointY)
{
	x = pointX;
	y = pointY;
}

void pointType::print() const
{
	cout << fixed << setprecision(2) << "The x and y coordinates are: ";
	cout << getX() << "," << getY() << "." << endl;
}

double pointType::getX() const
{
	return x;
}

double pointType::getY() const
{
	return y;
}

pointType::pointType()
{
	x;
	y;
}

pointType::pointType(double pointX, double pointY)
{
	x = pointX;
	y = pointY;
}
// int main
#include "pointType.h"
#include "circleType.h"
#include "cylinderType.h"
#include <iostream>

using namespace std;

int main()
{

	pointType point;

	double x, y;

	cout << "Enter the x-coordinate: ";
	cin >> x;

	cout << "Enter the y-coordinate: ";
	cin >> y;

	point.setPoints(x, y);
	point.print();
	
	circleType circle;

	double r;

	cout << "Enter the radius of the circle: ";
	cin >> r;

	circle.setRadius(r);
	circle.print();

	cylinderType cylinder;

	double h;

	cout << "Enter the height of the cylinder: ";
	cin >> h;

	cylinder.setHeight(h);
	cylinder.print();

	system("pause");
	return 0;
}

Where do you set the radius of your cylinderType? The math look good(just a cursory glance at cylinderType though so assuming that the calcCir() and calcArea() functions work.). Note that setting it for circleType doesn't set it for cylinderType.

A little thing to fix at well, you set pi in your calcSurface function and then never use it. And you can write height * calcArea() inside the calcVol() function instead of doing it manually. These are just minor "errors" and the code should work find regardless.
Last edited on
Okay, I think what I need to fix is really the input regarding the cylinderType.h and cylinderType.cpp
I am going to work on it a bit and see where I go. If I get stumped or get past the problem I will let you know!
Yeah, tried different things over the week. Nothing seems to work. The output is really weird. When it gets to the cylinder it is just a very long number.
Topic archived. No new replies allowed.