2017年电大《C++语言程序设计》期末考试试题及答案小抄参考.doc
上传人:天马****23 上传时间:2024-09-12 格式:DOC 页数:9 大小:70KB 金币:10 举报 版权申诉
预览加载中,请您耐心等待几秒...

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

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

预览

在线预览结束,喜欢就下载吧,查找使用更方便

10 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

小抄版C++语言程序设计期末考试试题及答案姓名____________学号____________班号___________题号一二(1)二(2)三总分成绩一、填空1.在类中必须声明成员函数的原型,成员函数的实现部分可以写在类外。2.如果需要在被调函数运行期间,改变主调函数中实参变量的值,则函数的形参应该是引用类型或指针类型。3.抽象类只能作为基类使用,而不能声明它的对象。4.进行函数重载时,被重载的同名函数如果都没有用const修饰,则它们的形参个数或类型必须不同。5.通过一个常对象只能调用它的常成员函数,不能调用其他成员函数。6.函数的递归调用是指函数直接或间接地调用自身。7.拷贝构造函数的形参必须是本类对象的引用。二、阅读下列程序,写出其运行时的输出结果如果程序运行时会出现错误,请简要描述错误原因。1.请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。(1)程序:#include<iostream.h>#include<string.h>classBase{private:charmsg[30];protected:intn;public:Base(chars[],intm=0):n(m){strcpy(msg,s);}voidoutput(void){cout<<n<<endl<<msg<<endl;}};classDerived1:publicBase{private:intn;public:Derived1(intm=1):Base("Base",m-1){n=m;}voidoutput(void){cout<<n<<endl;Base::output();}};classDerived2:publicDerived1{private:intn;public:Derived2(intm=2):Derived1(m-1){n=m;}voidoutput(void){cout<<n<<endl;Derived1::output();}};intmain(){BaseB("BaseClass",1);Derived2D;B.output();D.output();}运行结果:1BaseClass210Base(2)程序:#include<iostream.h>classSamp{public:voidSetij(inta,intb){i=a,j=b;}~Samp(){cout<<"Destroying.."<<i<<endl;}intGetMuti(){returni*j;}protected:inti;intj;};intmain(){Samp*p;p=newSamp[5];if(!p){cout<<"Allocationerror\n";return1;}for(intj=0;j<5;j++)p[j].Setij(j,j);for(intk=0;k<5;k++)cout<<"Muti["<<k<<"]is:"<<p[k].GetMuti()<<endl;delete[]p;return0;}运行结果:Muti[0]is:0Muti[1]is:1Muti[2]is:4Muti[3]is:9Muti[4]is:16Destroying..4Destroying..3Destroying..2Destroying..1Destroying..02.请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。(1)程序:#include<iostream.h>#include<stdlib.h>classVector{public:Vector(ints=100);int&Elem(intndx);voidDisplay(void);voidSet(void);~Vector(void);protected:intsize;int*buffer;};Vector::Vector(ints){buffer=newint[size=s];}int&Vector::Elem(intndx){if(ndx<0||ndx>=size){cout<<"errorinindex"<<endl;exit(1);}returnbuffer[ndx]