ex4_3.cpp
来自「《C++面对对象程序设计》的所有源代码和部分头文件」· C++ 代码 · 共 30 行
CPP
30 行
// ex4_3.cpp
// uses structure to model volume of room
#include <iostream>
using namespace std;
////////////////////////////////////////////////////////////////
struct Distance
{
int feet;
float inches;
};
////////////////////////////////////////////////////////////////
struct Volume
{
Distance length;
Distance width;
Distance height;
};
////////////////////////////////////////////////////////////////
int main()
{
float l, w, h;
Volume room1 = { { 16, 3.5 }, { 12, 6.25 }, { 8, 1.75 } };
l = room1.length.feet + room1.length.inches/12.0;
w = room1.width.feet + room1.width.inches /12.0;
h = room1.height.feet + room1.height.inches/12.0;
cout << "Volume = " << l*w*h << " cubic feet\n";
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?