Write a class “Circle” with one data member radius. Write three member functions as follows
o set_radius() that accepts a value in parameter and assigns to radius
o get_area() that calculate and return area
o get_circum() that calculate and return circumference
The program should create two objects of class and input radius for these objects. The program should display area for first object and circumference for second object.
#include <iostream>
using namespace std;
class Circle{
private:
int radius;
const double PI = 3.14;
public:
void set_radius(int r){
radius = r;
}
double get_circum(){
double circum = 2*PI*radius;
return circum;
}
double get_area(){
double area = PI*radius*radius;
return area;
}
};
int main()
{
Circle cx, cy;
cx.set_radius(10);
cy.set_radius(20);
cout << "Circle 1 Area: "<< cx.get_area()<<endl;
cout << "Circle 2 Circumference: "<< cy.get_circum()<<endl;
return 0;
}
Comments
Leave a comment