#include <iostream>
using namespace std;
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
void func1(box a);
void func2(box * ar);
int main() {
box ar={
"canon",
12.3,
4.2,
6.7,
9.3
};
func1(ar);
func2(&ar);
cout<<"\nNew struct:"<<endl;
func1(ar);
return 0;
}
void func1(box a)
{
cout<<"maker: "<<a.maker<<endl;
cout<<"height: "<<a.height<<endl;
cout<<"width: "<<a.width<<endl;
cout<<"length: "<<a.length<<endl;
cout<<"volume: "<<a.volume<<endl;
}
void func2(box * ar)
{
ar->volume=ar->height*ar->width*ar->length;
}
C++primer plus 6th 第7章7.3编程答案
最新推荐文章于 2025-11-30 21:05:18 发布
本文通过一个具体的C++代码示例,展示了如何定义和使用结构体,包括成员变量和函数调用。示例中,我们创建了一个box结构体,包含制造商名称、高度、宽度、长度和体积等属性,并定义了两个函数来处理和展示这些数据。
232

被折叠的 条评论
为什么被折叠?



