源程序:
//4.基类是使用极坐标的点类,从它派生一个圆类,圆类用点类的左边作圆心,圆周通过极坐
//标原点,圆类有输出圆心直、圆半径和面积的成员函数。完成类的设计并验证之。
#include < iostream >
#include < cmath >
using namespace std;
class Point//点类
{
protected:
int x, y;
public:
Point() {}
};
class Circular : public Point//圆类,继承点类
{
protected:
double r, area;
public:
Circular(int a, int b)
{
x = a;
y = b;
r = sqrt(x * x + y * y);
area = 3.1415926 * r * r;
}
void printPoint()
{
cout << "圆形直角坐标:(" << x << ", " << y << ")" << endl;
}
void printRadius()
{
cout << "圆的半径:" << r << endl;
}
void printArea()
{
cout << "圆的面积:" << area << endl;
}
};
void main()
{
Circular c(10, 25);
c.printPoint();
c.printRadius();
c.printArea();
system("pause");
}
运行结果: