这里涉及到两个问题
1,结构体传值。
2,结构体指针传值的问题。
#pragma region 3.cpp 7.3
/*
3.下面是一个结构声明:
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
a.编写一个函数,按值传递box结构,并显示每个成员的值。
b.编写一个函数,传递box 结构的地址,并将volume成员设置为其他三维长度的乘积。
c.编写一个使用这两个函数的简单程序。
*/
#if 1
#include<iostream>
struct Box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
void box_1(Box);
void box_2(Box*);
int main()
{
using namespace std;
Box box = {"zhang yong jiang",90,40,160,0};
box_1(box);
box_2(&box);
box_1(box);
return 0;
}
//函数的实现
void box_1(Box box)
{
std::cout << box.maker << "\t" << box.height << "\t" << box.width
<< "\t" << box.length << "\t" << box.volume << "\t";
std::cout << std::endl;
}
void box_2(Box* pbox)
{
pbox->volume = pbox->height * pbox->width * pbox->length;
}
#endif
#pragma endregion