东南大学笔试A卷09103程序设计及算法语言电类Ⅱ.docx
- 文档编号:17671571
- 上传时间:2023-07-27
- 格式:DOCX
- 页数:19
- 大小:26.77KB
东南大学笔试A卷09103程序设计及算法语言电类Ⅱ.docx
《东南大学笔试A卷09103程序设计及算法语言电类Ⅱ.docx》由会员分享,可在线阅读,更多相关《东南大学笔试A卷09103程序设计及算法语言电类Ⅱ.docx(19页珍藏版)》请在冰点文库上搜索。
东南大学笔试A卷09103程序设计及算法语言电类Ⅱ
东南大学考试卷(A卷)
课程名称
程序设计及算法语言(电类)Ⅱ
考试学期
09-10-3
得分
适用专业
电类
考试形式
闭卷
考试时间长度
120分钟
()
题目
一
二
三
四
总分
得分
批阅人
自觉遵守考场纪律如考试作弊此答卷无效
一、选择题(每题1分,共10分)
1.在数组intarray[4][4]={{45,1,8},{9,28},{11,39,12,76},{64}}中,array[3][1]的值。
是。
A.0B.39C.8D.11
2.设有变量定义:
intnum=20;int*ip;double*dp;下面赋值不正确的是____。
A.ip=#B.*ip=#C.dp=ip;D.*dp=*ip;
3.设有变量定义如下:
intk=10;
inta=20,m=&k,*p1=&k,*p2=&m;
执行a=p1==&m;后a的值是。
A.10B.20C.0D.1
4.关于通过new运算符动态创建的对象数组,下列判断中是错误的。
A.动态创建的对象数组只能调用默认构造函数
B.动态创建的对象数组必须调用delete[]动态撤销
C.动态创建的对象数组的大小必须是常数或常变量
D.动态创建的对象数组没有数组名
5.顺序表不具有的特点是。
A.元素的存储地址连续
B.存储空间根据需要动态开辟,不会溢出
C.可以直接随机访问元素
D.插入和删除元素的时间开销与位置有关
6.假设一个对象Ob1的数据成员是指向动态对象的指针,如果采用浅复制的方式复制该对象得到对象Ob2,那么在析构对象Ob1和对象Ob2时会的问题。
A.有重复释放B.没有C.内存泄漏D.动态分配失败
7.假设对5个元素A、B、C、D、E进行压栈或出栈的操作,压栈的先后顺序是ABCDE,则出栈的先后顺序不可能是。
A.ABCDEB.EDCBAC.EDBCAD.BCADE
8.下列关于虚函数的判断中,是错误的。
A.类成员函数前用virtual修饰的称为虚函数。
B.只有通过指向派生类对象的基类类型的指针变量或引用来调用基类的虚函数,才能实现动态的多态性。
C.构造函数一般不定义为虚函数。
D.派生类中定义的函数名与基类的虚函数名相同就可以实现覆盖。
9.cin、cout、cerr和clog四个流对象中有个是全局标准流对象。
A.1B.2C.3D.4
10.打开一个二进制文件时必须采用模式。
A.ios:
:
inB.ios:
:
outC.ios:
:
binaryD.ios:
:
app
二、填空题(每空1分,共20分)
1.面向对象程序设计具有的特点:
、和。
2.C++中的多维数组用的是一个的定义,即多维数组的基本定义是以
作为元素构成的数组。
3.通过new运算符动态创建的对象的存放在中。
4.默认复制构造函数是按成员复制,称为。
5.为实现代码的,通常采用模板,它把数据类型改为一个,称为
程序设计。
6.类的继承方式有:
、和。
如果不显示给出访问控制关键字,则默认继承方式为。
7.以下程序中Sort()函数是顺序表的成员函数。
template
:
Sort(){
inti,j,k;
Ttemp;
for(i=0;i k=i;temp=slist[i]; for(j=i;j<=last;j++) if(slist[j] k=j; temp=slist[j]; } if(k! =i){ temp=slist[i]; slist[i]=slist[k]; slist[k]=temp; } } } 该成员函数用到的是排序。 若未排序前的数据为: 553498217643 外层for循环执行了第一次后的数据顺序为: 8. voida(node*p,Datatypex){ node*q=newnode; q->info=x; q->link=p->link; p->link=q; } 以上a函数实现的功能是。 9.通过表达式可以判断文件流fd的读写指针是否到达文件的尾部。 10.在文件中存取的最小信息单位为字符,而文件中存取的最小信息单位为字节。 三、阅读程序,根据要求填空: (共40分) 1.写出下面程序的输出结果(每空2分,共4分) #include usingnamespacestd; intmax_value(int*arr,intn) { inti,max=arr[0]; for(i=0;i if(arr[i]>max) max=arr[i]; return(max); } intmain() { inta[3][4]={{1,3,6,7},{2,4,6,8},{15,17,34,12}}; int*b=(int*)a; cout< cout< return0; } 输出结果: 2.指出以下程序的错误: (每空2分,本题10分) #include usingnamespacestd; classPrinter { intPrintValue; intPrintPages(); public: voidPrinter(intvalue); intPrintDocuments(); ~Printer(); ~Printer(intvalue); }; ……//成员函数在类外的定义在此处未具体写出。 (略) intmain() { PrinterHP,Canon(4); Canon.PrintPages(); return0; } 错误之处: 3.写出下面程序的输出结果(每空2分,本题4分) #include usingnamespacestd; voidswap1(doubled1,doubled2){ doubletemp; temp=d1;d1=d2;d2=temp; } voidswap2(double*d1,double*d2){ doubletemp; temp=*d1;*d1=*d2;*d2=temp; } intmain(void){ doublex=1.0,y=2.0; swap1(x,y); cout<<"x="< swap2(&x,&y); cout<<"x="< return0; } 输出结果: 4.写出下面程序的输出结果(每空1~3分,本题9分) #include usingnamespacestd; classstack{ int*rep; intsize,top; public: stack(intn=10): size(n)//构造函数 { cout<<"InitialConstructor"< rep=newint[size]; top=-1; } stack(stack&s): size(s.size)//复制构造函数,需深复制。 { cout<<"CopyConstructor"< rep=newint[size]; for(inti=0;i rep[i]=s.rep[i]; top=s.top; } ~stack() { cout<<"Destructor"< delete[]rep; } voidpush(inta){rep[++top]=a;} intpop(){returnrep[top--];} boolisEmpty(){returntop==-1;} }; intmain() { stack*ptr=newstack[2]; for(inti=1;i<5;i++) {ptr[0].push(i); ptr[1].push(i+6); } stacks2(ptr[0]); for(i=0;i<2;i++) cout< s2.push(ptr[1].pop()); ptr[0].push(ptr[1].pop()); s2.push(ptr[1].pop()); while(! s2.isEmpty()) cout< cout< delete[]ptr; return0; } 输出结果: (1分) (1分) (1分) (3分) (1分) (1分) (1分) 5.写出下面程序的输出结果(每空2分,本题8分) #include #include usingnamespacestd; classperson { charname[10]; intage; public: voidinit1(char*str,intk) { strcpy(name,str); age=k; } virtualvoiddisp() { cout<<"name: "< cout<<"age: "< } }; classstudent: publicperson { intnum; doubleavg; public: voidinit2(inti,doublef){num=i;avg=f;} voiddisp() { cout<<"num: "< cout<<"avg: "< } }; intmain() { personA,*p; studentB; A.init1("王明",19); p=&A; p->disp(); B.init2(20090332,97.5); p=&B; p->disp(); return0; } 输出结果: 6.写出下面程序的输出结果(每空1~2分,共5分) #include usingnamespacestd; template { returna+b; } voidmain() { cout< cout< cout< } 输出结果: (2分) (2分) (1分) 四、完善程序(13、14空每空1分,其余每空2分,共30分) 1.建立线性表模板,能够按照用户要求的元素个数(缺省为10个元素)创建数组、实现元素的有序插入(即将元素插入在有序数组适当位置,保持数组有序)、降序排列数组的二分查找以及数组打印。 主函数中将模板实例化,创建一个整型数组,通过调用有序插入函数建立一个降序排列的数组,并测试二分查找功能。 程序如下: #include usingnamespacestd; template classseqlist{ T*slist; intlast; intmaxsize; public: seqlist(intn=10){ maxsize=n; slist=newT[n]; last=-1; } ~seqlist(){if(slist) (1)} voidprint(){ for(inti=0;i<=last;i++)cout< cout< } voidinsertOrder(T); intbisearch(Tkey); }; template (2){ for(inti=last;i>=0&&slist[i] (3)=key; last++; } template intseqlist : bisearch(Tkey){ intlow=0,high=last,mid; while(low<=high){ mid=(low+high)/2; if(key elseif(key>slist[mid])high=mid-1; elsebreak; } if(low>high)(4); returnmid; } intmain(){ seqlist intk,p; cout<<"input8integers: "< for(inti=0;i<8;i++){//建立降序排列数组 cin>>k; (5); } a.print(); cout<<"inputanintegertobesearched: "< cin>>k; p=a.bisearch(k); if(p==-1)cout< elsecout<<"a["< return0; } 2、建立单链表模板类,并实例化为字符串链表,测试建立链表、查找结点并删除结点等功能。 #include #include usingnamespacestd; template template Tdata; Node*next; public: Node(){next=NULL;} Node(Td){data=d;next=NULL;} friendclassList }; template classList{ Node public: List(){head=tail=newNode ~List(){makeEmpty();deletehead;}//析构函数 voidmakeEmpty();//清空链表,只留下一个表头的空结点 Node voidprintList();//打印链表 Node //建立数据结点 voidinsertRear(Node //将p结点插在当前链表尾 voiddeleteNode(Node }; template voidList : printList(){ Node while(t){ cout< t=t->next;} cout< } template voidList : makeEmpty(){ Node while(head->next){ t=head->next; (7); deletet; } tail=head; } template Node : find(Tkey){ Node while((8))t=t->next; returnt; } template voidList : deleteNode(Node Node while(q&&q! =p){t=t->next;q=t->next;} t->next=q->next; deleteq; } intmain(){ List Node strings; cout<<"input6strings: "< for(inti=0;i<6;i++){ cin>>s; pNode=list1.createNode(s);//建立数据结点 list1.insertRear(pNode); } list1.printList(); cout<<"inputastring: "< cin>>s; pNode=list1.find(s); if(pNode)(10);//删除pNode结点 elsecout<<"nosuchstring."< list1.printList(); return0; } 3、在抽象类object基础上派生圆类和矩形类,它们各自重构抽象类中的calculate函数,以实现面积的计算;同时重载”<<”运算符实现对象数据的输出。 主函数用基类指针指向不同派生类对象,以实现与所指对象相一致的操作。 #include #include usingnamespacestd; classobject{//抽象类 public: (11);//定义calculate函数 }; classcircle: publicobject{ doublex,y,r; doublearea; public: circle(doublex0=0,doubley0=0,doubler0=1){x=x0;y=y0;r=r0;} (12){area=3.14*r*r;returnarea;} (13){ os<<'('< returnos; } }; classrectangle: publicobject{ doubleleft,bottom,right,top; doublearea; public: rectangle(doublea=0,doubleb=0,doublec=0,doubled=0){ left=a;bottom=b;right=c;top=d; } doublecalculate(){area=fabs((right-left)*(top-bottom));returnarea;} (14){ os<<"left="< returnos; } }; intmain(){ (15); circlec(1,2,4); pObj=&c; doublearea=pObj->calculate();//计算圆面积 cout< rectangler(1,1,4,5); pObj=&r; (16);//计算矩形面积 cout< return0; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 东南大学 笔试 09103 程序设计 算法语言
![提示](https://static.bingdoc.com/images/bang_tan.gif)