资源描述
面向对象程序设计复习资料
一、选择题(每题2分,共20分)
1、有关类的说法不正确的是______
A、类是一种用户自定义的数据类型
B、只有类中的成员函数才能存取类中的私有数据
C、在类中,如果不作特别说明,所有的数据均为私有类型
D、在类中,如果不作特别说明,所有的成员函数均为公有类型
2、有关类和对象的说法下列不正确的有______
A、对象是类的一个实例 B、任何一个对象只能属于一个具体的类
C、一个类只能有一个对象 D、类与对象的关系和数据类型和变量的关系相似
3、有关构造函数的说法不正确的是______
A、构造函数的名字和类的名字一样 B、构造函数在说明类变量是自动执行
C、构造函数无任何函数类型 D、构造函数有且只有一个
4、有关析构函数的说法不正确的是______
A、析构函数有且只有一个 B、析构函数无任何函数类型
C、析构函数和构造函数一样可以有参数
D、析构函数的作用是在对象被撤消是收回先前分配的内存空间
5、______的功能是对对象进行初始化
A、析构函数 B、数据成员 C、构造函数 D、静态成员函数
6、只能访问静态成员变量,静态成员函数和类以外的函数和数据不能访问类中的非静态成员变量______
A、静态函数 B、虚函数 C、构造函数 D、析构函数
7、局部变量可以隐藏全局变量,那么在有同名全局变量和局部变量的情形时,可以用 ______ 提供对全局变量的访问
A、域运算符 B、类运算符 C、重载 D、引用
8、在下列关键字中,用以说明类中公有成员的是______
A、public B、private C、protected D、friend
9、下列的各类函数中,______不是类的成员函数
A、构造函数 B、析构函数 C、友元函数 D、拷贝初始化构造函数
10、 ______是析构函数的特征
A、一个类中只能定义一个析构函数 B、析构函数名与类名不同
C、析构函数的定义只能在类体内 D、析构函数可以有一个或多个参数
二、判断题(每题1分,共10分;对的为T,错的为F)
1、通常拷贝初始化构造函数的参数是某个对象的引用名。 ( )
2、成员函数一定是内联函数。 ( )
3、引用静态数据成员时,要在静态数据成员名前加类名和作用域运算符。 ( )
4、在 C++ 程序设计中,建立继承关系倒挂的树应使用单一继承。 ( )
5、基类的公有成员在派生类中的访问权限由访问控制决定。 ( )
6、在 C++ 中,访问一个对象的成员所用的运算符是成员访问运算符,访问一个指针所指向的对象的成员所用的运算符是成员选择运算符。 ( )
7、在 C++ 中,函数原型不能标识函数的功能。 ( )
8、类的指针成员的初始化是通过函数完成的,这个函数通常是析构函数。 ( )
9、通常情况下,函数模板中的类型参数个数不能是0。 ( )
10、基类的公有成员在派生类中仍然是公有的。 ( )
三、简答题(每题4分,共20分)
1、以下程序的输出结果是_________
#include<iostream.h>
main()
{
int a=10;
int &b=a;
a=a*a;
cout<<a<<" "<<b<<endl;
b=b/5;
cout<<b<<" "<<a<<endl;
}
2、以下程序的输出结果是_________
#include<iostream.h>
class point
{
public:
int x,y;
//int y;
point()
{x=0;y=0;}
void output()
{ cout<<x<<endl<<y<<endl;}
};
main()
{
point pt;
pt.output();
}
3、以下程序的输出结果是_________
#include<iostream.h>
class A
{
int x,y;
public:
A(int m=0,int n=0)
{
x=m;
y=n;
}
void disp()
{cout<<"x="<<x<<","<<"y="<<y<<endl;}
};
void main()
{
A a1;
A a2(10);
A a3(10,10);
a1.disp();
a2.disp();
a3.disp();
}
4、以下程序的输出结果是_________
#include<iostream.h>
class Tc
{
private:
int i;
static int k;
public:
Tc() {i=0;i++;k++;};
void display()
{
cout<<"i="<<i<<","<<"k="<<k<<endl;
}
};
int Tc::k=0;
void main()
{
Tc A,B;
A.display();
B.display();
}
5、以下程序的输出结果是_________
#include<iostream.h>
class A
{
public:
void disp()
{
cout<<"m="<<m<<endl;
cout<<"n="<<n<<endl;
}
int m,n;
};
void main()
{
int A::*p=&A::m;
A a;
a.*p=10;
p=&A::n;
a.*p=20;
a.disp();
}
四、分析题(每题10分,共50分)
1、以下程序的输出结果是_________
#include<iostream.h>
class A
{
int n;
public:
A() {}
A(int m)
{ n=m;}
void xxx(int m)
{
A s;
s.n=n+m;
*this=s;
}
void disp()
{
cout<<"n="<<n<<endl;
}
};
void main()
{
A s(45);
s.disp();
s.xxx(9);
s.disp();
}
2、以下程序的输出结果是_________
#include<iostream.h>
template<class T>
class TAdd
{
private:
T x,y;
public:
TAdd(T a,T b){x=a,y=b;}
T add(){return x+y;}
};
void main()
{
TAdd<int> A(5,6);
TAdd<double> B(2.4,5.8);
cout<<"s1="<<A.add()<<endl;
cout<<"s2="<<B.add()<<endl;
}
3、以下程序的输出结果是_________
#include<iostream.h>
class A
{
public:
A(){cout<<"武汉"<<endl;}
~A(){cout<<"荆门"<<endl;}
};
class B
{
public:
B(){cout<<"襄樊"<<endl;}
~B(){cout<<"黄冈"<<endl;}
};
class C:public A,public B
{
public:
C(){cout<<"孝感"<<endl;}
~C(){cout<<"潜江"<<endl;}
};
void main()
{
C c;
}
4、以下程序输出的是_________
#include<iostream.h>
class A
{
public:
A(){cout<<"北京"<<endl;}
};
class B
{
public:
B(){cout<<"湖北"<<endl;}
};
class C:public B,virtual public A
{
public:
C(){cout<<"上海"<<endl;}
};
class D:public B,virtual public A
{
public:
D(){cout<<"浙江"<<endl;}
};
class E:public C,virtual public D
{
public:
E(){cout<<"深圳"<<endl;}
};
void main()
{
E e;
}
5、以下程序的输出结果是_________
#include<iostream.h>
class A
{
int n;
public:
A(int i){n=i;}
void operator++(){n++;}
void operator++(int) {n+=2;}
void disp()
{
cout<<"n="<<n<<endl;
}
};
void main()
{
A a(9),b(9);
a++;
++b;
a.disp();
b.disp();
}
参考答案
一、选择题
1——5 DCDCC 6——10 AAACA
二、判断题
1——5 TFTTT 6——10 FTFTF
三、简答题
1、
2、 0
0
3、 x=0,y=0
x=10,y=10
x=10,y=10
4、 i=1,k=2
i=1,k=2
5、
四、分析题
1、 n=45
n=54
2、s1=11
s2=8.2
3、武汉
襄樊
孝感
潜江
黄冈
荆门
4、北京
湖北
浙江
湖北
上海
深圳
5、n=11
n=10
展开阅读全文