📄 privatemen.cpp
字号:
#include <iostream>
using std::cout;
using std::endl;
class Box{
public:
//Construtor
Box(double length=1.0,double width=1.0,double height=1.0);
//Function to calculate the volume of a box
double volume(){
return length*width*height;
}
double getlength();
private:
double length;
double width;
double height;
};
Box::Box(double lvalue,double wvalue,double hvalue):
length(lvalue),width(wvalue),height(hvalue){
cout<<"Box constructor called"<<endl;
cout<<lvalue<<" "<<wvalue<<" "<<hvalue<<endl;
if (length<=0)
length=1.0;
if (width<=0)
width=0;
if (height<=0)
height=0;
}
inline double Box::getlength(){return length;}
void main(){
Box firstBox(80.0,50.0,40.0);
cout<<endl;
/*cout<<"Size of first Box object is "
<<firstBox.length<<" by "
<<firstBox.width<<" by "
<<firstBox.height
<<endl;*/
cout<<"Volume of first Box object is "<<firstBox.volume()
<<endl;
Box secondBox;
/*secondBox.length=10.0;
secondBox.width=5.0;
secondBox.height=4.0;*/
cout<<endl;
/*out<<"Size of first Box object is "
<<secondBox.length<<" by "
<<secondBox.width<<" by "
<<secondBox.height
<<endl;*/
cout<<"Volume of second Box object is "<<secondBox.volume()
<<endl;
cout<<endl;
Box* pthirdBox=new Box(15.0,20.0,8.0);
cout<<endl;
cout<<"Volume of third Box object is "<<pthirdBox->volume()
<<endl;
cout<<pthirdBox->getlength()<<endl;
delete pthirdBox;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -