欢迎来到天天文库
浏览记录
ID:60763248
大小:53.50 KB
页数:9页
时间:2020-12-15
《最新C++ Exercise 6教学提纲.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、__________________________________________________学生实验报告学生姓名学号同组人实验项目Exercise6√必修□选修□演示性实验□验证性实验□操作性实验√综合性实验实验地点实验仪器台号指导教师实验日期及节次一、实验综述1、实验目的及要求1.根据所学知识,在上机前分析下列程序的运行结果,然后上机核对一下自己的结果正确与否,并给出其原因。classdemo{intx,y;public:demo(inta=1,intb=2){x=a;y=b;cout<<"Constructorbecalled...";}demo(demo&d){
2、x=d.x;y=d.y;cout<<"CopyConstructorbecalled...";}~demo(){cout<<"Destructorbecalled...";}voidshow(){cout<<"X="<3、箱,已知长方体的每个面木材的造价分别为:主视面35.2元/平米,侧视面21.8元/平米,俯视面11.3元/平米,要求编写一个长方体的类,输入长、宽、高后计算包装木箱的总造价.要求包括:构造函数和析构函数、拷贝构造函数、每个面的面积函数等。3.建立一个类STR,将任意整数转换为相应的字符串。例如,整数3456转换为字符串”3456”,具体要求如下:(1)私有数据成员intnum;被转换的整数。chars[15];存放转换后的字符串。(2)公有成员函数STR(intx);构造函数。voiditoa();实现将num转换成字符串并存放在字符串数组s中。voidshow();输出整数及转4、换后的字符串。编写主程序测试,其中字符串要求输出其长度。4.定义一个满足如下要求的Date类(用构造函数完成初始化):(1)用日/月/年的格式输出日期;(2)可运行在日期上加一天的操作;(3)设置日期操作。编写主程序进行测试。2、实验仪器、设备或软件PCVC++6.0二、实验过程(实验步骤、记录、数据、分析)1.预期:Constructorbecalled...X=1Y=2Constructorbecalled...X=3Y=5Constructorbecalled...X=3Y=5Constructorbecalled...Constructorbecalled...收集于网络5、,如有侵权请联系管理员删除__________________________________________________Constructorbecalled...2.#includeconstfloatPrice1=35.2f;constfloatPrice2=21.8f;constfloatPrice3=11.3f;classrec{floatwidth,height,length;public:rec(floata=3,floatb=2,floatc=2);floatprices(float,float,float);floatarea1(fl6、oat,float);floatarea2(float,float);floatarea3(float,float);rec(rec&r);~rec(){}};rec::rec(floata,floatb,floatc){length=a;width=b;height=c;}rec::rec(rec&r){length=r.length;width=r.width;height=r.height;cout<<"copyconstructorcalled:"<7、eight;}floatrec::area2(floatwidth,floatheight){returnwidth*height;}floatrec::area3(floatlength,floatwidth){returnlength*width;}floatrec::prices(floatlenght,floatwidth,floatheight){floatpr;收集于网络,如有侵权请联系管理员删除____________________________________
3、箱,已知长方体的每个面木材的造价分别为:主视面35.2元/平米,侧视面21.8元/平米,俯视面11.3元/平米,要求编写一个长方体的类,输入长、宽、高后计算包装木箱的总造价.要求包括:构造函数和析构函数、拷贝构造函数、每个面的面积函数等。3.建立一个类STR,将任意整数转换为相应的字符串。例如,整数3456转换为字符串”3456”,具体要求如下:(1)私有数据成员intnum;被转换的整数。chars[15];存放转换后的字符串。(2)公有成员函数STR(intx);构造函数。voiditoa();实现将num转换成字符串并存放在字符串数组s中。voidshow();输出整数及转
4、换后的字符串。编写主程序测试,其中字符串要求输出其长度。4.定义一个满足如下要求的Date类(用构造函数完成初始化):(1)用日/月/年的格式输出日期;(2)可运行在日期上加一天的操作;(3)设置日期操作。编写主程序进行测试。2、实验仪器、设备或软件PCVC++6.0二、实验过程(实验步骤、记录、数据、分析)1.预期:Constructorbecalled...X=1Y=2Constructorbecalled...X=3Y=5Constructorbecalled...X=3Y=5Constructorbecalled...Constructorbecalled...收集于网络
5、,如有侵权请联系管理员删除__________________________________________________Constructorbecalled...2.#includeconstfloatPrice1=35.2f;constfloatPrice2=21.8f;constfloatPrice3=11.3f;classrec{floatwidth,height,length;public:rec(floata=3,floatb=2,floatc=2);floatprices(float,float,float);floatarea1(fl
6、oat,float);floatarea2(float,float);floatarea3(float,float);rec(rec&r);~rec(){}};rec::rec(floata,floatb,floatc){length=a;width=b;height=c;}rec::rec(rec&r){length=r.length;width=r.width;height=r.height;cout<<"copyconstructorcalled:"<7、eight;}floatrec::area2(floatwidth,floatheight){returnwidth*height;}floatrec::area3(floatlength,floatwidth){returnlength*width;}floatrec::prices(floatlenght,floatwidth,floatheight){floatpr;收集于网络,如有侵权请联系管理员删除____________________________________
7、eight;}floatrec::area2(floatwidth,floatheight){returnwidth*height;}floatrec::area3(floatlength,floatwidth){returnlength*width;}floatrec::prices(floatlenght,floatwidth,floatheight){floatpr;收集于网络,如有侵权请联系管理员删除____________________________________
此文档下载收益归作者所有