注册 登录
编程论坛 C++教室

计算一个房间需要多少张墙纸

hmsabc 发布于 2010-08-17 20:14, 1264 次点击
程序代码:
// 计算一个房间需要多少张墙纸

#include<iostream>
using namespace std;

int main()
{
    double height = 0.0,width = 0.0,length = 0.0;             // 房间尺寸,长、宽、高,初始值均为 0
    double perimeter = 0.0;                                   // 房间的周长

    const double rollwidth = 20.0;                            // 墙纸宽
    const double rolllength = 12.0;                           // 墙纸长

    int strips_per_roll = 0;                                  // 一列有多少张
    int strips_reqd = 0;                                      // 有多少列
    int nrolls = 0;                                           // 需要的总张数

    cout << endl;                                            
    cout << "请输入房间的高度 cm:";
    cin >> height;                                            //输入房间高度
    cout << endl;
    cout << "请输入房间的长度和宽度 cm:";
    cin >> length >> width;                                   //输入房间的长和宽
    strips_per_roll =  height / rolllength;                   // 算出每列需要多少张(数据类型转换)
    perimeter = 2.0 * ( length + width);                      // 算出房间的周长
    strips_reqd = perimeter / rollwidth;                      // 算出有多少列(数据类型转换)
    nrolls = strips_reqd * strips_per_roll;                   // 总的需要多少张
    cout << endl;
    cout <<"在垂直方向一列有多少张:"<< strips_per_roll << endl << endl;
    cout <<"房间的周长是: " << perimeter << endl << endl;
    cout <<"在水平方向有多少列:" << strips_reqd << endl << endl;
    cout << "你的房间需要 " << " " << nrolls << " " << "张墙纸。" << endl << endl;
    system("pause");
    return 0;
}
如果照此程序采购墙纸,会有什么结果?如果你是设计人员,如何改进此程序?
7 回复
#2
mxs8102010-08-17 21:11
不知道墙纸需要覆盖到哪些面?
墙纸是否可以同时处于不同的平面?
#3
ToBeOOP2010-08-17 21:26
这程序是《visual C++ 2008 入门经典》里的例题,上面有解释的。。。
#4
hmsabc2010-08-17 22:34
回复 3楼 ToBeOOP
厉害!
#5
carmeloyin2010-08-18 19:31
从这个程序看,墙纸是可以同时贴在2个面上的,而且只贴四周,不贴顶和地
而且可以切割
#6
lisypro2010-08-18 21:07

介绍一个学习VC的群11619730
收费的群,所以有资学老师解答问题,有问必答。
#7
hmsabc2010-08-18 22:32
回复 5楼 carmeloyin
不是可以切割,是不能贴满。当然,依照程序来看,顶和底都没有用墙纸。事实上,一般也不用嘛。
#8
大天涯浪子2010-08-19 11:31
回复 3楼 ToBeOOP
厉害!
1