分数不会少,固然题目有点多,大家也帮忙一下。就当复习一下

分数不会少,虽然题目有点多,大家也帮忙一下。就当复习一下
一 选择题
1. 下列关于友元的描述中,错误的是
A.关键字friend 用于声明友元B.一个类的成员函数可以是另一个类的友元
C.友元函数访问对象的成员不受访问特性影响D.友元函数也是成员函数
2. 在C++中,要实现动态联编,调用虚函数时必须使用
A.派生类指针B.基类指针C.类D.对象
3. 在下列函数原型中,可以作为类A 构造函数的是)
A.void A(int); B.int A(); C.A(int) const; D.A(int);
4. 下列关于常类型的描述中,正确的是
A.可以通过成员函数修改常对象的状态B.通过常对象可以调用一般成员函数
C.必须使用成员初始化列表初始化常数据成员D.常对象中的成员函数都是常成员函数
5. 释放一个类的对象时,系统自动调用
A.构造函数B.析构函数C.成员函数D.友元函数
6. 当一个派生类继承自一个基类时,基类中的所有公有成员都成为派生类的
A.可访问成员B.公有成员C.私有成员D.保护成员
7. 下列描述中,作为重载函数调用时选择依据的是
A.参数名字B.函数体C.函数名字D.返回类型
二 填空题
1.类成员的访问权限分为____________、____________和____________三类。
2.下列语句序列执行后输出10,请将划线处的语句补充完整。
class MyClass {
public:
MyClass(int x):val(x) { }
void Print();
private :
int val ;
};
void  ______________Print() { cout<<val<<endl; }   //这里需要填写
int main() {
MyClass obj(10);
obj.Print();
return 0;
}

3. 有两个类M 和C,其中类C 定义如下:class C { public: M m;} ;。若建立类C 的对象object,则对象
m 和对象object 中后被初始化的是对象_________________

4. 下列语句序列执行后输出Hello,请将划线处的语句补充完整。(2 分)
class MyClass {
public:
void Print() const { cout<<"Hello"; }
};
int main() {
MyClass* p = new MyClass();
___________Print();     //这里需要填写
return 0;
}

5. 请在划线处填写正确内容,使类MyClass 的复制构造函数的声明完整。
class MyClass {
public:
MyClass(const __________________ obj);   //这里需要填写
};
6. 为了解决多继承产生的____________问题,在C++中引入了虚基类。
7. 派生新类的类称为_________________,而派生出的新类称_________________。
8. 运算符函数的函数名是由运算符前加关键字____________构成的。
9. 下列语句序列的输出结果是____________。
class MyClass {
public:
MyClass(int x) { cout<<x; }
~MyClass() { cout<<0; }
};
int main() {
MyClass obj1(1),obj2(obj1),&ptr=obj1;
return 0;
}
10. 所有在类内部定义的成员函数都是__________函数。//横线需要填写的
三、改错题
下列程序中有三个错误,请改正错误(注意不要修改主函数),使程序的输出结果为:
The point is (0,1)
The point is (3,5)
源文件清单如下:
Line1: #include <iostream.h>
Line2: class Point {
Line3: public:
Line4: Point(int xx=0, int yy) : x(xx), y(yy) { }
Line5: void Move(int xOff, int yOff) const {
Line6: x+=xOff; y+=yOff;
Line7: }
Line8: void Print() const
Line9: { cout<<"The point is ("<<x<<', '<<y<<')'<<endl; }
Line10: private:
Line11: int x,y=0;
Line12: };
Line13: int main() {
Line14: Point p1,p2(2,1);
Line15: p1.Print();
Line16: p2.Move(1,4);
Line17: p2.Print();
Line18: return 0;
Line19: }
四、阅读程序题
1. 请写出下列程序的输出结果。
#include <iostream.h>
class Test{
public:
Test(int x=0):val(x) { cout<<"Cons "<<val<<endl; }
Test(const Test &p) { val=p.val; cout<<"Copy "<<val<<endl; }
friend Test operator + (Test &t1,Test &t2);
private:
int val;
};
Test operator + (Test &t1,Test &t2) {
Test temp(t1.val+t2.val);
return temp;
}
int main() {
Test A(1),B(3);
Test C;
C=A+B;
return 0;
}
2. 请写出下列程序的输出结果。
#include <iostream.h>
class Base {
public:
void f() { cout<<"fB"<<endl; }
virtual void g() { cout<<"gB"<<endl; }
};
class Derived : public Base {
public:
void f() { cout<<"fD"<<endl; }
virtual void g() { cout<<"gD"<<endl; }
};
int main() {
Base *p=new Derived;
p->f();
p->g();
return 0;
}
3. 请写出下列程序的输出结果。
#include <iostream.h>
class Base{
public:
Base() { cout<<"Base"<<endl; }
10
~Base() { cout<<"~Base"<<endl; }
};
class Base1 : virtual public Base{
public:
Base1() { cout<<"Base1"<<endl; }
~Base1() { cout<<"~Base1"<<endl; }
};
class Base2 : virtual public Base{
public:
Base2() { cout<<"Base2"<<endl; }
~Base2() { cout<<"~Base2"<<endl; }
};
class Derived : public Base1, public Base2 {
public:
Derived() { cout<<"Derived "<<endl; }
~Derived() { cout<<"~Derived"<<endl; }
private:
Base b;
};
int main() {
Derived d;
return 0;
}
4. 请写出下列程序的输出结果。
#include <iostream.h>
class A {
public:
A(int i):r1(i) { cout<<r1<<endl; }
~A() { cout<<'~'<<r1<<endl; }
void print() {cout<<"Empty:"<<r1<<endl;}
void print() const {cout<<"Const:"<<r1<<endl;}
void print(int x) {cout<<"Param:"<<x*x<<endl;}
private:
int r1;
};
int main() {
A a1(1),a2(2);
a1.print();
a2.print(3);
return 0;

------解决思路----------------------

1.D
2.B
3.D
4.C
5.B
6.是什么方式继承的?public/private/protected?
7.B

1.public/private/protected
2.MyClass::
3.object 
4.p->
5.MyClass&
6.二义性
7.父类(或基类)  (子类)派生类
8.operator
9.100
10.inline??
------解决思路----------------------

Line1: #include <iostream.h>改成#include <iostream>
Line5: void Move(int xOff, int yOff) const {去掉const
Line11: int x,y=0;改成int x,y;


1.Cons 1
  Cons 2
  Cons 0
  Cons 4;
  Copy 4
2. fB
   gD
3.Base
  Base1
  Base2
  Base
  Dervived
4.1
  2
  Empty:1
  Param:9