Derive a cylinder class frrom circle class. Cylinder should have a private float
ID: 3650715 • Letter: D
Question
Derive a cylinder class frrom circle class. Cylinder should have a private floating point memebr height, constructor, surface area function. Accessor function for height. Data members privateBase class:
class circleType
{
public:
void setRadius (double r) ;
double getRadius();
double area ();
double circumference();
circleType (double r=0);
private:
double radius;
};
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);
}
My code so far:
Class Cylinder : public cirlcleType
{
private:
float height;
public:
cylinderType(float b) circleType(a)
{
setH(b);
}
void setH(float height)
{
h=height;
}
float getH()
{
return h;
}
int main()
{
circleType a;
a.setR(1.5);
cout << "Radius"<<r<<endl;
cylinderType b;
b.setH(12.2)
cout<<"Height"<<h<<endl;
return 0;
}
Explanation / Answer
Please rate...
Program:
======================================================
#include<iostream>
using namespace std;
class circleType
{
public:
void setRadius (double r) ;
double getRadius();
double area ();
double circumference();
circleType (double r=0);
private:
double radius;
};
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);
}
//Cylinder class
class Cylinder:public circleType
{
private:
float height;
public:
Cylinder(double h=0);
void setHeight(double h);
double getHeight();
double surfaceArea();
};
Cylinder::Cylinder(double h)
{
setHeight(h);
}
void Cylinder::setHeight(double h)
{
height=h;
}
double Cylinder::getHeight()
{
return height;
}
double Cylinder::surfaceArea()
{
return ((2*area())+(height*circumference()));
}
int main()
{
circleType a;
a.setRadius(1.5);
double r=a.getRadius();
cout<<"Radius: "<<r<<endl;
Cylinder b;
b.setRadius(1.5);
b.setHeight(12.2);
double h=b.getHeight();
cout<<"Height: "<<h<<endl;
cout<<"Surace Area= "<<b.surfaceArea();
return 0;
}
===========================================================
Sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.