收藏 分销(赏)

C--复习题.doc

上传人:仙人****88 文档编号:7926760 上传时间:2025-01-27 格式:DOC 页数:4 大小:35.50KB 下载积分:10 金币
下载 相关 举报
C--复习题.doc_第1页
第1页 / 共4页
C--复习题.doc_第2页
第2页 / 共4页


点击查看更多>>
资源描述
7、实现运行时的多态性要使用( ) A) 重载函数 B) 构造函数 C) 析构函数 D) 虚函数 10、当保护继承时,基类的( )在派生类中成为保护成员,不能通过派生类的对象来直接访问该成员。 A) 任何成员; B) 公有成员和保护成员; C) 保护成员和私有成员; D) 私有成员; 11、以下( )成员函数是纯虚函数。 A) virtual int f(int) B) void f(int)= 0 C) virtual void f()=0 D) virtual void f(){} 三、        程序分析 1、分析程序,写出程序的输出结果(6分)。 #include <iostream.h> class A { public: A() {cout<<"A's con."<<endl;} ~A() {cout<<"A's des."<<endl;} }; class B { public: B() {cout<<"B's con."<<endl;} ~B() {cout<<"B's des."<<endl;} }; class C:public B { public: C():member(),B() {cout<<"C's con."<<endl;} ~C(){cout<<"C's des."<<endl; } private: A member; }; void main() { C obj; } 3。分析下列程序中的错误,并说明出错原因。     #include     class A {     int x;     public:     A(int a) { x=a; fun(); }     virtual void fun()=0;     };     class B:public A {     public:     B(int b) :A(b) {}     void fun() { }     };     void main()     { A aa(5);     B bb(8);     } 5.写出下列程序的运行结果。     #include     class AA {     int a;     public:     AA(int i) { a=i; cout<<”AA=”<<A<<>     virtual ~AA() { cout<<”~AA=”<<A<<>     };     class BB:public AA {     int b;     public:     BB(int i,int j):AA(i) { b=j; cout<<”BB=”<<B<<>     ~BB() { cout<<”~BB=”<<B<<>     };     void main()     { AA *pa=new AA(8);     delete pa;     AA *pb=new BB(6,9);     delete pb;     } 7.写出下列程序的输出结果。     #include     class AA {     public:     AA{} { cout<<”Constructor of AA. \n”; fun(); }     virtual void fun() { cout<<”AA::fun() calle     D.\n”; }     };     class BB:public AA {     public:     BB(){ cout<<”Constructor of B     B.\n”; fun(); }     void fun() { cout<<”BB::fun() calle     D.\n”; }     };     void main()     { BB d; }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服