📄 friend.cpp
字号:
#include <iostream>
using std::cout;
using std::endl;
class Box{
public:
//Construtor
Box(){
cout<<"Default constructor called"<<endl;
length=width=height=1.0;
}
Box(double lvalue,double wvalue,double hvalue):length(lvalue),width(wvalue),height(hvalue){
cout<<"Box constructor called"<<endl;
}
//Function to calculate the volume of a box
double volume(){
return length*width*height;
}
friend double boxSurface(Box theBox);
private:
double length;
double width;
double height;
};
void main(){
Box firstBox(80.0,50.0,40.0);
cout<<endl;
cout<<"Volume of first Box object is "<<firstBox.volume()
<<endl;
cout<<"Surface of first Box object is "<<boxSurface(firstBox)
<<endl;
}
double boxSurface(Box theBox){
return 2.0*(theBox.length*theBox.width+
theBox.length*theBox.height+
theBox.width*theBox.height);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -