C++找对象的季节——长方形的表面积和体积

#include <iostream>
using namespace std;
class Cube
{
private:
    double length,width,heigh,volume,areas;
public:
    void set_data(double,double,double);
    void get_volume();
    void get_areas();
    void display();
};
int main()
{
    Cube c;
    double l,w,h;
    for(int i=0;i<3;i++)
    {
        cin>>l>>w>>h;
        c.set_data(l,w,h);
        c.get_volume();
        c.get_areas();
        c.display();
    }
    return 0;
}
void Cube::set_data(double l,double w,double h)
{
    length=l;
    width=w;
    heigh=h;
}
void Cube::get_volume()
{
    volume=length*width*heigh;
}
void Cube::get_areas()
{
    areas=2*(length*width+width*heigh+heigh*length);
}
void Cube::display()
{
    cout<<"此长方形体积为:"<<volume<<endl;
    cout<<"此长方形表面积为:"<<areas;
}

我就是懒了点做了个正方体的,不过应该都没问题,如有问题,请赐教。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值