2004程序实习考题new

上传人:marr****208 文档编号:149741373 上传时间:2020-10-29 格式:DOC 页数:12 大小:61.50KB
返回 下载 相关 举报
2004程序实习考题new_第1页
第1页 / 共12页
2004程序实习考题new_第2页
第2页 / 共12页
2004程序实习考题new_第3页
第3页 / 共12页
2004程序实习考题new_第4页
第4页 / 共12页
2004程序实习考题new_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《2004程序实习考题new》由会员分享,可在线阅读,更多相关《2004程序实习考题new(12页珍藏版)》请在金锄头文库上搜索。

1、一、 单项选择题(共20分,每题2分,正确答案只有一项)1. 抽象类A. 至少含有一个纯虚函数B. 至少含有一个静态函数C. 其派生类必须提供纯虚函数的实现代码D. 可以定义抽象类的对象,也可以由派生类生成新类(A)2. 以下说法中正确的是:A. 一个类可以有不止一个复制构造函数B. 构造函数的返回值类型是 voidC. 一个类只能定义一个析构函数,但可以定义多个构造函数D. 一个类只能定义一个构造函数,但可以定义多个析构函数(C)3. 下列函数模板中定义正确的是:A. templateT1 fun (T1,T2) return T1 + T2; B. templateT fun(T a) r

2、eturn T + a;a) tempmlateT1 fun(T1,T2) return T1 + T2 ; b) templateT fun(T a,T b) return a + b ; (D)4. 如果类定义中没有使用 private、protected、或public 关键字,则所有成员A. 都是 public 成员 B. 都是 proctected 成员C. 都是 private 成员 D. 不一定(C)5. 对于通过 new 运算符生成的对象A. 在程序结束时自动析构B. 执行 delete 操作时才能析构C. 在包含该 new 语句的函数返回时自动析构 D. 在执行 delete

3、 操作时会析构,如果没有执行delete操作,则在程序结束时自动析构(B)6. 如果某函数的返回值是个对象,则该函数被调用时,返回的对象A. 是通过复制构造函数初始化的B. 是通过无参数的构造函数初始化的C. 用哪个构造函数初始化取决于函数中 return 语句是怎么写的D. 不需要初始化(A)7. 以下说法正确的是:A. 在静态成员函数中可以调用同类的其他任何成员函数B. const成员函数不能作用于非 const 对象C. 在静态成员函数中不能使用 this 指针D. 在纯虚函数中可以调用同类的其他非虚函数(C)8. 如果将运算符 “”重载为某个类的成员运算符(也即成员函数),则该成员函数

4、的参数个数是:i. 0 个 B. 1个 C. 2个 D. 3个 (B)9. 编译器根据类模板,在需要的时候能自动生成:A. 一个或多个相似的函数B. 一个或多个函数模板C. 一个或多个对象D. 一个或多个相似的类(D)10. 以下说法不正确的是(假设在公有派生情况下)A. 可以将基类对象赋值给派生类对象B. 可以将派生类对象的地址赋值给基类指针C. 可以将派生类对象赋值给基类的引用E. 可以将派生类对象赋值给基类对象(A)二以下程序编译、连接都能通过,请写出运行时输出的结果。你认为没有输出的,就写无输出(共50分)。1)(5分) *变量作用域int a;class CA private :in

5、t a;public: void SetA() a = 10; CA( int i) a = i;int GetA() return :a; ;int main () int a; a = 15; :a = 2; cout :a ,a endl; CA objCA(100); objCA.SetA (); cout :a ,a , objCA.GetA() endl; /2,15/2,15,22)(5分) *引用int g = 10;int SetValue1( int n) n = 10; return n; int & SetValue2( int & n ) n = 20; return

6、 n; main() int & ref = g;ref = 100; SetValue1( ref );cout g ,; SetValue2(ref);cout g ,; SetValue2(g) = 300;cout g , ; int const c = 70;ref = c; ref = 15;cout ref , c;/100,20,300,15,703)(4分) *构造函数class CSample int x;public: CSample() cout C1 endl; CSample(int n ) x = n;cout C2,x= n endl; ;main()CSamp

7、le array12;CSample array22 = 6,8;CSample array32 = 12;CSample * array4 = new CSample3;/C1/C1/C2,x=6/C2,x=8/C2,x=12/C1/C1/C1/C1 4)(8分) *构造函数class Demo int id;public:Demo(int i) id = i; cout id= id ,Con endl; Demo() cout id= id ,Des endl; ;Demo d1(4);void fun(Demo d) static Demo d2(2);Demo d3(3);cout

8、fun endl; void main () cout main endl;fun(d1);cout endmain endl;fun(d1); Demo * p = new Demo(8);/*id=4,Conmainid=2,Conid=3,Confunid=3,Desid=4,Desendmainid=3,Confunid=3,Desid=4,Desid=8,Conid=2,Desid=4,Des*/5)(4分) *函数覆盖class B private:int nBVal;public: void Print() cout nBVal= nBVal endl; void Fun() c

9、out B:Fun endl; B ( int n ) nBVal = n;class D:public B private :int nDVal;public:void Print() B:Print();cout nDVal=nDValendl;D( int n) : B(3*n) nDVal = n;void Fun() cout D:Fun Fun(); pd-Fun();pb-Print (); pd-Print ();pb = & d; pb-Fun();pb-Print();/*D:FunB:FunD:FunnBVal=2nBVal=24nDVal=8B:FunnBVal=12*

10、/6)(4分) *多继承class Base public:int val;Base() cout Base Constructor endl; Base() cout Base Destructor endl;class Base1:virtual public Base ;class Base2:virtual public Base ;class Derived:public Base1, public Base2 ;main() Derived d; /*Base constructorBase destructor*/7)(5分) *多态class A public:A( ) vir

11、tual void func() cout A:func endl; A( ) virtual void fund( ) cout A:fund endl; ;class B:public A public:B ( ) func( ) ; void fun( ) func( ) ; B ( ) fund( ); ;class C : public B public :C( ) void func( ) cout C:func endl; C() fund( );void fund() cout C:fund endl;main() C c; /*A:funcC:fundA:fund*/8)(5分) *模板重载template T Max( T a,T b) cout TemplateMax endl;return 0; double Max(double a,double b)cout MyMax endl;return 0; main() int i=4,j=5; Max( 1.2,3.4); Max(i,j); /MyMax/TemplateMax9)(5分) *静态成员#include class Apple private :int nWeight;static int nTotalNumber;public:

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号