您好,欢迎访问三七文档
||||||||密|||||||||封|||||||||线||||||||||河北师范大学考试命题专用纸《面向对象程序设计》期中考试试题一二三四五六七八九十总分代号A学院软件学院专业年级08学号姓名备注:①试卷首页必须用统一的考试命题专用纸,第二页以后用专用纸续页。②试卷必须打印成卷字迹要工整、清楚。③各题留出答案空白。④试卷打印后应认真校对,避免卷面错误。得分阅卷人一、程序分析题(共11题,70分)1.阅读程序,指出错误。(3分)#includeiostreamintmain(void){coutHelloworld!\n;return0;}答:___usingnamespacestd;或std::cout或usestd::cout;_____________________________________________________________2.阅读程序,指出错误。(5分)#includeiostreamvoidfoo(intx,inty=3){//TODO}intmain(void){intx=3;int*p=3;int&q;q=x;return0;}答:_____*p不可直接赋数值。q=x;应该删除,int&q;改成int&q=x;_____________________________________________________________3.阅读程序,根据提示完成程序。(5分)#includeiostreamusingnamespacestd;intx=3;//定义全局变量xnamespacens1//写出名字空间定义的关键字{intx=4;};intmain(void){intx=5;cout::xendl;//打印出全局变量x中的值coutns1::xendl;//打印出名字空间ns1中x的值return0;}4.分析程序中定义的各指针的特点,并指出错误的语句。(10分)#inclueiostreamusingnamespacestd;intmain(void){intx=3;inty=4;intz=5;int*px=&x;int*py=&y;int*constpz=&z;/*声明的同时必须初始化*/int*const*const_p2x=&px;/*声明的同时可以不初始化*/int**const_const_p2x=&px;/*声明的同时必须初始化*/int*const*constconst_const_p2x=&px;/*声明时必须初始化*/pz=&y;const_p2x=&py;*const_p2x=&y;**const_p2x=5;_const_p2x=&py;*_const_p2x=&y;**_const_p2x=5;共10页,第1页共10页,第2页|||||||||密|||||||||封|||||||||线线||||||||||const_const_p2x=&py;*const_const_p2x=&y;**const_const_p2x=5;system(PAUSE);return0;}答:_____________________________________________________________________________________________________________________________________________________________________________5.阅读程序,指出错误。(7分)#includeiostreamusingnamespacestd;classPerson{intage=3;//intage;public:voidsetAge(intage=0){this.age=age;//this-age=age;}public:intgetAge(){returnthis.age;//this-age;}}intmain(void){Personperson0;person0.setAge();coutperson0.getAge()endl;Personperson1=newPerson;//Person*person1=newPerson;person1.age=4;//person1-setAge(4);deleteperson1;return0;};答:_____________________________________________________________________________________________________________________________________________________________________________河北师范大学考试命题专用纸试卷代号A学院软件学院专业年级08姓名学号6.阅读程序,给出执行结果。(10分)#includeiostreamusingnamespacestd;classStudent{floatscore;public:Student(){coutStudent::Student()iscalled.endl;}Student(floatscore){this-score=score;coutStudent::Student(float)iscalled.endl;}~Student(){coutStudent::~Student()iscalled.endl;}}intmain(void){Studentstudent0;Student*student1=newStudent;Student*student2=newStudent(3.0);coutHelloworld!endl;deletestudent2;deletestudent1;return0;}答:__Student::Student()iscalled.__________________________Student::Student()iscalled.____________________________Student::Student(float)iscalled.__________________________Helloworld!___________________________________Student::~Student()iscalled.__________________________Student::~Student()iscalled.Student::~Student()iscalled.____________________共10页,第3页共10页,第4页|||||||||密|||||||||封|||||||||线线||||||||||7.请问下面两个函数定义是否算重载?为什么?(5分)intfoo(){//TODO}doublefoo(){//TODO}答:不算。因为返回值不能作为重载的依据。____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________8.阅读程序,根据提示完成程序。(5分)#includeiostreamusingnamespacestd;classPerson{public:Person(constPerson&person);//请写出拷贝构造函数的函数原型声明};河北师范大学考试命题专用纸试卷代号A学院软件学院专业年级08姓名学号9.阅读程序,指出错误并改正。(10分)#includeiostreamusingnamespacestd;classPerson{constintage=0;//改成constintage;floatscore;public:voidPerson():age(0)//构造函数没有返回值{this-age=0;//删除}voidsetScore(floatscore)const//删除const{this-score=score;}};intmain(){Personperson0;return0;}答:______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________共10页,第5页共10页,第6页|||||||||密|||||||||封|||||||||线线||||||||||10.阅读程序,一方面根据提示完成程序,一方面给出其输出结果。(5分)#includeiostreamclassA{staticintx;public:A(){x++;}};intA::x=0;//对A::x进行初始化,将其初值设置为0;intmain(){coutA::xendl;Aa0;coutA::xendl;Aa1;coutA::xendl;return0;}结果:_01_________________________________________________________2_____________________________________________________11.根据提示完成程序.(5分)#includeiostreamusingnamespacestd;classA{intx;public:friendboolfoo(Aa);//声明foo函数是A的友元.};boolfoo(Aa){a.x=3;};intmain(void){Aa;return0;}河北师范大学考试命题专用纸试卷代号A学院软件学院专业年级姓名学号得分阅卷人二、判断题(共10题,15分)1.静态成员变量的存储空间被同类对象共享。(对)2.成员方法(函数)的存储空间不被同类对象共享。(错)3.const成员变量的存储空间被同类对象共享。(错)4.静态成员变量只能被静态成员方法所访问。(错)5.静态成员方法不能访问非静态成员变量。(对)6.对一个拥有静态成员变量的类而言,每实例化一次,都将为该静态成员变量分配一次存储空间。(错)7.程序员使用new申请的空间,必须用delete释放。(对)8.同类对象所具有的成员变量和成员函数一样。(对)9.用户可以在堆区、栈区、全局区实例化对象。(对)10.顶层函数可以作为某个类的友元,但一个类的成员函数不可以作为另一个类的友元。(错)得分阅卷人三、程序题(共1题,15分)有如下类:课程类(Course):课程编号(私有成员)、课程名称(私有成员)
本文标题:C++期中考试试卷
链接地址:https://www.777doc.com/doc-2904258 .html