Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Most of the code is written for a Point-Circle-Cylinder class hierarchy and the main function. A Point object can be specified by giving its

Problem

Most of the code is written for a Point-Circle-Cylinder class hierarchy and the main function.

  • A Point object can be specified by giving its position (coordinates)
  • A Circle object can be specified by giving its position (coordinates) and a radius
  • A Cylinder object can be specified by giving its position, radius, and a height

Attached is the partial program without the implementation of class Cylinder.

You are required to implement the class Cylinder.

Runtime output

Base Radius: 4.00 Base Circumference: 25.13 Base Area: 50.27 Cylinder height: 3.90 Cylinder surface area: 198.55 Cylinder volume: 196.04

Enter x Coordinates of the center: 1

Enter y Coordinate of the center: 2

Enter base radius: 10.0

Enter cylinder height: 20.0

***** Cylinder 3 ***** Base Center: (1.00, 2.00)

Base Radius: 10.00 Base Circumference: 62.83 Base Area: 314.16 Cylinder height: 20.00 Cylinder surface area: 1884.96 Cylinder volume: 6283.20

Partial coding

Attached is the program for lab 7. You need to complete the constructor and functions in the class Cylinder.

#include #include using namespace std; class pointType { public: void setPoint(double x, double y); void print() const; double getX() const; double getY() const; pointType(double x = 0.0, double y = 0.0); protected: double xCoordinate; double yCoordinate; }; class circleType: public pointType { public: void print() const; void setRadius(double r); double getRadius() const; double getCircumference() const; double getArea() const; circleType(double x = 0.0, double y = 0.0, double r = 0.0); protected: double radius; }; class cylinderType: public circleType { public: void print() const; void setHeight(double h); void setBaseCenter(double x, double y); void setCenterRadiusHeight(double x, double y, double r, double h); double getHeight() const; double getVolume() const; double getSurfaceArea() const; cylinderType(double x = 0.0, double y = 0.0, double r = 0.0, double h = 0.0); protected: double height; }; void pointType::setPoint(double x, double y) { xCoordinate = x; yCoordinate = y; }

void pointType::print() const { cout << "(" << xCoordinate << ", " << yCoordinate << ")" << endl; }

double pointType::getX() const { return xCoordinate; }

double pointType::getY() const { return yCoordinate; }

pointType::pointType(double x, double y) { xCoordinate = x; yCoordinate = y; } void circleType::print() const { cout << "Base Center: "; pointType::print(); cout << endl; cout << "Base Radius: " << radius << endl; cout << "Base Circumference: " << getCircumference() << endl; cout << "Base Area: " << getArea() << endl; }

void circleType::setRadius(double r) { radius = r; }

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

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

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

circleType::circleType(double x, double y, double r) :pointType(x,y) { radius = r; } //YOUR CODE TO IMPLMENT THE CONSTRUCTORS AND FUNCTIONS IN THE CLASS Cylinder

int main() { cylinderType cylinder1(3, 2.5, 4, 2.5); cylinderType cylinder2;

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

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

cylinder2.setPoint(-2.5, 7); cylinder2.setRadius(4); cylinder2.setHeight(3.9); cout << "***** Cylinder 2 *****" << endl; cylinder2.print(); cout << endl;

double x, y; double r; double h;

cylinderType cylinder3;

cout << "Enter x Coordinates of the center: "; cin >> x; cout << endl;

cout << "Enter y Coordinate of the center: "; cin >> y; cout << endl;

cout << "Enter base radius: "; cin >> r; cout << endl;

cout << "Enter cylinder height: "; cin >> h; cout << endl;

cylinder3.setCenterRadiusHeight(x, y, r, h);

cout << "***** Cylinder 3 *****" << endl; cylinder3.print(); cout << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions