第三周实验报告4

#include <iostream>

using namespace std;

class Rp
{
public:
 void set_ckg();
 void calculate_va();
 void show_va();
private:
 struct Cfz
 {
 int length;
 int width;
 int height;
 int volume;
 int areas;
 }cfz1,cfz2,cfz3;
};

Rp r;

int main()
{
    r.set_ckg();
    r.calculate_va();
    r.show_va();
 return 0;
}

void Rp::set_ckg()
{
 cout<<"分别输入3个长方柱的长、宽、高:";
 cin>>cfz1.length>>cfz1.width>>cfz1.height;
 cin>>cfz2.length>>cfz2.width>>cfz2.height;
    cin>>cfz3.length>>cfz3.width>>cfz3.height;
}

void Rp::calculate_va()
{
 cfz1.volume=cfz1.length*cfz1.height*cfz1.width;
 cfz1.areas=2*cfz1.length*cfz1.width+2*cfz2.length*cfz1.height+2*cfz1.height*cfz1.width;
 cfz2.volume=cfz2.length*cfz2.width*cfz2.height;
  cfz2.areas=2*cfz2.length*cfz2.width+2*cfz2.length*cfz2.height+2*cfz2.height*cfz2.width;
    cfz3.volume=cfz3.length*cfz3.width*cfz3.height;
 cfz3.areas=2*cfz3.length*cfz3.width+2*cfz3.length*cfz3.height+2*cfz3.height*cfz3.width;


}

void Rp::show_va()
{
 cout<<"3个长方柱的体积分别是:"<<endl;
 cout<<cfz1.volume<<" "<<cfz2.volume<<" "<<cfz3.volume<<endl;
 cout<<"3个长方柱的面积分别是:"<<endl;
 cout<<cfz1.areas<<" "<<cfz2.areas<<" "<<cfz3.areas<<endl;
}

 

 

 

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值