c++ 结构体,设置物品体积并输出物品属性

#include <iostream>
using namespace std;

struct box {
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
};

void displayBox(const box b);
void setVolume(box * b);

int main() {
	box b = {"abc", 3, 4, 5, 0};
	setVolume(&b);
	displayBox(b);
	return 0;
}

void displayBox(const box b) {
	cout << "maker: " << b.maker << endl;
	cout << "height: " << b.height << endl;
	cout << "width: " << b.width << endl;
	cout << "length: " << b.length << endl;
	cout << "volume: " << b.volume << endl;
}

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

  

posted @ 2018-09-28 14:34  ranwuer  阅读(358)  评论(0编辑  收藏  举报