用面对对象的方法,编程实现求长方体的体积和表面积,数据成员包括length(长)、width(宽)、height(高),
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/09/28 21:31:20
用面对对象的方法,编程实现求长方体的体积和表面积,数据成员包括length(长)、width(宽)、height(高),要求用成员函数实现以下功能 1有一个无参构造函数和有参构造函数;2、由键盘输入长方体的长,宽,高;3,输入长方体的长宽高;4,计算长方体的表面积和体积并输出
/*输入长方体的长、宽、高(空格隔开) : 3 4 5Ca属性 :长 3宽 4高 5体积 : 60表面积 : 94Cb属性 :长 0宽 0高 0体积 : 0表面积 : 0Press any key to continue*/#include <iostream>
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;
}
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;
}
用面对对象的方法,编程实现求长方体的体积和表面积,数据成员包括length(长)、width(宽)、height(高),
需要求3个长方柱的体积,请编写一个基于对象的程序.数据成员包括length长、width宽、height高.
VB编程:定义一个Box(盒子)类,在该类定义中包括数据成员 length(长)、width(宽)和height(高);
1、按下列要求编程:定义一个描述矩形的类Rectangle,包括的数据成员有宽(width)和长(length),并实现
定义一个Box(盒子)类,在该类定义中包括数据成员: length(长),width(宽)和height(
跟类的定义有关的.按下列要求编程:(1)定义一个描述矩形的类Rectangle,包括的数据成员有宽(width)和长(l
C++定义描述矩形的类Rectangle,其数据成员为矩形的中心坐标(X,Y)、长(Length)与宽(Width).
C++问题:定义一个Rectangle类,包括两个数据成员length和width,以及用于求长方形面积的成员函数.
求大神用c++设计一个长方体类,包括长,宽,高等私有数据成员,用友元函数的方法求长方体的体积.
定义一个描述长方体的类,类中有长、宽、高三个成员,定义一个方法求长方体的体积、表面积.
定义一个矩形类CRect,其数据成员包括左上角坐标,长和宽,其函数成员包括设置矩形的大小(SetSize),设置矩形左上
长:5dm,宽:3dm,高:2dm(长方体).求表面积和体积.