C期末考试试题.pdf

上传人:无*** 文档编号:90893694 上传时间:2023-05-18 格式:PDF 页数:13 大小:1,014.49KB
返回 下载 相关 举报
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,另一个将数据成员初始化为一个固定的值。另有一成员函数将时间以1 0:1 0:1 0的格式显示在屏幕上,编写成为个完整的程序。#i n cl u d e cl ass Ti m eIp r i vat e:i n t x,y,z;p u b l 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 n

2、 d l;);voi d m ai 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),姓名(Nam e),性 别(Se x),生 日(B i r t h d ay)和家庭住址(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 am e sp ace st d;e n u m Tse x m i d,m an,

3、w om an);cl ass Pe r son(ch ar Id Pe r son 1 9;身份证号,1 8位数字ch ar Nam e 2 0;姓名Tse x Se x;性别i n t B i r t h d ay;生日,格式 1 9 86 年 8 月 1 8 日写作 1 9 86 081 8ch ar Hom e A d d r e ss5 0;家庭地址p u b l i c:Pe r son(ch ar *,ch ar *,Tse x,i n t,ch ar *);Pe r son(Pe r son&);Pe r son ();Pe r son ();voi d Pr i n t Pe

4、 r son l n f o();voi d i n p u t Pe r son(););Pe r son:Pe r son(ch ar *i d,ch ar *n am e,Tse x se x,i n t b i r t h d ay,ch ar *h om e ad d)st r cp y(Id Pe r son,i d);st r cp y(Nam e,n am e);Se x=se x;B i r t h d ay二b i r t h d ay;st r cp y(Hom e A d d r e ss,h om e ad d);Pe r son:Pe r son()Id Pe r

5、son 0=,0 ;Nam e 0=,0J;Se x二m i d;B i r t h d ay=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(Nam e,Ps.Nam e);Se x=Ps.Se x;B i r t h d ay=Ps.B i r t h d ay;st r cp y(Hom e A d d r e ss,Ps.Hom e A d d r e ss);Pe r son:Pe r son()voi d Pe r son:

6、i n p u t Pe r son()ch ar 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(Nam e,2 0);cou t ch;i f(ch二 二 m)Se x=m an;e l se Se x=w om an;cou t 请输入生日,格 式1 9 86年8月1 8日写作1 9 86 081 8:e n d l;ci n B i r t h d ay;ci n.g e t ();吸收回车符,否则地址输不进去cou t

7、 ”请输入地址:e 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 姓名:Nam e n ”性别:;i f (Se x=m an)cou t 男 n;e l se i f (Se x=w om an)cou t ,C,n;e l se cou t n ;cou t 出生年月日:;i二B i r t h d ay;cou t i/1 0000 年;i=i%1 0000;cou t i/1 00

8、月”i%1 00 日 n 家庭住址:Hom e A d d r e ss n ;)i n t m ai n()Pe r son Psi (3 4 082 2 1 9 86 081 81 6 1 1 ,程利,m an,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 Pe r son l n f o();r e t u r n 0;)编程题3.建立一个基类CB u i

9、l d i n g,用来存储一座楼房的层数、房间数以及它的总平方英尺数。建立派生类Ch ou si n g,继承CB u i l d i n g,并存储下面的内容:卧室和浴室的数量。另外再建立派生类COf f i cB u i l d i n g,继承CB u i l d i n g,并存储灭火器和电话的数目。然后编写应用程序,建立住宅对象和办公楼对象,并输出它们的有关数据。编写成为一个完整的程序。#i n cl u d e#i n cl u d e u si n g n am e sp ace st d;cl ass cb u i l d i n g p r ot e ct e d:i n

10、t f l oor,r oom s,ar e a;p u b l i c:cb u 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;ar e a=a;cl ass ch ou si n g:p u b l i c cb u i l d i n g i n t b e d r oom s,b at h r oom s;p u b l i c:ch ou si n g(i n t f,i n t r,i n t a,i n t b,i n t b a):cb u i l d i n g(f,r,a)b e d r oom s=b;b

11、at h r oom s=b a;voi d d i sp l ay()cou t,zt h e n u m b e r of f l oor i s/z f l oor e n d l;cou t z/t h e n u m b e r of r oom s i s,r oom s e n d l;c o u t/zt h en u m b e r of ar e a i s z,ar e a e n d l;cou t ,t h e n u m b e r of b e d r oom s i s*b e d r oom s e n d l;cou t z,t h e n u m b e

12、r of b at h r oom s i s z/b at h r oom se n d l;);cl ass cof f i ce b u i l d i n g s:p u b l i c cb u i l d i n g i n t f i r e s,p h on e s;p u b l i c:cof f i ce b u 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 b a):cb u i l d i n g(f,r,a)f i r e s=b;p h on e s二b a;)voi d d i sp l ay()cou

13、t,zt h e n u m b e r of f l oor i s/z f l oor e n d l;cou t z/t h e n u m b e r of r oom s i s,r oom s e n d l;cou t ,t h e n u m b e r of ar e a i s z z ar e a e n d l;cou t ,t h e n u m b e r of f i r e s i s z f i r e se n d l;cou t /zt h e n u m b e r of t e l e p h on e s i s/zp h on e se n d l

14、;);voi d m ai n()Ich ou si n g h ou se (1,2,3,4,5);cof f i ce b u i l d i n g s of f i ce(6,7,8,9,1 0);h ou se,d i sp l ay ();of f i ce,d i sp l ay ();编程题4.某公司雇员(e m p l oy e e)包括技术人员(t e ch n i ci an)和销售员(sal e sm an)。以e m p l oy类为虚基类派生出t e ch n i ci an和sal e sm an类;e m p l oy e e类的属性包括姓名、职工号、工资级别,

15、月薪(实发基本工资加业绩工资)。操作包括月薪计算函数(pa y(),该函数要求输入请假天数,扣去应扣工资后,得出实发基本工资。technicia n类派生的属性有每小时附加酬金和当月工作时数,及研究完成进度系数。业绩工资为三者之积。也包括同名的pa y()函数,工资总额为基本工资加业绩工资。sa lesma n类派生的属性有当月销售额和酬金提取百分比,业绩工资为两者之积。也包括同名的pa y()函数,工资总额为基本工资加业绩工资。编写成为一个完整的程序。#include#include using na mespa ce std;sta tic int G ra des =5 0 0,6 0

16、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;工资级别double sa la ry;/)-double ba se_ sa la ry;基本月薪double ca reer_ sa la ry;业绩工资public:employee(string=,int=0,int=0);employee(employee&);拷贝构造函数virtua l void pa y();月薪计算函数void show();double

17、getsa la ry()return sa la ry;)double getba se_ sa la ry()return ba se_ sa la ry;double 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;月薪ba se_ sa la ry=0;基本月薪ca reer_ sa la ry=0;业绩工资)employee:employee(employee&emp)拷贝构造函

18、数na me=emp.na me;I D=emp.I D;gra de=emp.gra de;sa la ry=emp.sa la ry;月薪ba se_ sa la ry=emp.ba se_ sa la ry;基本月薪ca reer sa la ry=emp.ca reer sa la ry;业绩工资)void employee:show()cout na me,t*ID,t*sa la ry endl;void employee:pa y()int da ys;cout 请输入请假天数:n;cin da ys;ba se sa la ry=G ra des gra de*(2 3 -da

19、 ys)/2 3;ca reer_ sa la ry=ba se_ sa la ry/2;普通员工业绩工资为基本工资的一半sa la ry=ba se_ sa la ry+ca reer_ sa la ry;)cla ss ma na ger:virtua l public employee 虚基类protected:double priz e;固定奖金额double fa ctor;业绩系数public:ma na ger(string=,int=0,int=0,double=0);ma na ger(ma na ger&ma g);拷贝构造函数void pa y();ma na ger:m

20、a na ger(ma na ger&ma g):employee(ma g)priz e=ma g.priz e;fa ctor=ma g.fa ctor;ma na ger:ma na ger(string nn,int id,int gr,double pr):employee(nn,id,gr)priz e=pr;固定奖金额fa ctor=0;void ma na ger:pa y()int da ys;cout ”请输入请假天数:n”;cin da ys;cout 请输入业绩系数:n;cin fa ctor;ba se_ sa la ry=G ra des gra de*(2 3 -

21、da ys)/2 3;ca reer_ sa la ry=priz e*fa ctor*(2 3 -da ys)/2 3;sa la ry=ba sesa la ry+ca reer_ sa la ry;)cla ss technicia n:virtua l public employeeprotected:double hours;月工作时数doub 1 e perhour;/每小时附加酬金double shfa ctor;研究进度系数public:technicia n(string=,/,/,int=0,int=0,double=0);technicia n(technicia n&)

22、;拷贝构造函数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,double phr):employee(nn,id,gr)hours=0;perhour=phr;每小时附加酬金shfa ctor=0;void technicia n:pa

23、y()int da ys;coutG 请输入请假天数:n;cin da ys;cout 请输入研究进度系数:n;hours=8*(2 3 一 da ys);cin shfa ctor;ba 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=ba se_ sa la ry+ca reer_ sa la ry;cla ss sa lesma n:virtua l public employeeprotected:double

24、 a mount;销售额double slfa ctor;提成比例public:sa lesma n(string“,int=0,int=0,double=0);sa lesma n(sa lesma n&);拷贝构造函数void pa y(););sa lesma n:sa lesma n(string nn,int id,int gr,double slfa c):employee(nn,id,gr)a mount=0;slfa ctor=slfa c;sa lesma n:sa lesma n(sa lesma n&sa le):employee(sa le)a mount=sa le,

25、a mount;slfa ctor=sa le.slfa ctor;void sa lesma n:pa y()int da ys;cout 请输入请假天数:n;cin da ys;coutG 请输入销售额:n;cin a mount;ba 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=ba se_ sa la ry+ca reer_ sa la ry;cla ss developerma nciger:public mema ger,public techn

26、icia n(public:developerma na ger(string=,/,int id=0,int gr=0,double pr=0,double phr=0);developerma na ger(developerma na ger&);/拷贝构造函数void pa y();developerma na ger:developerma na ger(string nn,int id,int gr,double pr,double phr):ma na ger(nn,id,gr,pr),technicia n(nn,id,gr,phr),employee(nn,id,gr)dev

27、eloperma na ger:developerma na ger(developerma na ger&dema n):ma na ger(dema n),technicia n(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);ba se sa la ry=G ra des gra de *(2 3 -da ys)/2 3;基本工资ca reer_ sa la ry=perhour*hours*shfa ctor

28、*(2 3 -da ys)/2 3;技术人员奖金ca reer_ sa la ry+=priz e*fa ctor*(2 3 -da ys)/2 3;加经理业绩工资ca reer_ sa la ry/=2;sa la ry=ba sesa la ry+ca reer sa la ry;)cla ss sa lesma na ger:publie ma na ger,public sa lesma npublic:sa lesma na ger(string=,/,int=0,int=0,double pr=0,double slfa c=0);sa lesma na ger(sa lesma

29、na ger&);拷贝构造函数void pa y(););sa lesma na ger:sa lesma na ger(string nn,int id,int gr,double pr,double 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:sa 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)/拷

30、贝构造函数void sa lesma na ger:pa y()int da ys;cout*请输入请假天数:n;cin da ys;cout。请输入业绩系数:n;cin fa ctor;cout a mount;ba se_ sa la ry=G ra des gra de *(2 3 -da ys)/2 3;基本工资ca reer_ sa la ry=priz e*fa ctor*(2 3 -da ys)/2 3;经理业绩工资ca reer_ sa la ry/=2;ca reer_ sa la ry+=a mount*sl fa ctor;加销售业绩工资sa la ry=ba se_ s

31、a la ry+ca reer_ sa la ry;int ma inO employee end 1 (张伟,1 0 0 1 2,0),*emlp;ma na ger ma gi(姚婕,2 0 0 0 5,4,1 0 0 0);technicia n tecl(王 茜 ,3 0 0 4 7,5,1 0);sa lesma n sa il(朱明,4 0 0 3 8,2,0.0 5);developerma na ger deml(沈俊”,5 0 0 6 9,6,1 5 0 0,1 2);sa lesma na ger sa ml(况钟,6 0 0 0 7,3,1 0 0 0,0.0 5);em

32、ll.pa y();eml 1.show();ma g 1.pa y();ma gi,show();tecl.pa y();tecl.show();sa il,pa y();sa il.show();emlp=&deml;emlp-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