-
Notifications
You must be signed in to change notification settings - Fork 0
/
CircleAIO.cpp
47 lines (39 loc) · 1.31 KB
/
CircleAIO.cpp
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
#include <iostream> // using IO functions
#include <string> // using string
using namespace std;
class Circle {
private:
double radius; // Data member (Variable)
string color; // Data member (Variable)
public:
// Constructor with default values for data members
Circle(double r = 1.0, string c = "red") {
radius = r;
color = c;
}
double getRadius() { // Member function (Getter)
return radius;
}
string getColor() { // Member function (Getter)
return color;
}
double getArea() { // Member function
return radius*radius*3.1416;
}
}; // need to end the class declaration with a semi-colon
// Test driver function
int main() {
// Construct a Circle instance
Circle c1(1.2, "blue");
cout << "Radius=" << c1.getRadius() << " Area=" << c1.getArea()
<< " Color=" << c1.getColor() << endl;
// Construct another Circle instance
Circle c2(3.4); // default color
cout << "Radius=" << c2.getRadius() << " Area=" << c2.getArea()
<< " Color=" << c2.getColor() << endl;
// Construct a Circle instance using default no-arg constructor
Circle c3; // default radius and color
cout << "Radius=" << c3.getRadius() << " Area=" << c3.getArea()
<< " Color=" << c3.getColor() << endl;
return 0;
}