📄 shiti2_4_2.cpp
字号:
#include<iostream.h>
class Cube
{
public:
Cube()
{
length=width=high=1;
cout<<"Cube's default constructor."<<endl;
}
Cube(int x,int y,int z)
{
length=x;
width=y;
high=z;
cout<<"Cube's constructor."<<endl;
}
Cube(Cube& obj)
{
length=obj.length;
width=obj.width;
high=obj.high;
cout<<"Cube's copy constructor."<<endl;
}
Cube& operator=(const Cube& obj)
{
length=obj.length;
width=obj.width;
high=obj.high;
cout<<"Cube's assignment operator."<<endl;
return *this;
}
int Surface(){return 2*(length*width+length*high+width*high);}
int Volume(){return length*width*high;}
private:
int length,width,high;
};
void main()
{
Cube c1;
cout<<"cube 1:surface="<<c1.Surface()<<"volume="<<c1.Volume()<<endl;
Cube c2(10,10,10);
cout<<"cube 2:surface="<<c2.Surface()<<"volume="<<c2.Volume()<<endl;
c1=c2;
cout<<"cube 1(2):surface="<<c1.Surface()<<"volume="<<c2.Volume()<<endl;
Cube c3(c1);
cout<<"cube 3(1):surface="<<c3.Surface()<<"volume="<<c3.Volume()<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -