Here is a base class, pointType. //Class pointType.h #ifndef H_PointType #define
ID: 3628339 • Letter: H
Question
Here is a base class, pointType.//Class pointType.h
#ifndef H_PointType
#define H_PointType
class pointType
{
public:
void setPoint(double x, double y);
void print() const;
double getX() const;
double getY() const;
pointType(double x = 0.0, double y = 0.0);
protected:
double xCoordinate;
double yCoordinate;
};
#endif
//pointType.cpp
//Implementation File pointTypeImp.cpp
#include <iostream>
#include "pointType.h"
using namespace std;
void pointType::setPoint(double x, double y)
{
xCoordinate = x;
yCoordinate = y;
}
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;
}
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
//circleType.cpp
//Implementation File circleTypeImp.cpp
#include <iostream>
#include "circleType.h"
using namespace std;
void circleType::print()
{
cout << "this circle has centre" << x << "and " << y << " radius is "<< r <<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;
}
circleType::circleType(double x = 0.0, double y = 0.0, double r = 0.0):pointType(x,y)
{
setRadius(r);
}
#include<iostream>
using namespace std;
int main()
{
circleType c1;
c1.setRadius(5);
cout << c1.getCircumference() << " circumference " << endl;
cout << c1.getArea() << " Area " << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.