Problem with my program

Hi everyone so heres my program the problem is that it only allows me to enter my x and y coordinate and then terminates. Heres the directions and the program thanks for looking and Merry Christmas!!!

Directions:Every circle has a radius. Design a class CircleType that can store the x-y coordinates of the center of the circle and the radius. You should include provisions for setting and getting the coordinates of the center of the circle and the value of the radius. CircleType should also have operations for calculating the circumference and the area of the circle. Every cylinder has a base and a height the base is a circle. Design a class CylinderType that can capture the properties of a cylinder and perform the usual operations of a cylinder. Derive this class from the class CircleType. Some of the operations that can be performed on a cylinder are: calculate volume, calculate surface area, set and get the radius and the coordinates of the center of the base. Write a program to test the capabilities of the CircleType and CylinderType.



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
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
const double PI = 3.1415926;
class Circle
{
private:
	double radius;
	double x;
	double y;
	double circumference;
	double cArea;
public:
Circle()
{
radius = 0;
x = 0;
y = 0;
circumference = 0;
cArea = 0;
}
	int setRadius()
{
cout << "Enter radius: ";
cin >> radius;
	 if (radius < 1)
{
cout << "Please eneter a positive number: ";
cin >> radius;
}
	 return radius;
}
	void setX()
{
cout << "Enter X cordinate: ";
cin >> x;
}
	void setY()
{
cout << "Enter y Coirdinate: ";
cin >> y;
}
	void setCircumference()
{
circumference = PI*(radius*radius);
cout << fixed << showpoint << setprecision(2);
cout << " Circumference is: " <<circumference << endl;
}
	void setCArea()
{
cArea = PI*(radius*radius);
cout << fixed << showpoint << setprecision(2);
cout << " Area is: " <<cArea << endl;
}
};
class Cylinder:public Circle
{
private:
	double height;
	double volume;
	double area;
	int rad;
public:
	Cylinder()
	{
		height = 0.0;
		volume = 0.0;
		area = 0.0;
		rad = 0.0;
	}


	void setheight()
	{
		cout << "What is the height: " << endl;
		cin >> height;
	}

	void setrad()
	{
		cout << "Please enter the radius" << endl;
		cin >> rad;
	}

	void setvolume()
	{
		volume = height * PI*(rad*rad);
		cout << fixed << showpoint << setprecision(2);
		cout << "Volume is : " << volume << endl;
	}

	void setarea()
	{
		area = 2*PI*(rad*rad) + 2*PI*(rad*height);
		cout << fixed << showpoint << setprecision(2);
		cout << "Surface area is : " << area << endl;
	}
};

int main()
{
	Circle shape1;
	Cylinder shape2;

	shape1.setX();
	shape1.setY();
	shape1.setCircumference();
	shape1.setCArea();
	cout << endl;
}






It doesn't wait because your not telling it to. You're setting x and y with std::cin, which waits for user input.
your setCircumference() and setArea() functions simply compute a value based on other things, and in your main() function you do nothing afterwards.

add these lines between lines 110 and 111

1
2
std::cin.get();
return 0;


However, this solution will not suffice as soon as you mistreat std::cin, take a look here:

http://www.daniweb.com/software-development/cpp/threads/90228/flushing-the-input-stream
Last edited on
Topic archived. No new replies allowed.