实 验 报 告
实验课程: 数据结构实验
学生姓名: 王维
学 号: 6100212202
专业班级: 网络工程121班
2014年 06月 25日
目录
实验一:测试长方形 1
实验二:顺序表 10
实验三:非循环单链表 28
实验四:循环双链表 48
南昌大学实验报告
---(1)测试长方形
学生姓名: 王维 学 号: 6100212202 专业班级: 网工121班
实验类型:□ 验证 □ 综合 ■ 设计 □ 创新 实验日期: 实验成绩:
【实验题目】
长方形C++类的定义与实现
【实验步骤】
需求分析
定义一个长方形类,能完成设置序号,设置长和宽,求长方形面积,以及重载拷贝初始化构造函数使之能直接通过=赋值。
概要设计
抽象长方形类:
ADT Rectangle
{
数据对象:D={序号,长,宽}
基本操作: void setNo(int i);
void setLength(ElemType a);
void setWidth(ElemType a);
ElemType area();
Rectangle(const Rectangle otherD);
}
详细设计
①长方形类基类
/////////////////////////////////////////////////
//长方形数据结构C++声明(基类)
/////////////////////////////////////////////////
template typename ElemType
class Rectangle
{
public:
//长方形的序号类
class RectangleNo
{
public:
int no;
};
void setNo(int i);
void setLength(ElemType a);
void setWidth(ElemType a);
ElemType area();
//
Rectangle();
Rectangle(const Rectangle otherD);
virtual ~Rectangle();
protected:
ElemType length;
ElemType width;
RectangleNo myNo;
};
/////////////////////////////////////////////////
//长方形数据结构C++实现(基类)
/////////////////////////////////////////////////
template typename ElemType
RectangleElemType::Rectangle()
{
length = width = 0;
cout 自动调用构造函数endl;
}
//拷贝构造函数
template typename ElemType
RectangleElemType::Rectangle(const RectangleElemType otherD)
{
length = otherD.length;
width = otherD.width;
myNo = otherD.myNo;
cout 自动调用拷贝初始化构造函数为(;
coutlength,width)endl;
}
//析构函数
template typename ElemType
RectangleElemType::~Rectangle()
{
cout\n 第myNo.no个长方形对象(length,width)生存期结束endl;
}
//功能:设置长方形的序号
template typename ElemType
void RectangleElemType::setNo(int i)
{
myNo.no=i;
}
//功能:设置长方形长度
template typename ElemType
void RectangleElemType::setLength(ElemType a)
{
length = a;
}
//功能:设置长方形宽度
template typename ElemType
void RectangleElemType::setWidth(ElemType a)
{
width = a;
}
/
您可能关注的文档
- 项目工程质量三检制度完整版及检查表格.doc
- 饰面板类装饰材料在各类建筑及装饰空间中的应用.docx
- 高速公路工程监理招标文件.doc
- 鲤鱼塘水库水利枢纽.doc
- 黄州城区社会治安视频监控系统升级改造工程建议资料V3.docx
- 一个小型电子商务.doc
- 一种新型的基于Web的在线考试系统的计算机科学教育.doc
- 万年历系统C++.doc
- 万维网并不是一种特殊的计算机网络.doc
- 三章程控数字交换与电话通信网.ppt
- 2026年心理咨询师之心理咨询师基础知识考试题库含答案【综合题】.docx
- 2026年心理咨询师之心理咨询师基础知识考试题库含答案【综合题】.docx
- 国际货物运输保险重要考试题含答案.docx
- 2026年心理咨询师之心理咨询师基础知识考试题库含答案【综合题】.docx
- 2026年心理咨询师之心理咨询师基础知识考试题库含答案【综合题】.docx
- 2026年心理咨询师之心理咨询师基础知识考试题库及参考答案【名师推荐】.docx
- 2026年心理咨询师之心理咨询师基础知识考试题库含答案【综合题】.docx
- 2026年心理咨询师之心理咨询师基础知识考试题库及参考答案(典型题).docx
- 2026年心理咨询师之心理咨询师二级技能考试题库(实用).docx
- 2026年心理咨询师之心理咨询师二级技能考试题库附答案【实用】.docx
原创力文档

文档评论(0)