问题及代码:
/*
*Copyright (c) 2015,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cop
*作者:
*完成日期:2015年3月22日
*版本号:v1.0
*
*问题描述: 已知长方柱的长(length)宽(wide)高(high),求长方柱的表面积和体积
*输入描述:<span style="font-family: Arial, Helvetica, sans-serif;">长方柱的长(length)宽(wide)高(high)</span>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
*输出描述:长方柱的表面积和体积
#include <iostream>
using namespace std;
class Bulk
{
public:
void hy(int,int,int);
double volume();
double areas();
private:
int length;
int with;
int heigth;
};
void Bulk::hy(int l,int w,int h)
{
length=l;
with=w;
heigth=h;
}
double Bulk::volume()
{
return length*with*heigth;
}
double Bulk::areas()
{
return 2*(length*with+length*heigth+with*heigth);
}
int main()
{
Bulk c;
int L,W,H;
int i;
for(i=1;i<=3;i++)
{
cin>>L>>W>>H;
c.hy(L,W,H);
cout<<c.volume()<<" "<<c.areas()<<endl;
}
return 0;
}