C++ PROGRAMMING: Exercise 2: Chapter 10 defined the class circleType, to impleme
ID: 673112 • Letter: C
Question
C++ PROGRAMMING:
Exercise 2:
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). 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 (5 points).
Some of the operations that can be performed on a cylinder are as follows:
- calculate and print the volume (5 points)
- calculate and print the surface area (5 points)
- set the height (5 points)
- set the radius of the base (5 points)
- set the center of the base (5 points)
Write a program to test various operations on a cylinder (5 points).
Write explanatory comments about all part of your code (2 points).
________________________________________________________________________________________
circleType.h
Explanation / Answer
#include<iostream>
#include "C:MinGWlibgccmingw32.8.1circleType.h"
using namespace std;
class Cylinder: public circleType {
public:
void print();
void setRadiusBase(double r){
if(r>=0){
radius=r;
}else{
radius=0;
}
}
double getRadius(){
return radius;
}
double surfaceArea(){
circleType t=circleType(radius);
double area=t.Area();
return area;
}
double volume(){
double vol=surfaceArea()*height;
return vol;
}
double setCenter(double x1,double y1){
x=x1;
y=y1;
}
Cylinder(double r = 0,double h=0){
radius=r;
height=h;
}
private:
double radius;
double height;
double x,y;
};
int main(){
double r,h;
cout<<"Enter the radius of the base: ";
cin>>r;
cout<<"Enter the height of the cylinder: ";
cin>>h;
Cylinder x;
x=Cylinder(r,h);
double area=x.surfaceArea();
cout<<"Surface area of cylinder: "<<area;<<endl;
double vol=x.volume();
cout<<"Volume of cylinder: "<<vol<<endl;
}
#ifndef CIRCLETYPE_H_INCLUDED
#define CIRCLETYPE_H_INCLUDED
class circleType
{
public:
void print();
void setRadius(double r){
if(r>=0){
radius=r;
}else{
radius=0;
}
}
double getRadius(){
return radius;
}
double Area(){
double area=3.14*radius*radius;
return area;
}
double circumference(){
double circum=2*3.14*radius;
return circum;
}
circleType(double r = 0){
radius=r;
}
private:
double radius;
};
#endif // CIRCLETYPE_H_INCLUDED
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.