Related questions with answers

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

Solutions

Verified
Answered 3 months ago
Step 1
1 of 2
class Circle{
private:
    double radius;
    
public:
    //function to get radius
    //it is declared const because it
    //will not change the calling object
    //in any manner
    double getRadius() const{
        return radius;
    }
    
    //function to set radius
    //accepts an argument of type double
    //and sets it to the radius member
    void setRadius(double r){
        radius = r;
    }
    
    //function to get area
    //declared const for the same reasons
    //as above
    double getArea() const{
        return 3.14159 * radius * radius;
    }
};

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Create an account to view solutions

By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Continue with GoogleContinue with Facebook

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263 (6 more)David A. Patterson, John L. Hennessy
220 solutions
Starting Out with C++ from Control Structures to Objects 8th Edition by Godfrey Muganda, Judy Walters, Tony Gaddis

Starting Out with C++ from Control Structures to Objects

8th EditionISBN: 9780133769395 (11 more)Godfrey Muganda, Judy Walters, Tony Gaddis
1,294 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777 (1 more)Ramez Elmasri, Shamkant B. Navathe
687 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
726 solutions

More related questions

1/2

1/3