Ask Question

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

+4
Answers (1)
  1. 3 July, 08: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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers