⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 struct.cpp

📁 我学习C++ Primer Plus过程中写下的课后作业的编程代码
💻 CPP
字号:
//第七章3
//下面是一个结构声明:
//  struct box
//  {
//	    char maker[40];
//		float height;
//		float width;
//		float length;
//		float volume;
//	};	
//a.编写一个函数,按值传递box结构,并显示每个成员的值。
//b.编写一个函数,传递box结构的地址,并将volume成员设置为其他三维长度的乘积。
//c.编写一个使用这两个函数的简单程序。
#include <iostream>
struct box
{
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
};

void box_display(const box & b);
void box_set(box* b);

int main()
{
	box box1={"liu dongming",12,5,9,0};
	box_display(box1);
	box_set(&box1);
	box_display(box1);
	return 0;
}

void box_display(const box & b)
{
	using namespace std;
	cout<<"maker:\t"<<b.maker<<endl;
	cout<<"height:\t"<<b.height<<endl;
	cout<<"width:\t"<<b.width<<endl;
	cout<<"length:\t"<<b.length<<endl;
	cout<<"volume:\t"<<b.volume<<endl;
}

void box_set(box* b)
{
	b->volume = b->height*b->width*b->length;
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -