C== Design a derived class circleType. Every circle has a center and a radius. G
ID: 3630002 • Letter: C
Question
C==Design a derived class circleType.
Every circle has a center and a radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine the position in the x-y plane. The center of a circle is a point in the x-y plane. Design a class, circleType, that can store the radius and center of the circle. Because the center is a point in the x-y plane and you designed the class to capture the properties of a point in the pointType class., you must derive the class circleType from the class pointType. You should be able to perform the usual operations on a circle, such as setting the radius, printing the radius, calculating and printing the area and circumference, and carrying out the usual operations on the center.
Write a test program to test the various operations.
// Specification of circleType
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;
};
Explanation / Answer
#include<iostream>
using namespace std;
class pointType
{
public:
pointType(double x = 0, double y =0)
{
xCoordinate = x;
yCoordinate = y;
}
double getX() {return xCoordinate;}
double getY() {return yCoordinate;}
protected:
double xCoordinate, yCoordinate;
};
// Specification of circleType
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;
};
void circletype::print() const
{
cout <<" circle radius is "<< radius <<endl;
}
void circleType::setradius(double r)
{
radius = r;
}
double circleType::getRadius() const
{
return radius;
}
double circleType::getCircumference() const
{
return 2*3.14159*radius;
}
double circleType::getArea() const
{
return 3.14159*radius*radius;
}
int main()
{
circleType cir;
cir.setradius(5);
cout << "circle circumferenceis " << cir.getCircumference();
cout << " cirlcle Area is " << cir.getArea();
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.