Ask Question
Today, 06:53

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

+5
Answers (1)
  1. Today, 10:48
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers