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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

本文(面向对象程序设计 C++山师 第七章习题答案.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

面向对象程序设计 C++山师 第七章习题答案.docx

1、面向对象程序设计 C+ 山师 第七章习题答案第七章习题答案一、选择填空 1、D 2、A 3、B 4、C 5、A 6、C 7、B 8、D 9、二、判断下列描述的正确性,对者划,错者划。 1、 2、 3、 4、 5、 6、 7、 8、 9、 10、 11、 12、 13、 14、 15、 16、 17、 18、 三、分析下列程序的输出结果。 1、(1)上述结构的DAG图如下所示。(2)无二义性(3)无二义性2、(1)无 (2无 (3)有 (4)无 (5)有四、分析下列程序的输出结果1、运行该程序输出如下结果。(1,2)5,6(6,9)2、该程序的输出结果如下所示(1,2)(6,9)5,6(6,9)

2、3、该程序的输出结果如下:(13,22,30,40)4、运行该程序输出结果如下所示。 D2:display()pri1=4,pri2=5pri4=6pri12=7D2:display()pri1=12 ,pri2=9pri4=7pri12=85、该程序输出结果如下所示:D2:display()pri1=1,pri2=4pri4=6pri12=7D2:display()pri1=9,pri2=8pri4=7pri12=86、该程序输出结果如下所示:base classbase classbase classderive1 classderive2 class五、按下列要求编写程序。1、程序内容如

3、下所示。#include #include class person int no; char name10; public: void input() coutno; coutname; void disp() cout 编号:noendl; cout 姓名:nameendl; ;class student:public person private:char depart6;int degree; public:void input() person:input(); coutdepart; coutdegree;void disp() person:disp(); cout 班号:dep

4、artendl; cout 成绩:degreeendl;class teacher:public person private:char prof10;char depart10; public:void input() person:input(); coutprof; cout depart ;void disp() person:disp(); cout 职称: profendl; cout 部门: depart endl;void main() student s1; teacher t1; cout输入一个学生数据:n; s1.input(); cout输入一个教师数据:n; t1.

5、input(); cout显示一个学生数据:n; s1.disp(); cout显示一个教师数据:n; t1.disp();2、程序内容如下所示。#include #include class stringint length;char *contents; public:int get_length()return length;char *get_contents()return contents;string()delete contents;int set_contents(int in_length,char *in_contents);int set_contents(char *

6、in_contents);void print()coutcontentsget_length(); pt=new_text-get_contents(); cp=this-get_contents(); m=this-get_length(); char *news=new charm+n+1; for (int i=0;icursor;i+) newsi=cpi; k=i; for (int j=0;jn;i+,j+)newsi=ptj; cursor=i; for(j=k;jget_length(); pt=new_text-get_contents(); m=this-get_leng

7、th(); news=new charmn+cursor ? m+1 : n+cursor+1; news=this-get_contents(); for(int i=cursor,j=0;in+cursor;j+,i+)newsi=ptj; if (mget_contents(); m=this-get_length(); for(int i=cursor;im;i+)cpi=cpi+how_much; cpi=0;void main() string s1; edit_string s2; char *cp; s1.set_contents(Object_Oriented Program

8、ming); cp=s1.get_contents(); s2.set_contents(cp); s2.print(); s2.move_cursor(15); s1.set_contents(Windwos); s2.add_at_cursor(&s1); s2.print(); s2.move_cursor(6); s2.dele_at_cursor(9); s2.print(); s1.set_contents( TTT); s2.repl_at_cursor(&s1); s2.print();3、程序内容如下所示。#include class vehicle protected:in

9、t wheels;float weight; public:vehicle(int wheels,float weight);int get_wheels();float get_weight();float wheel_load();void print();class car:vehicleint passenger_load; public:car(int wheels,float weight,int passengers=4);int get_passengers();void print();class truck:vehicleint passenger_load;float p

10、ayload; public:truck(int wheels,float weight,int passengers=2,float max_load=240000.00);int get_passengers();float efficiency();void print();vehicle:vehicle(int wheels,float weight) vehicle:wheels=wheels; vehicle:weight=weight;int vehicle:get_wheels() return wheels;float vehicle:get_weight() return

11、weight/wheels;void vehicle:print() cout 车轮:wheels个。endl; cout 重量:wheels公斤。endl;car:car(int wheels,float weight,int passengers):vehicle(wheels,weight) passenger_load=passengers;int car:get_passengers() return passenger_load;void car:print() cout 小车:endl; vehicle:print(); cout 载人:passenger_load人。endl;

12、 coutendl;truck:truck(int wheels,float weight,int passengers,float max_load):vehicle(wheels,weight) passenger_load=passengers; payload=max_load;int truck:get_passengers() return passenger_load;float truck:efficiency() return payload/(payload+weight);void truck:print() cout卡车endl; vehicle:print(); co

13、ut 载人:passenger_load人。endl; cout 效率:efficiency()endl; coutendl;void main() car car1(4,1000,5); truck tru1(10,5000,3,340000); car1.print(); tru1.print();4、程序内容如下所示。#include #include class employee protected:int no;char name10;float salary; public:employee() coutno; coutname; salary=0;void pay()void d

14、isplay();class technician:public employee private:float hourlyrate;int workhours; public:technician()hourlyrate=100;void pay() coutnameworkhours; salary=hourlyrate*workhours;void display() cout兼职技术人员:name(编号为:no)本月工资:salaryendl;class salesman:virtual public employee protected:float commrate;float sa

15、les; public:salesman()commrate=0.04;void pay() coutnamesales; salary=sales*commrate;void display() cout销售员:name(编号为:no)本月工资:salaryendl;class manager:virtual public employee protected:float monthlypay; public:manager()monthlypay=8000;void pay()salary=monthlypay;void display() cout经理:name(编号为:no)本月工资:

16、salaryendl;class salesmanager:public manager,public salesman public:salesmanager() monthlypay=5000; commrate=0.005;void pay() coutnamesales; salary=monthlypay+commrate*sales;void display() cout销售经理:name(编号为:no)本月工资:salaryendl;void main() manager m1; technician t1; salesman s1; salesmanager sm1; m1.pay(); m1.display(); t1.pay(); t1.display(); s1.pay(); s1.display(); sm1.pay(); sm1.display();

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

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