Question: Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius,

Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in Chapter 10. Some of the operations that can be performed on a cylinder are as follows: calculate and print the volume, calculate and print the surface area, set the height, set the radius of the base, and set the center of the base. I could also use help on the implementation file headers.

***********circleType.cpp*********** #ifndef cylinderType_CPP #define cylinderType_CPP //Implementation File for the class circleType #include #include "circleType.h"

using namespace std;

void circleType::print() { cout << "Radius = " << radius << ", area = " << area() << ", circumference = " << circumference(); }

void circleType::setRadius(double r) { if (r >= 0) radius = r; else radius = 0; }

double circleType::getRadius() { return radius; }

double circleType::area() { return 3.1416 * radius * radius; }

double circleType::circumference() { return 2 * 3.1416 * radius; }

circleType::circleType(double r) { setRadius(r); }

***********circleType.h*********** #ifndef circleType_H #define circleType_H #include

using namespace std;

class circleType { public: void print();

void setRadius(double r); //Function to set the radius. //Postcondition: if (r >= 0) radius = r; // otherwise radius = 0;

double getRadius(); //Function to return the radius. //Postcondition: The value of radius is returned.

double area(); //Function to return the area of a circle. //Postcondition: Area is calculated and returned.

double circumference(); //Function to return the circumference of a circle. //Postcondition: Circumference is calculated and returned.

circleType(double r = 0); //Constructor with a default parameter. //Radius is set according to the parameter. //The default value of the radius is 0.0; //Postcondition: radius = r;

private: double radius; };

#endif

***********cylinderType.cpp*********** #define cylinderType_CPP #ifndef cylinderType_CPP

//Implementation File for the class circleType

#include #include "circleType.h" #include "cylinderType.h"

using namespace std;

void circleType::setRadius(double r) { if (r < 0) throw negativeNumber("Radius");

radius = r; }

double circleType::getRadius() { return radius; }

double circleType::area() { return 3.1416 * radius * radius; }

double circleType::circumference() { return 2 * 3.1416 * radius; }

circleType::circleType(double r) { setRadius(r); }

***********cylinderType.h***********

#ifndef cylinderType_H #define cylinderType_H

#include "circleType.h"

class cylinderType: public circleType { public: void print(); void setHeight(double); double getHeight(); double volume(); double area(); //returns surface area cylinderType(double = 0, double = 0);

private: double height; };

#endif

***********main.cpp*********** #include "circleType.h" #include "cylinderType.h"

using namespace std;

int main() { cylinderType cylinder1(4.5, 6.75); cylinderType cylinder2;

cout << fixed << showpoint; cout << setprecision(2);

cout << "***** Cylinder 1 *****" << endl; cylinder1.print(); cout << endl;

cylinder2.setRadius(3.75); cylinder2.setHeight(8.25);

cout << "***** Cylinder 2 *****" << endl; cylinder2.print(); cout << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!