For this question you will write two (2) constructors in the implementation file: CylinderType.cpp
(Assume that the base class CircleType has a default constructor & assigns 1.0 to its private double radius)
part (a) // The first constructor is a default constructor. Please use height as the CylinderType's private member name in the body.
// It will create a CylinderType object with a radius of 1.0 and height of 1.0
part (b) // The second constructor should have two formal parameters: (double rad and double heit).
// For full credit use these formal parameter names in your definition.
// Assume the base class CircleType header file has a mutator function named void setRadius (double); so its radius may be initialized
CircleType header file (CircleType.h)
//CircleType header file
class CircleType
{
private:
double radius;
public:
//default constructor
CircleType()
{
radius=1.0;
}
//mutator function
void setRadius(double r)
{
radius=r;
}
double getRadius()
{
return radius;
}
};
CylinderType Implementation file (CylinderType.cpp)
#include<iostream>
#include "CircleType.h" //including the circletype header file
using namespace std;
// CylinderType inherits CircleType
class CylinderType: public CircleType
{
private:
double height;
public:
//default constructor
CylinderType()
{
height=1.0;
}
//parameterised constructor
CylinderType(double r, double h)
{
height=h;
//calling the mutator function to set the radius
setRadius(r);
}
//function to display the radius and height
void show()
{
cout<<"\nThe radius and height are: ";
cout<<getRadius()<<" and "<<height;
}
};
int main()
{
CylinderType c, d(2.5,4.6);
c.show();
d.show();
return 0;
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.