2011春C++期末试题 - B卷答案

2019-01-18 19:09

面向对象程序设计C++

2010-2011学年 春 季学期 末 考试B试卷答案及评分标准

一、单选题(45分,每题3分)

题号 答案 题号 答案 题号 答案 1 A 6 C 11 D 2 C 7 B 12 D 3 B 8 D 13 A 4 A 9 C 14 B 5 C 10 D 15 A 二、读程序写结果(28分,每题4分)

(1) 10,5 15,5 (2)

调用普通构造函数:4,8 调用复制构造函数:4,8 调用析构函数. 调用析构函数. (3)

创建点(1,1) 创建点(4,5) 两点的距离是:5 (4)

a=3,b=13 a=5,b=13 (5)

v1=(1,2) v2=(3,4)

v3=v1+v2=(4,6) (6)

调用基类Base的构造函数:1

调用派生类Derived的构造函数:2 (7)

7,14,21

第1页

三、编程题(27分)

1、 (14分)

class Complex (2分) {

private:

int real,image; public:

Complex(int x=0,int y=0); void show() const;

Complex operator+(const Complex& other); };

Complex::Complex(int x,int y) (4分,其中默认参数1分) {

real=x; image=y; }

void Complex::show() const (4分) { }

cout<<\输出复数:\

if(real==0&&image==0) cout<<0; if(real!=0) cout<0) {

if(image!=1)

cout<<\ else

cout<<\}

else if(image<0) {

if(image!=-1)

cout<

cout<<\}

cout<

Complex Complex::operator+(const Complex& other) (4分) {

Complex temp;

temp.real=real+other.real;

第2页

temp.image=image+other.image; return temp; }

2、(13分)

class Date (2分) {

private:

int year,month,day; public:

Date(int y,int m,int d); void show() const; };

Date::Date(int y,int m,int d) (4分) {

year=y; month=m; day=d;

Date::Date(const Date& other) (4分) {

year=other.year; month=other.month; day=other.day; }

void Date::show() const (3分) {

cout<

第3页


2011春C++期末试题 - B卷答案.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:电力市场营销部经理述职述廉报告

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: