欢迎来到天天文库
浏览记录
ID:55563654
大小:876.00 KB
页数:69页
时间:2020-05-17
《南昌大学数据结构实验报告(C++).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验报告实验课程:数据结构学生姓名:学号:专业班级:网络工程班2014年6月30日目录一、实验一长方形-------------------------3二、实验二循序表------------------13三、实验三链表--------------------29四、实验四循环双链表---------------51南昌大学实验报告---(1)长方形数据结构C++类学生姓名:学号:专业班级:实验类型:□验证■综合□设计□创新实验日期:2014-6-25实验成绩:【实验题目】长方形数据结构C++类【实验步骤】1.需求分析为实现长方形的输入输出和其他操作,我们进行如下需求分析:l长方形相关数据
2、的输出l重载赋值运算符的定义l输出长方形的面积l测试数据2.概要设计为了实现上述功能,需要设定以下模块:主程序模块↓测试长方形模块↓派生长方形模块↓抽象长方形模块设置长设置宽.......各模块之间调用关系如图3.详细设计①长方形数据结构基类templateclassRectangle{public:classRectangleNo{public:intno;};Rectangleoperator=(RectanglerightR);voidsetLength(ElemTypel);voidsetWidth(ElemTypez);voidsetNo(inti
3、);ElemTypeArea(ElemType);Rectangle();Rectangle(constRectangle&otherD);virtual~Rectangle();protected:ElemTypelength;ElemTypewidth;RectangleNomyNo;};templateRectangleRectangle::operator=(RectanglerightR){if(this!=&rightR){length=rightR.length;width=right
4、R.width;myNo=rightR.myNo;cout<<"赋值后,当前的长方形为("<voidRectangle::setLength(ElemTypel){length=1;}templatevoidRectangle::setWidth(ElemTypez){width=z;}templateElemTypeRectangle5、mType>::Area(ElemType){returnlength*width;}templatevoidRectangle::setNo(inti){myNo.no=i;}templateRectangle::Rectangle(){length=width=0;cout<<"自动调用构造函数"<Rectangle::Rectangle(constRectangle&oth6、erD){length=otherD.length;width=otherD.width;myNo=otherD.myNo;cout<<"自动调用拷贝初始化构造函数初始化为(";cout<Rectangle::~Rectangle(){cout<<"第"<classMyRec7、tangle:publicRectangle{public:voidread(istream&in);voiddiaplay(ostream&out)const;};templatevoidMyRectangle::read(istream&in){cout<<"请输入第"<
5、mType>::Area(ElemType){returnlength*width;}templatevoidRectangle::setNo(inti){myNo.no=i;}templateRectangle::Rectangle(){length=width=0;cout<<"自动调用构造函数"<Rectangle::Rectangle(constRectangle&oth
6、erD){length=otherD.length;width=otherD.width;myNo=otherD.myNo;cout<<"自动调用拷贝初始化构造函数初始化为(";cout<Rectangle::~Rectangle(){cout<<"第"<classMyRec
7、tangle:publicRectangle{public:voidread(istream&in);voiddiaplay(ostream&out)const;};templatevoidMyRectangle::read(istream&in){cout<<"请输入第"<
此文档下载收益归作者所有