2011春C++期末试题_B卷答案.doc
上传人:yy****24 上传时间:2024-09-10 格式:DOC 页数:3 大小:51KB 金币:16 举报 版权申诉
预览加载中,请您耐心等待几秒...

2011春C++期末试题_B卷答案.doc

2011春C++期末试题_B卷答案.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

16 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

第页面向对象程序设计C++2010-2011学年春季学期末考试B试卷答案及评分标准单选题(45分,每题3分)题号12345答案ACBAC题号678910答案CBDCD题号1112131415答案DDABA二、读程序写结果(28分,每题4分)(1)10,515,5(2)调用普通构造函数:4,8调用复制构造函数:4,8调用析构函数.调用析构函数.(3)创建点(1,1)创建点(4,5)两点的距离是:5(4)a=3,b=13a=5,b=13(5)v1=(1,2)v2=(3,4)v3=v1+v2=(4,6)(6)调用基类Base的构造函数:1调用派生类Derived的构造函数:2(7)7,14,21三、编程题(27分)1、(14分)classComplex(2分){private:intreal,image;public:Complex(intx=0,inty=0);voidshow()const;Complexoperator+(constComplex&other);};Complex::Complex(intx,inty)(4分,其中默认参数1分){real=x;image=y;}voidComplex::show()const(4分){cout<<"输出复数:";if(real==0&&image==0)cout<<0;if(real!=0)cout<<real;if(image>0){if(image!=1)cout<<"+"<<image<<"i";elsecout<<"+i";}elseif(image<0){if(image!=-1)cout<<image<<"i";elsecout<<"-i";}cout<<endl;}ComplexComplex::operator+(constComplex&other)(4分){Complextemp;temp.real=real+other.real;temp.image=image+other.image;returntemp;}2、(13分)classDate(2分){private:intyear,month,day;public:Date(inty,intm,intd);voidshow()const;};Date::Date(inty,intm,intd)(4分){year=y;month=m;day=d;}Date::Date(constDate&other)(4分){year=other.year;month=other.month;day=other.day;}voidDate::show()const(3分){cout<<year<<"-"<<month<<"-"<<day<<""<<endl;}