C++ primer plus 第七章编程练习:3. 下面是一个结构声明:

本文档详细介绍了如何在C++中使用struct定义的box结构,包括按值传递显示成员值的函数show_box,以及通过地址修改volume的vo_box函数。通过实例展示了如何在main函数中调用这些函数,展示了结构体在实际编程中的应用。
摘要由CSDN通过智能技术生成

3. 下面是一个结构声明:

struct box

{

        char maker[40];

        float height;

        float width;

        float length;

        float volume;

};

a. 编写一个函数,按值传递box结构,并显示每个成员的值。

b. 编写一个函数,传递box结构的地址,并将volume成员设置为其他三维长度的乘积。

c. 编写一个使用这两个函数的简单程序。
 

#include <iostream>
using namespace std;
struct box {
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
};
void show_box(box box1);
float vo_box(box* box2);

int main() {
	cout << "the following is example box:";
	box tem;
	cout << "please enter the box maker: ";
	cin >> tem.maker;
	cout << "please enter the height: ";
	cin >> tem.height;
	cout << "please enter the width: ";
	cin >> tem.width;
	cout << "please enter the length: ";
	cin >> tem.length;
	c
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值