收藏 分销(赏)

东南大学C++下期末考试笔试卷.doc

上传人:人****来 文档编号:3583702 上传时间:2024-07-10 格式:DOC 页数:12 大小:48.50KB
下载 相关 举报
东南大学C++下期末考试笔试卷.doc_第1页
第1页 / 共12页
东南大学C++下期末考试笔试卷.doc_第2页
第2页 / 共12页
东南大学C++下期末考试笔试卷.doc_第3页
第3页 / 共12页
东南大学C++下期末考试笔试卷.doc_第4页
第4页 / 共12页
东南大学C++下期末考试笔试卷.doc_第5页
第5页 / 共12页
点击查看更多>>
资源描述

1、东南大学C+下期末考试笔试卷一、选择题(每题1分,共 10 题,共 10 分)1、在数组int b4=1,3,4,4,7,9,10,8,5,6中,b22的值是 D 。A0 B 4 C 7 D92、以下关于this指针描述正确的是 C 。A使基类公有成员在子类中能够被访问。Bthis指针必须写成显式的。Cthis指针总指向要调用的其成员函数的对象。D静态成员函数也存在this指针。3、如果经过new运算符动态分配失败,返回结果是 B 。A-1 B0 C1 D不确定4、 D 是一种限制存取位置的线性表,元素的存取必须服从先进先出的规则。A顺序表B链表 C栈D队列5、下列关于指针运算的描述,错误的是

2、 D 。A可将一个空指针赋给某个指针。B两个指针在一定条件下,能够进行相等和不等运算。C一个指针能够加上一个整数,指向当前元素后面的若干个位置的元素。D两个指针在一定条件下能够相加。6、实现深复制,下面的类成员函数中, A 不是必须自定义的。A 构造函数 B 复制构造函数C 析构函数D 复制赋值操作符函数7、 设数组int fibon10,int *pfib=fibon; 则访问fibon数组第二个元素,以下写法错误的是 B 。A fibon1 B*+fibon C*+pfib D*(pfib+1)8、 假设Person类包含公有成员name,私有成员id和受保护成员GetID,而Studen

3、t类私有继承了Person类,那么Student类的成员函数能够直接访问 C 。APerson类的所有成员B仅有Person类的公有成员nameC仅有Person类的公有成员name和受保护成员GetIDDPerson类的任何成员都不能访问9、 实现多态的派生类函数不必 D 。A与基类虚函数同名 B与基类虚函数同参数表C与基类虚函数同返回类型 D用virtual修饰10、分析下列代码是否存在问题,选择合适的选项: B 。int main(void)int *p = new int 10; p = new int 10; delete p; p = NULL;return 0;A没有问题 B有内

4、存泄漏 C存在空悬指针 D存在重复释放同一空间二、填空题(每空 1 分,共 20 空,共 20 分)1、有序数组int B17中存放17个元素,用对半查找法查找B11元素,则进行比较的数组下标值依次是 8,12,10,11 。2、设整数型指针P1,P2分别指向整数型数组A10=1,2,0,4,5,9,7,8,6,4的第2和第5个元素,则P2-P1= 3 ,A5-A2= 9 。3、单链表的结点分为 指针 域和 数据 域两部分。4、标明为无具体实现的虚函数是 纯虚函数 。包含该函数的类称为 抽象类 ,不能用来定义对象。5、C+文件流采用两种格式访问文件:文本格式和二进制格式。前者按 字符 存取,后

5、者按 字节 存取。6、重载提取运算符和插入运算符实现对象的输入和输出,需要将重载的运算符函数声明为该类的 友元函数 。7指针类型变量用于存贮 地址 , 在内存中它占有4个存贮单元。8. 设有说明:int a, k, m, *p1=&k, *p2=&m; 执行a=p1=&m;后a的值是 0 。9若有:int i,&j=i;i=1;j=i+2;则 i= 3 。10 构造函数 是一种特殊的成员函数,它主要用来为对象分配内存空间,对类的数据成员进行初始化并执行对象的其它内部管理操作。11一般情况下,使用系统提供的默认析构函数就能够了,但当对象的成员中使用了 new 运算符动态分分配内存空间时,就必须定

6、义析构函数以正确释放对象空间。为了对象间能正确赋值,还必须要 重载运算符= 。12在类的派生过程中,要实现动态多态性,首先在类中必须要定义 虚函数 ,还要在使用对象的函数中定义 基类 指针,使该指针指向不同类的对象。13 . 利用成员函数对双目运算符重载,其有 1 个参数,该参数为运算符的 右操作函数 。三、阅读程序题(每空1-2分,共 40 分)1、以下程序的输出结果是:(本题6分,每空2分)#include using namespace std;void main(void) int a,b,k=4,m=6,*p1=&k,*p2=&m; int arr=30,25,20,15,10,5,

7、*p=arr; p+; cout*(p+3)endl; a=(p1=&m); b=(*p1)/(*p2)+7; couta=aendl; coutb=bendl;程序运行结果: 10 a=0 b=7 2、改正以下程序的错误:(本题8分,每空2分)#include using namespace std;class Sample int value; public: void Sample( int a ) value =a;int Max (int x,int y) return xy?x:y;int Max (int x,int y,int z=0) if (xy) return xz?x:

8、z; else return yz?y:z; Sample (int a) value =0;void main(void)Sample s(4);couts.valueendl;s.Max(10,20);以上程序中的错误有: Void去掉 重载产生二义性 析构函数不能有参数 私有数据成员不可类外访问 3、指出程序的运行结果:(本题8分,每空2分)#include using namespace std;class Vectorint x,y;public:Vector() ;Vector(int i,int j) x=i;y=j;void disp() cout (x,y)endl;void

9、 operator+=(Vector D) x+=D.x; y+=D.y;void operator-=(Vector D) x-=D.x; y-=D.y;void main(void)Vector A(1,2),B(4,2);coutA:;A.disp( );coutB:;B.disp( );A+=B;coutA+=B:;A.disp( );A-=B;coutA-=B:;A.disp( );程序运行结果: A(1,2) B(4,2) A+=B(5,4) A-=B(1,2) 4、下面是一个实现类的继承与派生的程序,请写出程序运行结果,并根据主函数中编程者的原意(调用派生类的成员函数),修改类的

10、成员定义,然后写出修改后的运行结果(本题10分)#include using namespace std;class Apublic: virtual void fun1()cout A fun1endl; virtual void fun2()cout A fun2endl; void fun3()cout A fun3endl;class B:public Apublic: void fun1()cout B fun1endl; void fun2(int x)cout B fun2endl; void fun3()cout B fun3fun1( ); p-fun2( ); p-fun3

11、( );修改前输出结果如下(每空1分): B fun1 B fun2 A fun3 纠正错误:(每空2分) Fun3改为虚函数 Fun2参数X去掉 修改后的输出结果如下(每空1分): B fun1 B fun2 B fun3 5、指出程序的运行结果:(本题8分,每空1分)#include using namespace std;class B1public:B1()coutB1:Constructorendl;B1()coutB1:Destructorendl;class B2public:B2()coutB2:Constructorendl;B2()coutB2:Destructorendl

12、;class B3public:B3()coutB3:Constructorendl;B3()coutB3:Destructorendl;class A:public B2,public B3B1 b1;public:A():B3(),B2(),b1()coutA:Constructorendl;A()coutA:Destructorendl;void main(void) A a;该程序的执行结果如下: B2 Constructor B3 Constructor B1 Constructor A Constructor A Destructor B1 Destructor B2 Destru

13、ctor B3 Destructor 四、完善程序填空题(每空2分,共 15 空,共 30 分)1. 完成如下程序,要求实现方阵(矩阵行列数目相同)的上三角元素(含对角线元素)的和。#includeusing namespace std;const int n=10;int main(void)int elementsnn= 1,1,1, ; /*初始化二维数组,首行前三个元素为1,其它元素为*/int sum=0;for(int i=0;in;i+)for( int j=i ; jn ;j+) sum+= elementsij ;coutsumendl; /*输出上三角的和*/return

14、0;2. 如下已定义点类Point,包含x,y坐标数据成员;再采用聚合和派生两种复合方式定义线段类Line。完成Line类的定义与实现。class Pointfriend class Line;protected:double x, y; public:Point(double xv = 0, double yv = 0) x = xv; y = yv;double area() return 0;void show() cout点坐标:x=x y=yendl;class Line : public PointPoint end;/终点public:Line(double xv1 = 0, d

15、ouble yv1 = 0, double xv2 = 0, double yv2 = 0) : Point (xv1, yv1), end(xv2, yv2) double getLength()return sqrt(x - end.x) * (x - end.x) + (y - end.y) * (y - end.y);double area() return 0;void show()cout起点: n;Point:show();cout终点: n; end .show();3. 下列程序将结构体变量tt中的内容写入D盘上的date.txt文件。#include #include st

16、ruct dateint year,month,day;void main(void)date tt= ,6,10;ofstream outdate ;outdate.open(d:date.txt,ios:binary);if ( !outdate ) cerr n D:write1.dat not open endl ; exit (-1) ; outdate.write( (char*)&tt ,sizeof(tt); outdata.close() ;4. 完善fruit类的构造函数、析构函数、深拷贝构造函数#include#includeusing namespace std;cla

17、ss fruitstring name; /水果名称string shape; /水果形状string color; /水果颜色double weight;/水果均重double *price;/指向一年中每个季度水果的均价public:fruit( string N,string S,string C,double W,double *p=0):name(N),shape(S),color(C),weight(W),price(P)fruit()if(price)delete price ;fruit(fruit& F)name=F.name;shape=F.shape;color=F.co

18、lor;weight=F.weight;if(F.price) price= new double4 ;for(int i=0;i4;i+) pricei=F.pricei ;else price=F.price;void setprice()if(price)cout请输入每个季度name的均价:n;for(int i=0;ipricei;int main(void)double *price_melon=new double4;fruit strawberry ; /运行后strawberry中的数据成员依次为:#,#,#,0,NULLFruit melon(watermelon,sphere,black and green,8.5,price_melon);melon.setprice();fruit Dongtai_melon(melon);return 0;5. 下面是一个选择排序函数,完成将数组元素值按上升的次序来排序,请完善程序。 void sort(int a,int n) for (int i = 0; i n; i+) int pos=i ; for (int j= i+1; j n; j+) if (ajapos) pos=j ; int temp = apos; apos = ai; ai = temp;

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服