-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircleAreaCircumference.cpp
More file actions
39 lines (31 loc) · 1.07 KB
/
CircleAreaCircumference.cpp
File metadata and controls
39 lines (31 loc) · 1.07 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
/*Write a C++ program to define class "Circle" and implement the following:
(i) a constructor
(ii) a member function to find area of a circle
(iii) a member function to find circumference of a circle
*/
#include <iostream>
using namespace std;
// Define the Circle class
class Circle {
public:
float radius; // Member variable to store the radius of the circle
// Constructor to initialize the radius of the circle
Circle(float radius) {
this->radius = radius;
}
// Member function to calculate the area of the circle
float area() {
return 3.14 * radius * radius;
}
// Member function to calculate the circumference of the circle
float circumference() {
return 2 * 3.14 * radius;
}
};
int main() {
Circle circle(5); // Create a Circle object with a radius of 5
// Display the area and circumference of the circle
cout << "The area of the circle is " << circle.area() << endl;
cout << "The circumference of the circle is " << circle.circumference() << endl;
return 0;
}