1. 编程实现一个长方体类 cuboid
成员变量包括:
length(长)
width(宽)
height(高)
要求成员函数实现以下功能
输入长方体的长、宽、高 void set(float length, float width, float height);
计算长方体的总棱长 float edge();
计算长方体的表面积 float surface();
计算长方体的体积 float volume();
判断长方体是否为正方体 bool iscube();
获取长方体的长、宽、高 float getlength(); float getwidth(); float getheight();
#include<iostream>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<cstdio>
#include<cstring>
using namespace std;
class cftl
{
public:
void set(float a, float b, float c);
float edge();
float surface();
float volume();
bool iscube();
float getlength();
float getwidth();
float getheight();
private:
float length,width,height;
};
void cftl::set(float a, float b, float c)
{
length=a;width=b;height=c;
}
float cftl::edge()
{
return (4*(length+width+height));
}
float cftl::surface()
{
return (2*(length*width+length*height+width*height));
}
float cftl::volume()
{
return (length*width*height);
}
bool cftl::iscube()
{
if(length==width&&height==width)
{
cout<<"是正方体";
}
else
cout<<"长方体";
}
float cftl::getlength()
{
return (length);
}
float cftl::getwidth()
{
return (width);
}
float cftl::getheight()
{
return (height);
}
int main()
{
cftl q;
int a,b,c;
cout<<"请输入长方体的长宽高:";
cin>>a>>b>>c;
q.set(a, b, c);
cout<<"周长"<<q.edge()<<endl;
cout<<"表面积"<<q.surface()<<endl;
cout<<"体积"<<q.volume()<<endl;
q.iscube();
cout<<endl;
cout<<"长"<<q.getlength()<<endl;
cout<<"宽"<<q.getwidth()<<endl;
cout<<"高"<<q.getheight()<<endl;
}