ImageVerifierCode 换一换
格式:DOCX , 页数:42 ,大小:142.92KB ,
资源ID:19705817      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/19705817.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(合肥工业大学程序设计基础实验报告Word文档格式.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

合肥工业大学程序设计基础实验报告Word文档格式.docx

1、类似地,如果分钟数大于59,则小时数向前增1。#include using namespace std;class Timeprivate: int hours, minutes, seconds;public: void get_time() cinhoursminutesseconds; void display_time() couthours:minutesseconds=60) seconds-=60; minutes+; if(minutes minutes-=60; hours+;void main() Time one, two, three;nEnter the first

2、time(hours minutes seconds):; one.get_time();nEnter the second time(hours minutes seconds): two.get_time(); three.add_time(one,two);the result is: three.display_time();基本要求 上机录入、调试上面程序。 运行程序,输入下面两组数据:1 2 34 451 47 56 2 67 100 1 56 200分析运行结果是否正确。分析与思考 定义构造函数对Time类的对象进行初始化(即不用成员函数get_time)。 该程序要求用户输入的

3、分钟数和秒数必须小于60,如何修改程序使得用户在输入分钟数和秒数大于等于60时,也能得到正确的结果。1 2 结果不正确,不是预想的5,1,8 说明程序不能输入大于60 的份和秒。更改后的程序为 Time(int h=0,int m=0,int s=0):hours(h),minutes(m),seconds(s) while(seconds while(minutes Time one(2,34,45), two(1,47,56), three;(2)阅读下面的一段程序代码,代码可能有错误,请仔细分析并体会。class Date public: void Date(); int Date(in

4、t year,int month,int day); void Date(); int &GetYear()return year;GetMonth()return month;GetDay()return day; private: int year=2000; int month=12; int day=31; static bool IsLeapyear;/是否闰年 ;bool Date:IsLeapyear=true;int Date:Date(int year,int month,int day) (*this).year=year; (*this).month=month; (*t

5、his).day=day; int year,month,day;yearmonthday; Date mydate(year,month,day);myyear=mydate.GetYear();int &mymonth=mydate.GetMonth();myday=mydate.GetDay();myyearendlmymonthmydaymyyear=8888;cout myyear=8888;输入1990 06 07得到分析:语句的意义是为了让本不可以调用的私有成员,可以利用公有成员函数在主函数中得到一个引用的变量,也就是可以用引用的变量来修改类中私有成员。但是这种做法并不可取,因为

6、类的封装性,这样就破坏的类的封装性,没有保护好私有成员。删掉即可。实验八 继承与派生类(1) 掌握单继承程序设计的基本方法。(2) 掌握多继承程序设计的基本方法。学习教材有关继承与派生类的内容,对单继承语义、继承控制和访问控制,多继承的多义性及其解决方法有充分的理解和把握。对实验基本要求应在上机实验前仔细阅读,程序应事先编制完成,上机时录入调试,同时还应设计相应的测试用例集,检查程序的正确性、可靠性、完备性和容错能力。(1) 下面程序定义一个vehicle类,并派生出car和truck两个派生类。#includeclass vehicleprotected: int wheels; doubl

7、e weight; void initialize(int whls, double wght); int get_wheels() return wheels; double get_weight() return weight; double wheel_loading() return weight/wheels;class car: public vehicle int passenger_load; void initialize(int whls, double wght, int people =4); int passengers() return passenger_load

8、;class truck: double payload; void init_truck(int number =2, double max_load =24000.0); double efficiency();void vehicle:initialize(int whls, double wght) wheels=whls; weight=wght;void car:initialize(int whls, double wght, int people) passenger_load=people;void truck:init_truck(int number, double ma

9、x_load) passenger_load=number; payload=max_load;double truck:efficiency() return payload/(payload+weight); vehicle bicycle; bicycle.initialize(2,25);the bicycle has bicycle.get_wheels() wheels.nthe bicycle weighs bicycle.get_weight() pounds.nthe bicycles wheel loading is bicycle.wheel_loading() poun

10、ds per tire.nn car audi; audi.initialize(4,3500.0,5);the audi has audi.get_wheels()the audi weighs audi.get_weight()the audiaudi.wheel_loading() truck jief; jief.initialize(18,12500.0); jief.init_truck(2,33675.0);the jief has jief.get_wheels()the jief weighs jief.get_weight()the jiefs efficiency is

11、100.0*jief.efficiency() percent.n 运行程序,观察运行结果是否正确且满足题意要求。 将class car: public vehicle和class truck: public vehicle分别改为: private vehicle和class truck: private vehicle程序运行结果有无变化,为什么? 定义并实现vehicle类、car类和truck类的构造函数,完成vehicle类、car类和truck类的数据成员初始化工作。 将vehicle中数据成员wheels和weight改为private性质,如何修改程序以达到相同的输出结果。答:

12、修改前和修改后的结果都是如果将两个继承都改成私有继承,不仅使wheel和weight成员变量没办法继承,而且公有成员函数像get_wheel()都不能被类外调用,解决的办法有可以设一个在派生类和基类公有成员函数调用本类私有成员,类外调用公有成员函数即可。思考题 vehicle(int whls, double wght) wheels=whls; int get_wheels() return wheels; car(int whls, double wght, int people =4):vehicle(whls, wght) int passengers() return passeng

13、er_load; truck(int whls, double wght,int number =2, double max_load =24000.0): passenger_load=number; double efficiency()return payload/(payload+weight); int passengers() return passenger_load; vehicle bicycle(2,25); car audi(4,3500.0,5); truck jief(18,12500.0,2,33675.0);2.基类保护成员改为似有成员: double weight; weight=wght;(2)下面程序对应图1所示的类层次继承结构:iost

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1