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 << " " << 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;
}

  

原文地址:https://www.cnblogs.com/ranwuer/p/9718419.html