#include <iostream>//派生类举例。
using namespace std;//点,派生到圆。
class point //点为基类
{
private:
float x;
float y;
public:
void setp(float a,float b) {x=a,y=b;}
float getx(){return x;}
float gety(){return y;};
};
class circle:public point //公友派生
{
private:
float radius;
public:
void setr(float a) {radius=a;}
float getr() {return radius;}
void dispaly()
{
cout<<"the center of the circle is:"<<"x="<<getx()<<" y="<<gety()<<endl;
cout<<"the radius of the circle is:"<<getr()<<endl;
};
};
int main()
{
class circle ttt;
ttt.setp(5.5,6.3);
ttt.setr(8.04);
ttt.dispaly();
return 0;
}
派生类举例
最新推荐文章于 2021-07-18 22:54:20 发布