//计算长方体的体积
#include<iostream>
struct box //结构体
{
char maker[40];
float height;
float width;
float length;
float volume;
};
void show(box t);
void count(box * pt); //传递地址计算体积
int main()
{
using namespace std;
box graph;
cout <<"Enter graph name :";
cin.getline(graph.maker,40);
cout <<"height =_\b";
cin >>graph.height;
cout <<"width =_\b";
cin >>graph.width;
cout <<"length =_\b";
cin >>graph.length;
count(&graph);
show(graph);
return 0;
}
void show(box t) //显示
{
using namespace std;
cout <<"\tmaker :"<<t.maker<<endl;
cout <<"\theight :"<<t.height<<endl;
cout <<"\twidth :"<<t.width<<endl;
cout <<"\tlength :"<<t.length<<endl;
cout <<"\tvolume :"<<t.volume<<endl;
}
void count(box * pt)
{
pt->volume = pt->height * pt->width * pt->length;
}
【C++】primer plus 练习7.3
最新推荐文章于 2024-08-30 19:51:30 发布