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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

大学C++面向对象试题及参考答案文档格式.docx

1、私有成员保护成员3.在C+中,关于类的析构函数,正确的说法是( A.能带形式参数 BC.可以被重载 D4.一个类拥有多个构造函数,A.重复关系.函数体中必须有 delete.无形参,也不可重载则这些构造函数之间为(.拷贝关系 语句5.C.重载关系C+冲声明常量的关键字是A. extern B . const试卷装订线6.C . public D一个函数功能不太复杂,但要求被频繁调用,该函数应该设计成A.内联函数 B. 重载函数C.递归函数嵌套函数.volatile7.以下基类中的成员函数表示纯虚函数的是(A. virtual void tt()=O; B. void tt(i nt)=0C.

2、virtual void tt(i nt)D. virtual void tt(i nt)8.p的基类成员a,其中a是( )。公有继承的私有成员;私有继承的公有成员。)F面正确的说法是( )可以在类外用p.a的形式访问派生类对象A.公有继承的公有成员; BC.公有继承的保护成员; D9.对于任意一个类,析构函数的个数最多为(A.0 B.1 C.2 D.310.对于在类中定义的静态数据成员 count :A. count在类外进行初始化B. 该类的每个对象中都有一个独立的静态数据成员 countC.对象创建时产生 countB)10、改错题(共3小题,每小题count既可以在类外初始化,也可以在

3、类内初始化6分,共18分)1.下面的程序在 VC6.0 上编译提示 error C2440: type cast : cannot convert from class Complex to float,No user-defi ned-con version operator available that can perform this conversion ,请指出错误原因并改正。#in clude using n amespace std;class Complexpublic:Complex(float r=0,float i=0)real=r; imag=i; void prin

4、t()cout(real,imag)e ndl; private:float real,imag;int mai n() Complex a(2.2f, 4.4f);a.pri nt();coutfloat (a) *0.5return 0;2.下面的程序在 VC6.0 上编译提示 error C2662:getX cannot convert this pointer from const class CTestclass CTest &,请指出错误原因并改正。#in cludex = x;in t getX() return x; const CTest obj(5);obj.getX()

5、class STRING STRING(char *s)ptr= new charstrle n( s)+1;strcpy(ptr,s);STRING() delete ptr; coutptrprivate:char *ptr; STRING p1(book); STRING p2(pe np仁 p2;p1:pl.pri nt();读程序,给出程序的输出结果(每小题6分,共24分)【1】#include class Pers on public:Pers on() coutC on structor of Pers onen dl; Pers on() coutDestructor of P

6、ers on ;class Stude nt: public PersonStudent() coutConstructor of Studentendl; Student() coutDestructor of Studentclass Teacher:Teacher() coutC on structor of Teacher Teacher() coutDestructor of Teacherint mai n()Stude nt s;Teacher t;【2】 #i nclude class A public:A (int i) x = i;void dispa () cout x

7、,private :int x ;class B : public AB(i nt i) : A(i+10) x = i;void dispb() dispa(); cout en dl; private :B b(2);b.dispb();【3】 #in cludeclass Count static int count ;Count( ) coutco un t+ ;static int Getc( ) retur n count ; Count( ) count- ;int Coun t:co unt = 5;int mai n() Cou nt c1,c2,c3,c4 ;Co un t

8、:Getc( ) return 0;【4】#includeclass MyClassMyClass(int i=0)cout1;MyClass(co nst MyClass &x)cout2;MyClass & operator=(co nst MyClass &3; return *this; MyClass()cout4;MyClass obj1(1),obj2(2),obj3(obj1);obj1=obj2;四、编程题(共38分)1 下面是一个类的测试程序,请设计出能使用如下测试程序的类。 (12分) Test a;a.i ni t(68,55);其执行结果为:测试结果:68-55=13

9、(12 分)2 请为fraction 类(分数类)定义下列重载运算符函数(注意函数原型) 加法运算+。赋值运算=提取运算。class fraction private:试 卷 装 订 线int fz; / 分子int fm; / 分母3创建一个表示雇员信息的 employee类,其中包含数据成员 name empNo和salary ,分别表示雇员的姓名、编号和月薪。再从 employee类派生出3个类worker、technician和salesman,分别代表普通工人、科研人员、销售人员。三个类中分别包含数据成员 productNum、workHours和monthlysales ,分别代表

10、工人每月生产产品的数量、科研人 员每月工作的时数和销售人员每月的销售额。要求各类中都包含成员函数 pay,用来计算雇员的月薪,并假定:普通工人的月薪=每月生产的产品数x每件产品的赢利x 20%科研人员的月薪=每月的工作时数x每小时工作的酬金销售人员的月薪=月销售额X销售额提成。 (14 分)重点大学考试试题答案(A卷)2014 2015学年2学期面向对象程序设计课程一、 单选题(每小题 2分,共20分)CCDCB AAABA二、 改错题 洪3小题,每小题6分,共18分)1.main()函数第3句出错,因为类 Complex无类类型转换函数,将 Complex对象转换成float。改正:在Com

11、plex中类增加:operator float() retur n real;2.main()函数第2句出错,因为常对象 obj不能调用非常成员函数,在 CTest 类中:将 CTest(i nt x)换成 fCTest(i nt x) con st。或者将 mai n()中 con st CTest obj(5);换成 CTest obj(5);3.当程序执行对象p2的析构函数时,对象 p1的数据成员ptr出现了所谓的“指针悬挂问题” ,这说明C+中提供给对象的默认的赋值运算符并不是万能的,解决的办法就是重载赋值运算符“ =”,使对象不但能浅拷贝,还能实现深层拷贝。STRING & STRI

12、NG:operator=(co nst STRING &s)if(this=&;s)return *this;delete ptr;ptr=new charstrle n( s.ptr)+1;strcpy(ptr,s.ptr);return *this;三、 读程序,给出程序的输出结果。 (每小题6分,共24分)【1 】 Co nstructor of PersonCon structor of Stude ntCon structor of Pers onCon structor of TeacherDestructor of TeacherDestructor of Pers onDest

13、ructor of Stude nt【2】12,2【3】56789【4】1123444四、编程题(共 38分=12分+ 12分+14分)1.解答:#includeclass Test 4 分 int x,y;void in it(i nt,i nt);void prin t();void Test:init(int i,int j) 4 分 x=i;y=j;print() 4 分x-y=x-y(istream & is,fracti on &isf.fzf.fm;return is;3.解答:class employeeprotected:char n ame20;int empNo;floa

14、t salary;employee(char *cp=李强,int no=1001); employee(employee&void set name(char *cp);void setempNo(i nt no);void setsalary(float sa);char*get name();int getempNo();float getsalary();void display();employee compsalary(employee *emp);employee:employee(char *cp,i nt no) int i=0;while(*cp) n amei=*cp;i

15、+;cp+;namei=0empN o=no;employee(employee & em)while(em. namei) n amei=em .n amei;O:empNo=em.empNo;salary=em.salary;void employee:set name(char *cp)setempNo(i nt no) empN o=no;setsalary(float sa) salary=sa;char*employee:get name() return n ame;int employee:getempNo() return empNo;float employee:getsa

16、lary() retur n salary;display()工号为empNo的雇员name的月薪为salarysalary=emp-salary)elsereturn *emp;class worker : public employee worker(char*,i nt,i nt);void setproductNum(i nt n) productN um=n;int getproductNum() retur n productNum;void pay();int productNum;static float proper; 每件产品的利润float worker:proper=2

17、0; /假设每件产品的利润为 20元worker:worker(char *n ame,i nt n o,i nt pronum)employee( name ,no)productNum=pr onum;void worker:pay()salary=productNum*proper*0.2;class tech nicia n :tech nician( char*,i nt,float);void sethours(float h) workHours=h;float gethours() return workHours;float workHours;static float pa

18、yperhour; 科研人员每小时工作的酬金40元float tech ni cia n:payperhour=40; /假设科研人员每小时工作的酬金为tech ni cia n:tech nician( char *n ame,i nt no float hours) workHours=hours;void tech ni cia n: salary=workHours*payperhour;class salesma n : public employeesalesma n( char*,i nt,float);void setm on thlysales(i nt num) mon t

19、hlysales=nu m;int getm on thlysales() retur n mon thlysales;float mon thlysales;static float perce nt; /销售人员的销售提成float salesma n:perce nt=0.5; II假设销售人员的销售提成为 50%salesma n:salesma n( char *n ame,i nt n, float sn)employee( name ,n)mon thlysales=s n;void salesma n:salary=mon thlysales*perce nt;void main()worker w1(张三,1001,1000);technician t1(李四,1002,200);salesman s1(王五,1003,10000);w1.pay();t1.pay();s1.pay();工人w1.getname()w1.getsalary()元n科研人员t1.getiname()t1.getsalary()销售人员s1.getname()s1.getsalary()元 n

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

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