expand icon
book C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith cover

C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith

Edition 8ISBN: 978-1285867410
book C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith cover

C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith

Edition 8ISBN: 978-1285867410
Exercise 4
Creating a Class in C++
In this exercise, you use what you have learned about creating and using a programmer-defined class. Study the following code, and then answer Questions.
class Circle{public:void setRadius(double);double getRadius();double calculateCircumference();double calculateArea();private:double radius; // Radius of this circleconst double PI = 3.14159;};void Circle::setRadius(double rad){radius = rad;}double Circle::getRadius(){return radius;}double Circle::calculateCircumference(){return (2 * PI * radius)}double Circle::calculateArea(){return(PI * radius * radius)}
In the following exercise, assume that a Circle object named oneCircle has been created in a program that uses the Circle class, and radius is given a value as shown in the following code:
Circle oneCircle;oneCircle.setRadius(4.5);
What is the output when the following line of C++ code executes?
cout ? "The circumference is : " ? oneCircle.calculateCircumference();
Explanation
Verified
like image
like image

Output of the code:
When executing the ...

close menu
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
cross icon