Skip to content

Commit 84ad48b

Browse files
Create ClassConstr1
1 parent cb946e0 commit 84ad48b

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

ClassConstr1

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <cstdlib>
2+
#include <iostream>
3+
4+
using namespace std;
5+
6+
7+
#include <math.h>
8+
9+
10+
const double PI = 3.14159;
11+
12+
// class interface (definition)
13+
class Circle
14+
{
15+
public:
16+
// constructors
17+
Circle(); // default constructor
18+
Circle(const Circle &); // copy constructor
19+
20+
// member functions (methods)
21+
void SetRadius(double); // modifier that sets new radius
22+
double Area();
23+
24+
private:
25+
// member variables (data)
26+
double radius; // circle's radius
27+
};
28+
29+
int main()
30+
{
31+
Circle myCircle; // circle object used as an example
32+
double circleArea = 0.0; // area of the circle
33+
double userInput = 0.0; // user input for radius of circle
34+
35+
cout << "Enter radius of the circle: ";
36+
cin >> userInput;
37+
38+
myCircle.SetRadius(userInput);
39+
circleArea = myCircle.Area();
40+
41+
cout << "The area is " << circleArea << endl << endl;
42+
43+
return 0;
44+
}// end of main
45+
46+
// class implementation
47+
48+
// default constructor
49+
Circle::Circle()
50+
{
51+
radius = 0.0;
52+
}
53+
54+
// copy constructor
55+
Circle::Circle(const Circle & Object)
56+
{
57+
radius = Object.radius;
58+
}
59+
60+
// sets the radius of the circle
61+
void Circle::SetRadius(double IncomingRadius)
62+
{
63+
radius = IncomingRadius;
64+
}
65+
66+
// computes the area of the circle
67+
double Circle::Area()
68+
{
69+
return(PI * pow(radius, 2));
70+
}

0 commit comments

Comments
 (0)