Question
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started