您的位置:首页 > 编程语言 > C语言/C++

C++利用结构

2015-09-23 21:34 453 查看
#include <iostream>
using std::cout;
using std::endl;

//定义结构
struct Box{
double length;
double width;
double height;
};
double volume(const Box& aBox);
int main(){
Box box={70.0,60.0,40.0};
double boxVolume=volume(box);
cout << "Size of box is:"<<endl
<< "length:"<<box.length<<endl
<<"width:"<<box.width<<endl
<<"height:"<<box.height<<endl;
cout <<"Voluem of box is:"<<boxVolume<<endl;
return 0;
}
//计算体积的函数
double volume(const Box& box){
return box.length*box.width*box.height;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: