【C++】primer plus 练习7.3

来源:互联网 发布:淘宝代写软文怎么发布 编辑:程序博客网 时间:2024/05/19 18:10
//计算长方体的体积#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;}

1 0