1 / 6
文档名称:

南京信息工程大学实验(实习)报告.docx

格式:docx   大小:66KB   页数:6页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

南京信息工程大学实验(实习)报告.docx

上传人:sssmppp 2020/12/8 文件大小:66 KB

下载得到文件列表

南京信息工程大学实验(实习)报告.docx

文档介绍

文档介绍:: .
南京信息工程大学实验(实习)报告
实验(实习)名称 c卄实验 实验(实习)日期 得分 指■导老师 姜膏山
系计算机 专业 软件工程班级 1 姓名周健学号20122344034
编程题:
,该类有长,宽,高三个数据成员,类屮有获取及修改长宽高的函数, 还有计算长方体表面积和体积的函数。请按照上述声明长方体类并在mnin函数屮定义 该类的一个对象,调用对象的各函数进行测试。
[稈序代码]
#include viostream>〃包含头文件命令
using namespace std; //使用名字空间 std
class Cube
{
private:
int length,width,height;
public:
int GetLe ngth()
{
return length;
}
int GetWidth()
{
return width;
)
int GetHeight()
{
return height;
}
void SetLength(int length)
{
this->le ngth = length;
}
void SetWidth(int width)
{
this->width = width;
}
void SetHeight(int height)
{
this->height = height;
int GetArea()
return 2*(length * width + length * height + width * height); } int GetVol()
{
return length * width * height;
)
};
int main()
{
Cube cube;
ngth(5);
(3);
(4);
cout«MThe area of cube is: n«()«endl; cout«HThe volume of cube is: H«()«endl; return 0;
}
【运行结果】
,然后在main函 数屮进行测试。
#include <iostream> //包含头文件命令
using namespace std; //使用名字空间 std
class Cube
private: int length, width, height;
public:
CubeO {}
Cube(int length, int width, int height):length(length), width(width), height(height){}
int GetLength()
{
return length;
}
int GetWidthO
{
return wi dth;
}
int GetHeig