文档详情

2017年电大C++语言程序设计__期末考试试题及答案小抄参考.doc

发布:2018-05-19约5.08万字共13页下载文档
文本预览下载声明
C++语言程序设计 期末考试试题及答案 姓名 ____________ 学号 ____________ 班号 ___________ 题 号 一 二(1) 二(2) 三 总 分 成 绩 一、填空 1.在类中必须声明成员函数的 原型 ,成员函数的 实现 部分可以写在类外。 2.如果需要在被调函数运行期间,改变主调函数中实参变量的值,则函数的形参应该是 引用 类型或 指针 类型。 3. 抽象 类只能作为基类使用,而不能声明它的对象。 4.进行函数重载时,被重载的同名函数如果都没有用const修饰,则它们的形参 个数 或 类型 必须不同。 5.通过一个 常 对象只能调用它的常成员函数,不能调用其他成员函数。 6.函数的递归调用是指函数直接或间接地调用 自身 。 7.拷贝构造函数的形参必须是 本类对象的引用 。 二、阅读下列程序,写出其运行时的输出结果 如果程序运行时会出现错误,请简要描述错误原因。 1.请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。 (1)程序: #include iostream.h #include string.h class Base { private: char msg[30]; protected: int n; public: Base(char s[],int m=0):n(m) { strcpy(msg,s); } void output(void) { coutnendlmsgendl; } }; class Derived1:public Base { private: int n; public: Derived1(int m=1): Base(Base,m-1) { n=m; } void output(void) { coutnendl; Base::output(); } }; class Derived2:public Derived1 { private: int n; public: Derived2(int m=2): Derived1(m-1) { n=m; } void output(void) { coutnendl; Derived1::output(); } }; int main() { Base B(Base Class,1); Derived2 D; B.output(); D.output(); } 运行结果: 1 Base Class 2 1 0 Base (2)程序: #include iostream.h class Samp {public: void Setij(int a,int b){i=a,j=b;} ~Samp() { coutDestroying..iendl; } int GetMuti(){return i*j;} protected: int i; int j; }; int main() { Samp *p; p=new Samp[5]; if(!p) { coutAllocation error\n; return 1; } for(int j=0;j5;j++) p[j].Setij(j,j); for(int k=0;k5;k++) coutMuti[k] is: p[k].GetMuti()endl; delete[]p; return 0; } 运行结果: Muti[0] is:0 Muti[1] is:1 Muti[2] is:4 Muti[3] is:9 Muti[4] is:16 Destroying..4 Destroying..3 Destroying..2 Destroying..1 Destroying..0 2.请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。 (1)程序: #include iostream.h #include stdlib.h class Vector { public: Vector(int s=100); int Elem(int ndx); void Display(void); void Set(void); ~Vector(void); protected: int size;
显示全部
相似文档