C++期末考试试题.pdf

上传人:文*** 文档编号:88923556 上传时间:2023-05-04 格式:PDF 页数:13 大小:1,013.70KB
返回 下载 相关 举报
C++期末考试试题.pdf_第1页
第1页 / 共13页
C++期末考试试题.pdf_第2页
第2页 / 共13页
点击查看更多>>
资源描述

《C++期末考试试题.pdf》由会员分享,可在线阅读,更多相关《C++期末考试试题.pdf(13页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、编程题1.创建一个名为t i m e 的类,它包括分别表示小时、分钟和秒的i n t 类型的数据成员以及两个构造函数,一个构造函数将数据成员初始化为8,另一个将数据成员初始化为一个固定的值。另有一成员函数将时间以i o:i o:i o的格式显示在屏幕上,编写成为个完整的程序。#i n cl u d e cl a ss Ti m eIp r i va t e:i n t x,y,z;p u bl i c:Ti m e ()x=y=z=8;Ti m e(i n t a,i n t b,i n t c)x=a;y=b;z=c;voi d d i sp()(cou t x ,z:,/y ,/:,z e

2、 n d l;);voi d m a i n()ITi m e t l(1 0,1 0,1 0);t l.d i sp();)编程题2.设计一个学校在册人员类(Pe r son)。数据成员包括:身份证号(Id Pe r son),姓名(Na m e),性 别(Se x),生 日(Bi r t h d a y)和家庭住址(Hom e A d d r e ss)o成员函数包括人员信息的录入和显示。还包括构造函数与拷贝构造函数。编写成为 个完整的程序。#i n cl u d e#i n cl u d e u si n g n a m e sp a ce st d;e n u m Tse x m i

3、d,m a n,w om a n);cl a ss Pe r son(ch a r Id Pe r son 1 9;/身份证号,1 8 位数字ch a r Na m e 2 0;姓名Tse x Se x;性别i n t Bi r t h d a y;生日,格式 1 9 86 年 8 月 1 8 日写作 1 9 86 081 8ch a r Hom e A d d r e ss5 0;家庭地址p u bl i c:Pe r son(ch a r *,ch a r *,Tse x,i n t,ch a r *);Pe r son(Pe r son&);Pe r son ();Pe r son ()

4、;voi d Pr i n t Pe r son l n f o();voi d i n p u t Pe r son(););Pe r son:Pe r son(ch a r *i d,ch a r *n a m e,Tse x se x,i n t bi r t h d a y,ch a r *h om e a d d)st r cp y(Id Pe r son,i d);st r cp y(Na m e,n a m e);Se x=se x;Bi r t h d a y 二 bi r t h d a y;st r cp y(Hom e A d d r e ss,h om e a d d)

5、;Pe r son:Pe r son()Id Pe r son 0=,0 ;Na m e 0=,0f;Se x=m i d;Bi r t h d a y=0;Hom e A d d r e ss0=,0;)Pe r son:Pe r son(Pe r son&Ps)st r cp y(Id Pe r son,Ps.Id Pe r son);st r cp y(Na m e,Ps.Na m e);Se x=Ps.Se x;Bi r t h d a y 二 Ps.Bi r t h d a y;st r cp y (Hom e A d d r e ss,Ps.Hom e A d d r e ss);

6、Pe r son:Pe r son()voi d Pe r son:i n p u t Pe r son()ch a r ch;cou t 请输入身份证号,1 8位数字:Ge n d l;ci n.g e t l i n e(Id Pe r son,1 9);cou t 请输入姓名:e n d l;ci n.g e t l i n e(Na m e,2 0);cou t ch;i f (ch=二 m,)Se x二m a n;e l se Se x=w om a n;cou t 请输入生日,格 式1 9 86年8月1 8日写作1 9 86 081 8:e n d l;ci n Bi r t h

7、d a y;ci n.g e t ();吸收回车符,否则地址输不进去cou t 请输入地址:Ge n d l;ci n.g e t l i n e(Hom e A d d r e ss,5 0);)voi d Pe r son:Pr i n t Pe r son l n f o()i n t i;cou t ”身份证号:Id Pe r son n 姓名:Na m e n Y”性别:;i f (Se x=m a n)cou t 男 n;e l se i f (Se x二 二w om a n)cou t 女 n ;e l se cou t ,z ,n;cou t 出生年月日:;i二Bi r t h

8、 d a y;cou t i/1 0000 年 ;i=i%1 0000;cou t i/1 00 月”i%1 00 曰 n 家庭住址:Hoi n e A d d r e ss n ;i n t m a i n()Pe r son Psi (3 4 082 2 1 9 86 081 81 6 1 1 ,程利,m a n,1 9 86 081 8,安徽省安庆市怀宁县),Ps2(Psl),Ps3;Psi.Pr i n t Pe r son l n f o();Ps2.Pr i n t Pe r son l n f o();Ps3.i n p u t Pe r son ();Ps3.Pr i n t

9、Pe r son l n f o();r e t u r n 0;)编程题3.建立一个基类C Bu i l d i n g,用来存储一座楼房的层数、房间数以及它的总平方英尺数。建立派生类C h ou si n g,继承C Bu i l d i n g,并存储下面的内容:卧室和浴室的数量。另外再建立派生类C Of f i cBu i l d i n g,继承C Bu i l d i n g,并存储灭火器和电话的数目。然后编写应用程序,建立住宅对象和办公楼对象,并输出它们的有关数据。编写成为一个完整的程序。#i n cl u d e#i n cl u d e u si n g n a m e sp

10、 a ce st d;cl a ss cbu i l d i n g p r ot e ct e d:i n t f l oor,r oom s,a r e a;p u bl i c:cbu i l d i n g(i n t f,i n t r,i n t a)f l oor=f;r oom s=r;a r e a=a;);cl a ss ch ou si n g:p u bl i c cbu i l d i n g i n t be d r oom s,ba t h r oom s;p u bl i c:ch ou si n g(i n t f,i n t r,i n t a,i n t

11、b,i n t ba):cbu i l d i n g(f,r,a)be d r oom s=b;ba t h r oom s=ba;voi d d i sp l a y()cou t,zt h e n u m be r of f l oor i s/z f l oor e n d l;cou t ”t h e n u m be r of r oom s i s,r oom s e n d l;cou t /zt h en u m be r of a r e a i s z,a r e a e n d l;cou t t h e n u m be r of be d r oom s i s z

12、 be d r oom s e n d l;cou t z,t h e n u m be r of ba t h r oom s i s,/ba t h r oom s e n d l;);cl a ss cof f i ce bu i l d i n g s:p u bl i c cbu i l d i n g i n t f i r e s,p h on e s;p u bl i c:cof f i ce bu i l d i n g s(i n t f,i n t r,i n t a,i n t b,i n t ba):cbu i l d i n g(f,r,a)f i r e s=b;

13、p h on e s二ba;)voi d d i sp l a y()cou t,zt h e n u m be r of f l oor i s/z f l oor e n d l;cou t ”t h en u m be r of r oom s i s,r oom s e n d l;c o u t z,t h en u m be r of a r e a i s z z a r e a e n d l;cou t ,t h e n u m be r of f i r e s i s/f i r e s e n d l;cou t z,t h e n u m be r of t e l

14、e p h on e s i s/z p h on e s e n d l;);voi d m a i n()Ich ou si n g h ou se (1,2,3,4,5);cof f i ce bu i l d i n g s of f i ce(6,7,8,9,1 0);h ou se,d i sp l a y ();of f i ce,d i sp l a y ();编程题4.某公司雇员(e m p l oy e e)包括技术人员(t e ch n i ci a n)和销售员(sa l e sm a n)。以e m p l oy类为虚基类派牛.出t e ch n i ci a n和s

15、a l e sm a n类;e m p l oy e e类的属性包括姓名、职工号、工资级别,月薪(实发基本工资加业绩工资)。操作包括月薪计算函数(pa y(),该函数要求输入请假天数,扣去应扣工资后,得出实发基本工资。technicia n类派生的属性有每小时附加酬金和当月工作时数,及研究完成进度系数。业绩工资为三者之积。也包括同名的pa y()函数,工资总额为基本工资加业绩工资。sa lesma n类派生的属性有当月销售额和酬金提取百分比,业绩工资为两者之枳。也包括同名的pa y()函数,工资总额为基本工资加业绩工资。编写成为一个完整的程序。#include#include using na

16、 mespa ce std;sta tic int G ra des =5 0 0,6 0 0,7 5 0,1 0 0 0,1 4 0 0,2 0 0 0,2 8 0 0,4 0 0 0);cla ss employee(protected:string na me;姓名int I D;职工号int gra de;工资级别doub le sa la ry;/)-doub le b a se_ sa la ry;基本月薪doub le ca reer_ sa la ry;业绩工资pub lic:employee(string=z/z/,int=0,int=0);employee(employee

17、&);拷贝构造函数virtua l void pa y();月薪计算函数void show();doub le getsa la ry()return sa la ry;)doub le getb a se_ sa la ry()return b a se_ sa la ry;doub le getca reer_ sa la ry()return ca reer_ sa la ry;;employee:employee(string nn,int id,int gr)na me二nn;I D =id;gra de=gr;sa la ry=0;b a se_ sa la ry=0;ca ree

18、r_ sa la ry=0;月薪基本月薪业绩工资)employee:employee(employee&emp)拷贝构造函数na me=emp.na me;I D=emp.I D;gra de=emp.gra de;sa la ry=emp.sa la ry;月薪b a se_ sa la ry=emp.b a se_ sa la ry;基本月薪ca reer_ sa la ry=emp.ca reer sa la ry;业绩工资)void employee:show()cout na me,V I D ,t*sa la ry endl;void employee:pa y()int da y

19、s;cout 请输入请假天数:n;cin da ys;b a se sa la ry=G ra des gra de*(2 3 -da ys)/2 3;ca reer_ sa la ry=b a se_ sa la ry/2;普通员工业绩工资为基本工资的一半sa la ry=b a se_ sa la ry+ca reer_ sa la ry;)cla ss ma na ger:virtua l pub lic employee 虚基类protected:doub le prize;固定奖金额doub le fa ctor;业绩系数pub lic:ma na ger(string=,int=0

20、,int=0,doub le=0);ma na ger(ma na ger&ma g);拷贝构造函数void pa y();ma na ger:ma na ger(ma na ger&ma g):employee(ma g)prize=ma g.prize;fa ctor=ma g.fa ctor;ma na ger:ma na ger(string nn,int id,int gr,doub le pr):employee(nn,id,gr)prize=pr;固定奖金额fa ctor=0;void ma na ger:pa y()int da ys;cout ”请输入请假天数:n”;cin

21、da ys;cout 请输入业绩系数:n;cin fa ctor;b a se_ sa la ry=G ra des gra de*(2 3 -da ys)/2 3;ca reer_ sa la ry=prize*fa ctor*(2 3 -da ys)/2 3;sa la ry=b a se_ sa la ry+ca reer_ sa la ry;)cla ss technicia n:virtua l pub lic employeeprotected:doub le hours;月工作时数doub 1 e perhour;/每小时附加酬金doub le shfa ctor;研究进度系数p

22、ub lic:technicia n(string=,/,/,int=0,int=0,doub le=0);technicia n(technicia n&);拷贝构造函数void pa y();technicia n:technicia n(technicia n&tech):employee(tech)拷贝构造函数hours=tech.hours;月工作时数perhour=tech,perhour;每小时附加酬金shfa ctor=tech.shfa ctor;研究进度系数)technicia n:technicia n(string nn,int id,int gr,doub le ph

23、r):employee(nn,id,gr)hours=0;perhour=phr;每小时附加酬金shfa ctor=0;void technicia n:pa y()int da ys;coutG 请输入请假天数:n;cin da ys;cout 请输入研究进度系数:n;hours=8*(2 3 -da ys);cin shfa ctor;b a se sa la ry=G ra des gra de*(2 3 -da ys)/2 3;ca reer_ sa la ry=perhour*hours*shfa ctor*(2 3 -da ys)/2 3;sa la ry=b a se_ sa l

24、a ry+ca reer_ sa la ry;cla ss sa lesma n:virtua l pub lic employeeprotected:doub le a mount;销售额doub le slfa ctor;提成比例pub lic:sa lesma n(string=,int=0,int=0,doub le=0);sa lesma n(sa lesma n&);拷贝构造函数void pa y(););sa lesma n:sa lesma n(string nn,int id,int gr,doub le slfa c):employee(nn,id,gr)a mount=0

25、;slfa ctor=slfa c;sa lesma n:sa lesma n(sa lesma n&sa le):employee(sa le)a mount=sa le,a mount;slfa ctor=sa le.slfa ctor;void sa lesma n:pa y()int da ys;cout 请输入请假天数:n;cin da ys;cout 请输入销售额:n;cin a mount;b a se_ sa la ry=G ra des gra de*(2 3 -da ys)/2 3;ca reer_ sa la ry=a mount*slfa ctor;sa la ry=b

26、 a se_ sa la ry+ca reer_ sa la ry;cla ss developerma nciger:pub lic mema ger,pub lic technicia n(pub lic:developerma na ger(string=,/,int id=0,int gr=0,doub le pr=0,doub le phr=0);developerma na ger(developerma na ger&);/拷贝构造函数void pa y();developerma na ger:developerma na ger(string nn,int id,int gr

27、,doub le pr,doub le phr):ma na ger(nn,id,gr,pr),technicia n(nn,id,gr,phr),employee(nn,id,gr)developerma na ger:developerma na ger(developerma na ger&dema n):ma na ger(dema n),techniciem(dema n),employee(dema n)void developerma na ger:pa y()(int da ys;cout fa ctor;cout shfa ctor;hours=8*(2 3 -da ys);

28、b a se sa la ry=G ra des gra de *(2 3 -da ys)/2 3;基本工资ca reer_ sa la ry=perhour*hours*shfa ctor*(2 3 -da ys)/2 3;技术人员奖金ca reer_ sa la ry+=prize*fa ctor*(2 3 -da ys)/2 3;加经理业绩工资ca reer_ sa la ry/=2;sa la ry=b a se_ sa la ry+ca reer sa la ry;)cla ss sa lesma na ger:pub lie ma na ger,pub lic sa lesma n

29、pub lic:sa lesma na ger(string=,/,int=0,int=0,doub le pr=0,doub le slfa c=0);sa lesma na ger(sa lesma na ger&);拷贝构造函数void pa y(););sa lesma na ger:sa lesma na ger(string nn,int id,int gr,doub le pr,doub le slfa c):ma na ger(nn,id,gr,pr),sa lesma n(nn,id,gr,slfa c),employee(nn,id,gr)sa lesma na ger:s

30、a lesma na ger(sa lesma na gerfe sa lma n):ma na ger(sa lma n),sa lesma n(sa lma n),employee(sa lma n)/拷贝构造函数void sa lesma na ger:pa y()int da ys;cout da ys;cout。请输入业绩系数:n;cin fa ctor;cout pa y();emlp-show();emlp=&sa ml;emlp-pa y();emlp-show();cout endl;employee emlO(emll);ma na ger ma gO(ma gl);technicia n tecO(tecl);sa lesma n sa lO(sa ll);developerma na ger demO(deml);sa lesma na ger sa mO(sa ml);cout show();emlp=&sa mO;emlp-show();return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com