《面向对象程序设计 C++》期末考试试卷(A)标准答案
班级:
姓名:
学号:
分数:
一
二
三
四
总分
题号
得分
一、单项选择题(每小题 2 分,共 40 分)
1-5.C D B C C
6-10.A A D D B
11-15.A B B B C
16-20.D C B C C
二、填空题(前 14 个空,每空 1 分,后 3 个空,每空 2 分,共 20 分)
1.
3.
4.
6.
8.
抽象
E
virtual
抽象类
实例
2.
this 指针
D、F
A、B、C、D、E
D、F
5. 静态多态性
动态多态性
7.
friend void fun(A &a)
继承
组合或模板
9. 在对象被系统释放之前做一些内存清理工作
10.
A(const A&)
11.
A operator++(int)
三、阅读程序(13 分)
1、a=89,b=56,c=12
2、ABC
3、A::A() called.
B::B() called.
第 1 页
B::~B() called.
A::~A() called.
4、Call B's function f()
Call B's function g()
Call C's function g()
四、编程题(共27分)
1、(10分)
Complex::Complex(){real=0;imag=0;}
Complex::Complex(double r){real=r;}
Complex::Complex(double r,double i){real=r;imag=i;}
Complex operator+(Complex &c1,Complex &c2)
{
Complex c;
c.real=c1.real+c2.real; c.imag=c1.imag+c2.imag;
return c;
}
ostream& operator << (ostream& output,Complex& c)
{ output<<"("<> (istream& input,Complex& c)
{
cout<<"input real and imaginary part of complex number:";
input>>c.real>>c.imag;
return input;
}
2、(17分)
class Circle:public Shape
第 2 页
{public:
Circle(double r){radius=r;}
void set()
{
cout<<"Please input the value of the circle:"<
>radius;
}
void show()
{
double area() {return 3.14159*radius*radius;}
cout<<"the radius of the circle="<a=a;}
void set()
{
cout<<"Please input the value of a:"<>a;
}
void show()
{
cout<<"a="<Circle C(5.5);
C.show();
Square S(9.9);
S.show();
Shape *s[]={&C,&S};
cout<<"total="<