![中山大学信息科学及技术学院计算机科学系C程序设计A2014.06试卷_第1页](http://file4.renrendoc.com/view/4b81726f8a1acade1528f082522a7022/4b81726f8a1acade1528f082522a70221.gif)
![中山大学信息科学及技术学院计算机科学系C程序设计A2014.06试卷_第2页](http://file4.renrendoc.com/view/4b81726f8a1acade1528f082522a7022/4b81726f8a1acade1528f082522a70222.gif)
![中山大学信息科学及技术学院计算机科学系C程序设计A2014.06试卷_第3页](http://file4.renrendoc.com/view/4b81726f8a1acade1528f082522a7022/4b81726f8a1acade1528f082522a70223.gif)
![中山大学信息科学及技术学院计算机科学系C程序设计A2014.06试卷_第4页](http://file4.renrendoc.com/view/4b81726f8a1acade1528f082522a7022/4b81726f8a1acade1528f082522a70224.gif)
![中山大学信息科学及技术学院计算机科学系C程序设计A2014.06试卷_第5页](http://file4.renrendoc.com/view/4b81726f8a1acade1528f082522a7022/4b81726f8a1acade1528f082522a70225.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、警 示中山大学授予学士学位工作细则第六条考试作弊不授予学士学位计算机科学系 2014学年度第二学期 程序设计II 期末考试试题( A )任课教师:吴维刚 刘聪 考试形式: 闭卷 考试时间:2小时年级: 班别: 专业: 姓名: _ 学号: _成绩 1. Single Choice (20points)Please choose the choice that best completes the statement in the questionWhich of the following statements about object-oriented programming (OOP) is
2、 NOT correct?A) The key idea of OOP is to build programs using software object.B) OOP offers many advantages: simplicity, modularity, modifiability, and so on.C) OOP is more efficient than POP in terms of programming productivity.D) An object-oriented program can run faster than a procedure-oriented
3、 program with the same functionality. Which of the following statements about static data members is NOT correct?A) A static data member can initialized at declaration.B) A static data member refers to a member whose value cannot be changed after initialized.C) We may access static data members with
4、out before any object created.D) A static data member is shared by objects of the same class. Which of the following variables cannot be a member of class A? A) A *p B) A a C) A &r D) string sWhich of the following statements is not a characteristic of a constructor?A) The name of a constructor must
5、 be the same as the class.B) A constructor can be overloaded.C) The parameters of constructor may have default values.D) The return type of a constructor must be void.If C is a class name, how many times is the constructor of C called in C a, b2, *p2;?A) 2 B) 3 C) 4 D) 5If p is a pointer to an objec
6、t with a member function x(), which of the following access to x() is correct?A) *p.x B) p-x() C) *p-x() D) *p.x() Which of the following is NOT a member function of a class?A) constructor B) destructor C) friend function D) copy constructorIf class X is declared to be the friend of a class Y, then
7、which of the following statements is correct? A) Y can access the protected members of X.B) X can access the private members of Y. C) If class Z is declared to be friend of X, Z becomes Ys friend.D) Y becomes Xs friend automaticallyWhich of the following declarations of constant function member is c
8、orrect?A) void print() const;B) const void print();C) void const print();D) void print(const); To realize polymorphism, the following two elements are necessary:A) Multiple-inheritance and virtual function B) Virtual inheritance and function overloading C) Virtual function and pointer of base classD
9、) Virtual inheritance and dynamic castingWith the base class B and its derived D, which of the following statements has a compiling error? A) B * base = D(); B) B * base = new D(); C) B base = D(); D) B &base = D();Which of the following statements about virtual function is correct?A) Virtual functi
10、on is not a member function.B) Virtual function must be a static function.C) A virtual function in a base class must be defined, even though it may not be used.D) A virtual function is function without implementation.Which of the following statements about upcast is NOT correct?A) Upcast is to cast
11、a pointer of a base class to that of an derived class.B) C+ performs type checking for pointer to prevent errors.C) Upcast is always safe since an object of a derived class has everything of its base class.D) Upcast does not have to be explicit.Which of the following definitions about pure virtual f
12、unction is correct?A) virtual void fun()=0;B) void fun(int)=0;C) virtual void fun(int);D) virtual void fun(int)Which of the following statements about the operator new is NOT correct?A) The new operator is used to allocate storage dynamically.B) The new operator returns a object or a simple variable
13、. C) The delete operator should be used to destroy the variable/object created by new.D) The new operator is necessary to realize deep copy.Which of the following statements about constructor is correct?A) the constructor of a base class is executed after the constructor of a derived classB) the con
14、structor of a base class cannot have any parameter.C) the constructor of a base class can be used to create an object of a derived classD) the constructor of a base class need to be called explicitly.An exception thrown by a function can beA) caught by only the catch block of the same functionB) han
15、dled exactly onceC) can only be an object of the exception classes defined by C+ standardD) a variable defined by the userWith string s1; char s220; cins2;, which statement is NOT correct? A) s1 = s1+s2; B) s1.append(s2); C) s1 = s2; D) s2 = s1; Which is NOT an I/O object?A) std:cin B) std:cout C) s
16、td: cerr D) iostreamTo output data into a file, it is necessary for you toA) make sure the file is already there before opening it.B) open it in binary mode.C) know the format of the data.D) convertthedatatocharacters(oranobjectoftypestring).2. Output analysis (20points, 5points for each)Please writ
17、e down the printout of the following programs.1) A program about copy constructor1 #include2 usingnamespacestd;34 classPoint5 6 public:7 Point(int xx=0)8 x=xx;9 1011Point(Point &p)12x=p.x;13 cout”Calling the copy constructor”endl;141516int getX()17 return x;18 19 private:20 int x;21 ;2223 void fun1(
18、 Point p)24 coutp.getX()endl;25 2627 Point fun2()28Point a(1);29return a;30 31 int main()32 Point a(4);33 Point b=a;34 coutb.getX()endl;35 fun1(b);36 b=fun2();37 coutb.getX()endl;38 2) A program about inheritance1#include2usingnamespacestd;34 classB056 public:7 voidprint() cout”B0”endl; 8 ;910 class
19、B1:publicB01112 public:13void print() cout”B1”endl; 14 ;1516 class D1: public B117 18 public:19 void print() cout”D1”print();25 2627 int main()28B0 b0; B1 b1; D1 d1; B0 *p;29p=&b0;30fun(p);31p=&b1;32 fun(p);33 p=&d1;34 fun(p);35 3) A program about string and vector1 #include2 #include3 using namespa
20、ce std;45 int main()6 int n=7;7vector v;8for(int i=1; i=n; i+)9 v.push_back(i);10 11 int j=2;12 for( int i=1; i=n; i+)13 coutvj” ”;14 v.erase(v.begin()+j);15 if(v.size()!=0)16 j=(j+2)%v.size();17 18 194) A program about template and exception1 #include2 #include3 usingnamespacestd;45 classEmptyStack
21、Exception;67 template8 classStack9 10 private:11vectorimpl;1213 public:14 voidpush(constE&e)15 impl.push_back(e);16 1718Epop()19if(impl.size()=0)20throwEmptyStackException();21Ee=implimpl.size()-1;22impl.pop_back();23returne;2425 ;2627 intmain()28 Stackstack;29 for(inti=0;i3;+i)30 stack.push(0.5+i);
22、3132try33while(true)34coutstack.pop()endl;353637catch(EmptyStackException&ex)38coutcaught:EmptyStackExceptionendl;3940 3. Error Correction (20points)Thereare5errorsintotalineachofthefollowingprogram.Youneedtofindout10ofthem,whichyouaremostconfident.Ifyoulistmorethan10errors,onlythefirst10errorswillb
23、egraded. 1). Class and object1)#include 2)using namespace std;3)4) class MyClass 5) 6) public:7) MyClass(int x) 8) member=x; 9) 10) GetMember() 11) return member;12) 13) void SetMember(int m) 14) member=m; 15) 16) void MyClass() 17) private:18) int member=0; 19) ;20)21)int main()22) MyClass obj1; 23
24、) MyClass obj2(3);24) obj1.SetMember(1);25) coutobj2.memberendl; 26) return 0;27)2). Inheritance and Template1)#include 2)using namespace std;3)4)template5)class BASE 6) 7) public: 8) void show(TYPE obj)9) coutobjendl; 10) 11) 12) 13)template 14)class DERIVED: :public BASE 15)public: 16) void show(T
25、YPE obj1, TYPE1 obj2)17) coutobj1endl;18) BASE:show(obj2); 19) 20);21)22)int main()23)DERIVED obj;24) BASE *pBase=&obj; 25) DERIVED *pDerived=pBase; 26) obj.show(“Pi is”, 3.14);27) return 0;28) 3). Template and vector1)#include 2)#include 3)using namespace std;4) 5)template 6)class MyQueue 7)8)priva
26、te:9) vector impl; 10) 11)public: 12) void enqueue(E &e) 13) impl.push_back(e); 14) return e;15) 16) E dequeue(); 17); 18)template 19)E MyQueue:dequeue() 20) E e = impl0; 21) impl.pop_back();22) return e;23) 24)int main() 25) MyQueue q; 26) q.enqueue(100); 27) q.dequeue(0); 28)4. Concept explanation (20points) Please explain the following concepts with concrete examples. You can choose 4 out of all the 5 questions to an
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度房地产个人借款担保合同范本
- 2025年度海洋渔业资源保护合作开发合同
- 2025年度风力发电场建设安全操作合同
- 贵州2025年贵州省司法厅所属事业单位招聘2人笔试历年参考题库附带答案详解
- 衢州2025年浙江衢州职业技术学院招聘人员9人笔试历年参考题库附带答案详解
- 医疗文书管理制度
- 新疆维吾尔自治区克孜勒苏柯尔克孜自治州九年级上学期1月期末语文试题(PDF版含答案)
- 河南2024年河南信阳师范大学招聘专职辅导员30人笔试历年参考题库附带答案详解
- 2025年中国中空导电粒市场调查研究报告
- 2025年贡丸串项目可行性研究报告
- 21中华文化-2023年中考英语新热点时文阅读
- 学校课程整体框架图
- 环境卫生学第二章 环境与健康的关系
- 2024届高考语文复习:小说阅读之叙事顺序与叙事节奏
- 环卫市场化运营方案PPT
- 电流互感器和电压互感器选型指南
- 大学生心理健康教育PPT完整全套电子教学课件
- 会务服务投标技术方案
- 中国传统图案大全
- 人间草木读书报告
- 市政污水管网深基坑拉森钢板桩支护专项施工方案
评论
0/150
提交评论