Ask Question
12 October, 20:35

Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as: 3.14159 * radius * radius

+3
Answers (1)
  1. 12 October, 23:17
    0
    See explaination

    Explanation:

    #include

    using namespace std;

    class Circle{

    / / private member variable named radius

    private:

    double radius;

    / / get function for radius

    public:

    double getRadius () {

    return radius;

    }

    / / set function for radius

    void setRadius (double rad) {

    radius=rad;

    }

    / / returning area = 3.14159 * radius * radius

    double getArea () {

    return (3.14159 * radius * radius);

    }

    };

    / / Sample run

    int main ()

    {

    / / Declaring object of Circle

    Circle myCircle;

    myCircle. setRadius (5);

    / / printing radius of circle

    cout<<"Radius of circle is: "<< (myCircle. getRadius ()) <
    / / printing area of circle

    cout<<"Area of circle is: "<< (myCircle. getArea ()) <
    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers