📄 68.cpp
字号:
#include<iostream.h>
#include<iomanip.h>
class point //point类的定义
{
public: //外部接口
point(int a=0, int b=0); //构造函数
point(const point &p); //拷贝构造函数
~point();
void display(void) const;
void move(int xx,int yy);
private: //私有数据
int x;
int y;
};
//类的实现
point::point(int a,int b)
{
x=a;
y=b;
cout<<"point构造函数被调用"<<endl;
}
point::~point()
{
cout<<"point析构函数被调用"<<endl;
}
point::point(const point &p)
{
x=p.x;
y=p.y;
cout<<"point拷贝构造函数被调用"<<endl;
}
void point::display(void) const
{
cout<<"x="<<x<<",y="<<y<<endl;
}
void point::move(int xx,int yy)
{
x+=xx;
y+=yy;
}
class circle //circle类的定义
{
public: //外部接口
circle(int a=0,int b=0,float c=1); //构造函数
circle(circle &s); //拷贝构造函数
~circle();//析构函数
void display(void);
private: //私有数据成员
const point p;//常对象成员
float r;
};
// 类的实现
circle::circle(int a,int b,float c):p(a,b)
{
if(c<=0)
r=1;
else
r=c;
cout<<"circle构造函数被调用"<<endl;
}
circle::circle(circle &s):p(s.p)
{
r=s.r;
cout<<"circle拷贝构造函数被调用"<<endl;
}
circle::~circle()
{
cout<<"circle析构函数被调用"<<endl;
}
void circle::display(void)
{
p.display();
cout<<"r="<<r<<endl;
}
//类的应用
int main ()
{
int a,b;
float c;
cout<<"请输入圆心的坐标:"<<endl; //提示用户输入圆心坐标
cin>>a>>b;
cout<<"请输入圆的半径:"<<endl;//提示用户输入半径
cin>>c;
circle t(a,b,c); //定义circle 对象
t.display();
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -