定义一个点类Point,由此派生出一个圆类

Microsoft Visual C++ 6.0 系统,高手帮忙做一下
2024-12-03 15:54:21
推荐回答(2个)
回答1:

#include
using namespace std;

class point
{
public:
point(int ix,int iy){set(ix,iy);}
void set(int ix,int iy){x = ix;y = iy;}
void disp(){cout << "x: " << x << "\ty: " << y <<" ";}
private:
int x;
int y;
};
class circle:public point
{
public:
circle(int ix,int iy,int r):point(ix,iy),R(r){}
void disp()
{
cout << "圆心坐标为: ";
point::disp();
cout << "圆半径为: " << R << endl;
}
private:
int R;
};

int main()
{
circle c(3,5,10);
c.disp();
return 0;
}

回答2:

我觉得圆类应该作为一个基类好点,其成员可以已是Point类的对象,2点确定一个圆嘛