7.3
#include <iostream>
using namespace std;
struct box{
char marker[40];
float height;
float width;
float length;
float volume;
};
void show(const box b);
void set(box &b);
void main73()
{
box b[2]={{"mybox",5,6,8,0},{"herbox",10,10,10,0}};//初始化结构数组
cout<<"now the box valus is :"<<endl;
cout<<"b[0] is :"<<endl;
show(b[0]);
cout<<"b[1] is :"<<endl;
show(b[1]);
set(b[0]); //因为我这里是数组,数组传递的时候其实就是传递其引用!
set(b[1]);
cout<<"after set ,the box valus is:\n\n\n";
cout<<"b[0] is :"<<endl;
show(b[0]);
cout<<"b[1] is :"<<endl;
show(b[1]);
system("pause");
}
void show(const box b)
{
cout<<"maker:"<<b.marker<<endl;
cout<<"height:"<<b.height<<"\nwidth:"<<b.width<<"\nlength:"<<b.length<<endl;
cout<<"volume:"<<b.volume<<endl;
}
void set(box &b)
{
b.volume=b.height*b.width*b.length;
}