长方体类(受贺利坚的代码的启发,谢谢老师)

#include<iostream>
using namespace std;
class Bulk
{
protected:
float lengh;
float height;
float width;
float area;
float volume;
public:
void get_value();
void display();
void get_volume();
void get_area();
};
void Bulk::get_value()
{cout<<"请输入长方体的数据"<<endl;
cin>>lengh;
cin>>height;
cin>>width;
}
void Bulk::get_volume()
{
volume=lengh*height*width;
}


void Bulk::get_area()
{area=2*(lengh*height+lengh*width+height*width);
}
void Bulk::display()
{
cout<<"这个长方体的面积为:"<<endl;
cout<<area<<endl;
cout<<"这个长方体的体积为:"<<endl;
cout<<volume<<endl;
}
int main()
{
Bulk t1,t2,t3;
t1.get_value();
t1.get_volume();
t1.get_area();
t1.display();
t2.get_value();
t2.get_volume();
t2.get_area();
t2.display();
t3.get_value();
    t3.get_volume();
t3.get_area();
t3.display();
system("pause");
return 0;}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值