#include
using namespace std;
class Rect
{
private:
float length;
float width;
float height;
public:
Rect();
Rect(float length, float width, float height);
void Surface();
void Volume();
~Rect();
};
Rect::Rect()
{
length = 1;
width = 1;
height = 1;
}
Rect::Rect(float length, float width, float height)
{
this->length = length;
this->width = width;
this->height = height;
}
void Rect::Surface()
{
float l=length,w=width,h=height;
cout<<"表面积"<<2*(l*w+l*h+w*h)<}
void Rect::Volume()
{
float l=length,w=width,h=height;
cout<<"体积:"<}
int main(void)
{
float l,w,h;
Rect * pR1 = new Rect();
pR1->Surface();
pR1->Volume();
Rect * pR2 = new Rect(1,2,3);
pR2->Surface();
pR2->Volume();
cout<<"输入长、宽、高:";
cin>>l>>w>>h;
Rect * pR3 = new Rect(l,w,h);
pR3->Surface();
pR3->Volume();
return 0;
}
/*
输入长方体的长、宽、高(空格隔开) : 3 4 5
Ca属性 :
长 3
宽 4
高 5
体积 : 60
表面积 : 94
Cb属性 :
长 0
宽 0
高 0
体积 : 0
表面积 : 0
Press any key to continue
*/
#include
using namespace std;
class Cuboid {
private :
int length;
int width;
int height;
public :
Cuboid() {length = width = height = 0;}
Cuboid(int l,int w,int h) {
length = l;
width = w;
height = h;
}
int Volume() { return length * width * height; }
int SuperficialArea() {
return 2 * (length * width + width * height + height * length);
}
void Show() {
cout << "长 " << length << endl;
cout << "宽 " << width << endl;
cout << "高 " << height << endl;
}
};
int main() {
int len,w,h;
cout << "输入长方体的长、宽、高(空格隔开) : ";
cin >> len >> w >> h;
Cuboid Ca(len,w,h),Cb;
cout << "Ca属性 :\n";
Ca.Show();
cout << "体积 : " << Ca.Volume() << endl;
cout << "表面积 : " << Ca.SuperficialArea() << endl;
cout << "Cb属性 :\n";
Cb.Show();
cout << "体积 : " << Cb.Volume() << endl;
cout << "表面积 : " << Cb.SuperficialArea() << endl;
return 0;
}
#include
using namespace std;
class JUXING
{
public:
int length;
int width;
int height;
int fun()
{
cout<<"请输入长方体的长:";
cin>>this->length;
cout<<"请输入长方体的宽:";
cin>>this->width;
cout<<"请输入长方体的高:";
cout>>this->height;
int area;
area = (length*width+length*height+width*heigth)*2;
cout<<“长方体的表面积为:"< int size;
size = length*width*height;
cout<<"长方体的体积为:"<
}
int main()
{
JUXING. fun();
return 0;
}
#include
using namespace std;
class Rectangle
{
double len,wid,hig;
public:
Rectangle()
{}
Rectangle(double len1,double wid1,double hig1)
{len=len1;wid=wid1;hig=hig1;}
double CaculateArea()
{
return 2*(len*wid+len*hig+hig*wid);
}
virtual double CaculateV()
{
return len*wid*hig;
}
};
int main()
{
double len2,wid2,hig2;
cout<<"请依次输入长宽高: ";
cin>>len2>>wid2>>hig2;
Rectangle C(len2,wid2,hig2);
cout<<"长方体表面积是:"<
return 0;
}
//主函数
public static void main(){
System.out.println("请输入长方体的长:");
Scanner scanner = new Scanner();
int length = scanner.nextInt();
System.out.println("请输入长方体的宽:");
Scanner scanner2 = new Scanner();
int width=scanner2.nextInt();
System.out.println("请输入长方体的高:");
Scanner scanner3 = new Scanner();
int height=sanner3.nextInt();
s(length,width,height);
}
public void s(){}
public void s(int length,int width,int height){
long s;
s=2*(length*width+length*height+width*height);
System.out.println("长方体的表面积:"+s);
long v;
v=length*width*height;
System.out.println("长方体的面积:"+v);
}