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

النسخة 8الرقم المعياري الدولي: 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

النسخة 8الرقم المعياري الدولي: 978-1285867410
تمرين 7
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);
Write the C++ code that will assign the circumference of oneCircle to a double variable named circumference1.
التوضيح
موثّق
like image
like image

Program plan:
• Define a class named "C...

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