Answer to Question #203110 in C++ for Rabia akbar

Question #203110

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.



1
Expert's answer
2021-06-05T02:13:24-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog