C.保证基类保护成员在子类中可以被访问 D.保证基类私有成员在子类中可以被访问 15.下列关于类的权限的描述错误的是( A )
A.类本身的成员函数只能访问自身的私有成员 B.类的对象只能访问该类的公有成员
C.普通函数不能直接访问类的公有成员,必须通过对象访问 D.一个类可以将另一个类的对象作为成员 16.关于虚函数,下列说法正确的是( B )
A. 虚函数在基类中说明后,不用再在派生类中重新说明 B. 包含有虚函数的基类称为抽象基类
C. 每个派生类必须对从基类继承的虚函数进行重新重定义 D. 包含虚函数的类不能够生成实例对象
17.设类A将其它类对象作为成员,则建立A类对象时,下列描述正确的是( B )
A.A类构造函数先执行 B.成员构造函数先执行 C.两者并行执行
D.不能确定
18.下列描述错误的是( A )
A.在创建对象前,静态成员不存在 C.静态成员不能是虚函数
B.静态成员是类的成员
D.静态成员函数不能直接访问非静态成员
19.对于友元描述正确的是( B )
A.友元是本类的成员函数 C.友元不是函数
B.友元不是本类的成员函数
D.友元不能访问本类私有成员
20.可以在派生类的成员函数中访问基类的非私有成员,并能通过派生类的对象直接访
问基类公有成员的派生方式是( A ) A.public
B.protected C.private D.friend
三、程序分析题 (本题共4小题,每小题5分,共20分)
1. 下列程序运行后,当用户输入1 2 3 4 5 6 7 8 9 0 回车后(各数字间有空格),程序的
输出结果为: 0, 9, 8, 7, 6, 5, 4, 3, 2, 1 。 #include
第 31 页 共6页
void main() { int i; float score[10]; cout<<\ for(i=0; i<10; i++) cin>>score[i]; for(i=0; i<10; i++) cout< 2.下列该程序的运行结果是 A::Show B::Show B::Show #include public: void Show() { cout<<\}; class B : public A { public: void Show() { cout<<\ void Display() { Show(); }; }; void main() { A a; B b; a.Show(); b.Show(); b.Display(); } 3.下列程序的输出结果是 a=40, b=20 #include 第 32 页 共6页 swap(&a, &b); cout<<\} void swap(int* px, int* py) { int temp=*px; *px=*py; *py=temp; } 4. 给出下列程序的输出结果: Calling show(a). A.i=10 Calling show(b). B.j=10 #include public: virtual void fun(int i) {cout<<\}; class B : public A { public: void fun(int j) {cout<<\}; void show(A &a) { int k=10; a.fun(k); } int main() { A a; B b; cout<<\ show(a); cout<<\ show(b); return 1; } 第 33 页 共6页 四、完成程序题 (本题共5小题,每小题6分,共30分) 1.完成下面类中的成员函数的定义。 class point { private: int m,n; public: point(int,int); point(point&); }; point::point(int a,int b) { m=a; n =b; } point::point( point& t ) { m=t.m; n=t.n; } 2.下面是一个输入半径,输出其面积和周长的C++程序,在下划线处填上正确的语句。 #include double r; cout<<″r=″; cin>>r ; double l=2.0*pi*r; double s=pi*r*r; cout<<”\n The long is:”< 3.在下划线处填上缺少的部分。 #include 第 34 页 共6页 using namespace std; class complex { public: int real; int imag; complex(int r=0,int i=0) { real=r; imag=i; } }; complex operator+( complex& a ,complex& b) { int r=a.real+b.real; int i=a.imag+b.imag; return complex(r,i) ; } void main( ) { complex x(1,2),y(3,4),z; z=x+y; cout< } 4.下面程序的输出结果如下: 1,9 50,30 请根据输出数据在下面程序中的下划线处填写正确的语句。 源程序如下: #include private: int m; base( ){ }; base(int a):m(a){} int get( ){return m;} void set(int a){m=a;} 第 35 页 共6页 public: 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库南京信息工程大学C++期中试卷(8)在线全文阅读。
相关推荐: