
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
Edition 8ISBN: 978-1285867410
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
Edition 8ISBN: 978-1285867410 Exercise 5
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);
Is the following a legal C++ statement? Why or why not?
cout ? "The area is : " ? calculateArea();
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);
Is the following a legal C++ statement? Why or why not?
cout ? "The area is : " ? calculateArea();
Explanation
Analyzing the given statement:
The give...
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
Why don’t you like this exercise?
Other Minimum 8 character and maximum 255 character
Character 255