-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path09_circle.cpp
65 lines (51 loc) · 1.3 KB
/
09_circle.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// // Define a class Circle and define an instance member function to find the area of the circle.
// // Header files
#include <iostream>
// // use namespace
using namespace std;
// // define class Circle
class Circle
{
private:
// // instance member variables
double radius, area = 0;
public:
// // instance member function to set radius of circle
void setRadius(int r)
{
radius = r;
}
// // instance member function to get radius of circle
double getRadius(int l)
{
return radius;
}
// // instance member function to calculate area of circle
double calculateArea()
{
area = 22.0 / 7 * radius * radius;
return area;
}
// // instance member function to get the area of circle
double getArea()
{
return area;
}
};
// // Main Function Start
int main()
{
Circle cir1; // create object of Circle
double rad, area;
// // Get radius of a circle to find its area
cout << "\nEnter Radius of A Circle => ";
cin >> rad;
cir1.setRadius(rad); // set radius of circle
area = cir1.calculateArea(); // find area
// // display area of circle
cout << "\nArea of Circle => " << area;
cout << endl; // Add new line
cin.ignore();
return 0;
}
// // Main Function End