-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassConstr1
More file actions
70 lines (52 loc) · 1.16 KB
/
ClassConstr1
File metadata and controls
70 lines (52 loc) · 1.16 KB
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
#include <cstdlib>
#include <iostream>
using namespace std;
#include <math.h>
const double PI = 3.14159;
// class interface (definition)
class Circle
{
public:
// constructors
Circle(); // default constructor
Circle(const Circle &); // copy constructor
// member functions (methods)
void SetRadius(double); // modifier that sets new radius
double Area();
private:
// member variables (data)
double radius; // circle's radius
};
int main()
{
Circle myCircle; // circle object used as an example
double circleArea = 0.0; // area of the circle
double userInput = 0.0; // user input for radius of circle
cout << "Enter radius of the circle: ";
cin >> userInput;
myCircle.SetRadius(userInput);
circleArea = myCircle.Area();
cout << "The area is " << circleArea << endl << endl;
return 0;
}// end of main
// class implementation
// default constructor
Circle::Circle()
{
radius = 0.0;
}
// copy constructor
Circle::Circle(const Circle & Object)
{
radius = Object.radius;
}
// sets the radius of the circle
void Circle::SetRadius(double IncomingRadius)
{
radius = IncomingRadius;
}
// computes the area of the circle
double Circle::Area()
{
return(PI * pow(radius, 2));
}