点,派生到圆。

#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;
}

猜你喜欢

转载自blog.csdn.net/gaocui883/article/details/88372837