?? 7_5.cpp
字號:
#include<iostream.h>
class point //基類point類的定義
{
public: //公有成員函數(shù)
point(float xx=0, float yy=0);
point(point &p);
~point();
void display(void);
protected: //保護數(shù)據(jù)成員
float x;
float y;
};
point::point(float xx,float yy)
{
x=xx;
y=yy;
cout<<"point類的構(gòu)造函數(shù)被調(diào)用"<<endl;
}
point::point(point &p)
{
x=p.x;
y=p.y;
}
point::~point()
{
cout<<"point類的析構(gòu)函數(shù)被調(diào)用"<<endl;
}
void point::display(void)
{
cout<<"x="<<x<<" y="<<y<<endl;
}
class circle: public point //公有繼承
{
public: //新增公有函數(shù)成員
circle(float a, float b,float c);//初始化
circle(circle &p);
~circle();
void display(void);
float get_cum(void);
float get_area(void);
private: //新增私有數(shù)據(jù)成員
float r;
};
circle::circle(float a, float b, float c):point(a,b)
{
r=c;
cout<<"circle類的構(gòu)造函數(shù)被調(diào)用"<<endl;
}
circle::circle(circle &p):point(p.x,p.y)
{
r=p.r;
}
circle::~circle()
{
cout<<"circle類的析構(gòu)函數(shù)被調(diào)用"<<endl;
}
void circle::display(void)
{
cout<<"r="<<r<<" x="<<x<<" y="<<y<<endl;
point::display();
}
float circle::get_cum(void)
{
return(2*3.14*r);
}
float circle::get_area(void)
{
return(3.14*r*r);
}
int main()
{
circle c(0,0,1); //定義circle類的對象
c.display(); //顯示數(shù)據(jù)
cout<<"周長:"<<c.get_cum()<<endl;
cout<<"面積:"<<c.get_area()<<endl;
return(0);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -