2004年下半年程序员下午试卷

考试总分:8分

考试类型:模拟试题

作答时间:60分钟

已答人数:967

试卷答案:有

试卷介绍: 2004年下半年程序员下午试卷

开始答题

试卷预览

  • 1. 试题二(15分,每空3分)阅读下列说明和流程图,将应填入__(n)__的字句写在答题纸的对应栏内。【函数说明】函数sort(inta[],intn)的功能时对数组a中的a[0]~a[n-1]这n个元素进行排序。排序过程如下:第一趟对所有的偶数下标p,比较a和a[p+1],若a>a[p+1],则将两者交换;第二趟对所有的奇数下标q,比较a[q]和a[q+1],若a[q]>a[q+1],则将两者交换;第三趟对偶数下标,第四趟对奇数下标,…,依次类推,直至整个数组元素有序排列为止。【函数]voidsort(inta[],intn){intI,j,t,tag=1;for(j=0;j<n;j++={for(I=__(1)__;i<n-1;__(2)__={if(a>a[I+1]){t=a;a=a[I+1];a[I+1]=t;tag=0;}}tag++if(__(3)__)break;}}对包含十个元素的数组a采用上述方法排序时,元素间的比较次数最少为__(4)__次,最多为__(5)__次。[15分]

    A(1)__;i<n-1;__

    B(2)__={if(a>a[I+1]){t=a;a=a[I+1];a[I+1]=t;tag=0;}}tag++if(__

    C(3)__)break;}}对包含十个元素的数组a采用上述方法排序时,元素间的比较次数最少为__

    D(4)__次,最多为__

    E(5)__次。[15分]

  • 2. 试题三(15分,每空3分)阅读下列说明和流程图,将应填入__(n)__的字句写在答题纸的对应栏内。【函数说明]函数movetoend(LinkedListLainti)的功能时:将线性表示A的第I个元素移到表尾。若移动成功,则返回0,否则返回-1。线性表A采用带头结点的单链表表示,La为表A的头指针,如下图所示。链表结点的类型定义为:typedefstructnode{intkey;structnode*next;}*LinkedList【函数]intmovetoend(LinkedListLa,inti){LinkedListp,q,prep;Intk=1;P=La->next;prep=La;While(__(1)__){/*查找第I个元素并使指针p指向该结点*/Prep=p;p=p->next;k++}if(!p||k>i)return-1;if(__(2)__)/*第I个元素结点已经是表尾结点,则无需移动*/return0;q=p;while(__(3)__)q=q-﹥next;/*查找表尾并使q指向表尾结点*/__(4)__=p->next;p->next=NULL;__(5)__;return0;}[15分]

    A(1)__){/*查找第I个元素并使指针p指向该结点*/Prep=p;p=p->next;k++}if(!p||k>i)return-1;if(__

    B(2)__)/*第I个元素结点已经是表尾结点,则无需移动*/return0;q=p;while(__

    C(3)__)q=q-﹥next;/*查找表尾并使q指向表尾结点*/__

    D(4)__=p->next;p->next=NULL;__

    E(5)__;return0;}[15分]

  • 3. 试题四(15分,每空3分)阅读下列说明和流程图,将应填入__(n)__的字句写在答题纸的对应栏内。【说明]某单位举办了一场知识竞赛,参加竞赛的选手为300名,依次从1~300进行编号。竞赛时间为9:00~11:00。8道竞赛题目依次从‘A’~‘H’编号,选手可按任意次序答题,每完成一道题目,可立即提交答案。若答题正确(Y),则选择其他题目进行解答,否则,可继续做该题目或选择其他题目进行解答,直至竞赛结束。选手提交答案的情况及判定结果由专人即时录入,录入的数据如下表1所示,对竞赛情况进行统计和排名的结果如表2所示。统计和排名的规则如下:1.若选手X在竞赛时提交的题目P解答正确,2.则解答该题目所用时间如下计算:解答题目P的用时=提交题目P正确的时间-竞赛的开始时间+罚时罚时=提交题目P错误解答的次数×20例如:表1中14号选手在10:27提交了题目A的正确解答,因此该选手正确解答该题目所用时间为87分钟,由于之前的两次提交错误解答,罚时为2×20=40分钟,所以14号选手解答题目A的用时=87+40=127(分钟)。2.已经提交正确答案的题目再次提交时不再计算。3.竞赛结束时,选手的总用时为所有解答正确的题目用时累加所得,解答不正确的题目不计时。4.排名时,完成题目数量多者排名靠前;若完成的题目数相同,则用时少者排名靠前;若完成的题目数和所用时间均相等,则名次相同;完成题目数为0的选手不参加排名。函数voidStatistic()的功能是:读取输入数据,进行统计、排名并输出结果。#defineMAXN300typedefstruct{intno;/*选手编号*/intnum;/*完成的题目数量*/inttime;/*完成题目的总用时*/intd[8];/*d用于记录提交第I个题目错误答案的次数*/inta[8];/*a用于记录第I个题目是否已经提交正确答案*/}Info;【函数】voidStatistic(){charch,pass;intI,j,k,h,m,t,time,MaxIndex;InfoR[MAXN+1];For(I=1;IMaxIndex)MaxIndex=k;}/*while*/for(I=1;I0){if(Rnum!=R[0].num||R[i].time!=R[0]time)k++;R[0]=__(5)__;Printf(“%d:%3d%4d%5d\n”,k,Rno,RnumRtime);}/*if*/}/*Statistic*/[15分]

    A(1){/*录入一名选手提交答案的信息(小时:分钟,选手编号,题目号,是否正确)*/scanf(”%d:%d,%d,%c”,&h,&m,&k,&ch,&pass);if(h==0)break;R[k]no=k;Time=__(1)__;If(isupper(ch))ch=’a’+ch-‘A’;If(pass!=’Y’&&pass!=’Y’){R[k]d[ch-‘a’]++;continue;}If(R[k]a[ch-‘a’]==1)continue;R[k]a[ch-‘a’]=1;R[k]num++;R[k]time+=__

    B(2)__;if(k>MaxIndex)MaxIndex=k;}/*while*/for(I=1;I<MaxIndex;I++){/*选择排序*/for(t=I,j=I+1;j<=MaxIndex;j++)if(R[t]num<R[j]num||__

    C(3)__t=j;)if(__

    D(4)__){R[0]=R[t];R[t]=R[i];R[i]=R[0];}}/*for*/k=1;R[0]=R[1];for(I=1;I0){if(Rnum!=R[0].num||R[i].time!=R[0]time)k++;R[0]=__

    E(5)__;Printf(“%d:%3d%4d%5d\n”,k,Rno,RnumRtime);}/*if*/}/*Statistic*/[15分]

  • 4. 试题五(15分,每空3分)阅读下列说明及VisualBasic程序代码,将应填入__(n)__的字句写在答题纸的对应栏内。【应用说明]某单位举办了一场知识竞赛,参加竞赛的选手为300名,依次从1~300进行编号。竞赛时间为9:00~11:00。8道竞赛题目依次从‘A’~‘H’编号,选手可按任意次序答题,每完成一道题目,可立即提交答案。若答题正确(Y),则选择其他题目进行解答,否则,可继续做该题目或选择其他题目进行解答,直至竞赛结束。选手提交答案的情况及判定结果由专人即时录入,录入数据包括提交答案的时间、选手编号、题目编号(A~H)、是否正确(Y/N)。对竞赛情况进行统计和排名的规则如下:1.若选手X在竞赛时提交的题目P解答正确,则解答该题目所用时间如下计算:解答题目P的用时=提交题目P正确的时间-竞赛的开始时间+罚时罚时=提交题目P错误解答的次数×20例如:表1中14号选手在10:27提交了题目A的正确解答,因此该选手正确解答该题目所用时间为87分钟,由于他在09:37和09:52两次提交了题目A的错误解答,因此罚时为2×20=40分钟,所以14号选手解答题目A的用时=87+40=127(分钟)。2.已经提交正确答案的题目再次提交时不再计算。3.竞赛结束时,选手的总用时为所有解答正确的题目用时累加所得,解答不正确的题目不计时。4.排名时,完成题目数量多者排名靠前;若完成的题目数相同,则用时少者排名靠前;若完成的题目数和所用时间均相等,则名次相同;完成题目数为0的选手不参加排名。本应用程序的运行窗口如下图所示:窗口中的两个文本框为Txt_time和Txt_player,分别用于录入提交答案的时间和选手编号。组合列表框Combol提供题目编号(A~H),录入时从中选择。检查框Chk_yn用于输入解答是否正确信息。当单击“确定”按钮(Cmd_comfirm)时,录入的提交信息加入列表框List1中,排名情况在列表框List2输出。单击“关闭”按钮时退出应用程序。在开发过程中,需要编写的部分程序代码如下:【程序代码]PrivateTypeInfoNoasinteger’选手编号NumasInteger’完成题目数量Timeasinteger’完成题目的总用时D(8)asinteger’d用于记录提交第i个题目错误答案的次数A(8)asBoolean’a用于记录第i个题目是否已经提交正确答案EndtypeDimR(301)asinfo’R[j]用于统计编号为j的选手提交答案的情况DimMaxIndexasInteger’MaxIndex记录提交答案的选手中编号最大者PrivateSubFrom_Load()Fori=1to8Combo1.additemchr(__(1)__)NextCombol.text=combol.list(0):txt_time.text=””:txt_player.text=””Fori=1to300R(i).num=0:R(i).time=0:R(i).no=iForj=1to8R(i).d(j)=0:R(i).a(j)=falseNextj,iEndSubPrivatesubcmd_confirm_click()Dimh,m,k,timeasinteger,ch,pass,s1asstringK=Instr(txt_time.text,”:”):ifk11orh=11andm>0orm>=60thengotoerror1Time=__(2)__’计算答题时间,以分钟为单位Iftxt_plater.text300thengotoerror1Ch=__(3)__Pass=IIf(chk_yn.__(4)__=0,”N”,”Y”)S1=txt_time.text+space(4)+txt_player.textS1=s1+space(10-len(txt_player.text))+ch+space(8)+passList1.additems1K=val(txt_player.text)'k为选手编号R(k).no=k'编号为k的选手的提交信息记录在下标为k的数组元素中Ifk>maxindexthenmaxindex=kM=asc(ch)-asc(“a”)Ifpass”Y”then'编号为k的选手提交第m个题目的解答不正确R(k).d(m)=R(k).d(m)+1ElseifR(k).a(m)truethen'已经提交正确的题目的解答不再计算R(k).a(m)=true:R(k).num=R(k).num+1R(k).time=R(k).time+__(5)__Callstatistic'调用过程statistic进行实时排名和输出EndifExitsubError1:msgbox”录入信息有错误!”,vbOKOnlyEndsub[15分]

    A(1)__)NextCombol.text=combol.list(0):txt_time.text=””:txt_player.text=””Fori=1to300R(i).num=0:R(i).time=0:R(i).no=iForj=1to8R(i).d(j)=0:R(i).a(j)=falseNextj,iEndSubPrivatesubcmd_confirm_click()Dimh,m,k,timeasinteger,ch,pass,s1asstringK=Instr(txt_time.text,”:”):ifk11orh=11andm>0orm>=60thengotoerror1Time=__

    B(2)__’计算答题时间,以分钟为单位Iftxt_plater.text300thengotoerror1Ch=__

    C(3)__Pass=IIf(chk_yn.__

    D(4)__=0,”N”,”Y”)S1=txt_time.text+space(4)+txt_player.textS1=s1+space(10-len(txt_player.text))+ch+space(8)+passList1.additems1K=val(txt_player.text)'k为选手编号R(k).no=k'编号为k的选手的提交信息记录在下标为k的数组元素中Ifk>maxindexthenmaxindex=kM=asc(ch)-asc(“a”)Ifpass”Y”then'编号为k的选手提交第m个题目的解答不正确R(k).d(m)=R(k).d(m)+1ElseifR(k).a(m)truethen'已经提交正确的题目的解答不再计算R(k).a(m)=true:R(k).num=R(k).num+1R(k).time=R(k).time+__

    E(5)__Callstatistic'调用过程statistic进行实时排名和输出EndifExitsubError1:msgbox”录入信息有错误!”,vbOKOnlyEndsub[15分]

  • 5. 第七题(15分,每空3分)阅读以下应用说明及VB部分的程序代码,将应填入__(n)__处的字句写在答题纸的对应栏内【应用说明]设一个简单的“通讯录”存储在一个Access类型的数据库表中,包括姓名、电话和email三个字段。下面的应用程序实现对“通讯录”数据库表中的记录进行增加、删除及修改处理,其运行界面如下:(1)数据控件(data1)与"通讯录"数据库表相连接,用户可通过"》"和"《"按钮指定表中的当前记录。(2)文本框txt_name,txt_phone和txt_email分别与数据库中的姓名、电话和email字段绑定,用于显示当前记录的内容。(3)应用程序启动时,"确定"按钮(cmd_ok)和"取消"按钮(cmd_cancel)不可操作,文本框中显示表中的第一条记录,这时文本框处于不可操作状态。(4)单击"增加"按钮(cmd_add)或"修改"按钮(cmd_modify)后,方可以编辑记录内容,同时增加、删除、修改和退出按钮变为不可操作状态。增加和修改操作需通过确定和取消按钮确认。(5)单击删除按钮(cmd_del)后,弹出对话框,再单击确定按钮,当前记录被删除。【程序代码】privatesubenableop(isenabledasBoolean)txt_name.enabled=isenabled:txt_phone.enabled=isenabledtxt_email.enabled=isenabledcmd_ok.enabled=isenabled:cmd_cancel.enabled=isenabledcmd_add.enabled=notisenabled:cmd_del.enabled=notisenabledcmd_end.enabled=notisenabled:cmd_modify.enabled=notisenabledendsubprivatesubform_load()callenableop(false)detal.refreshifdata1.recordset.recordcount=0thencmd_del.enabled=false:cmd_modify.enabled=__(1)__endifendsubprivatesubcmd_add_click()'单击“增加”按钮的代码callenableop(__(2)__)data1.recordset.addnew'在数据库表中添加一个新记录txt_name.__(3)__endsubprivatesubcmd_del_click()'单击“删除”按钮的代码onerrorgotoerror3ans=msgbox(“确定删除吗?”,vbYesNo+vbInformation,”操作提示!”)if(ans=vbyes)thendata1.recordset.__(4)__data1.recordset.movenextifdata1.recordset.Eofthendata1.refreshendifexitsuberror3:msgboxerr.description,vbokonly,”错误提示!”endsubprivatesubcmd_ok_click()'单击确定按钮的代码onerrorgotoerror1data1.recordset.__(5)__callenableop(false)exitsuberror1:msgboxerr.description,vbokonly,”错误提示!”data1,updatecontrolscallenableop(false)endsub'修改和取消按钮的程序代码略[15分]

    A(1)__endifendsubprivatesubcmd_add_click()'单击“增加”按钮的代码callenableop(__

    B(2)__)data1.recordset.addnew'在数据库表中添加一个新记录txt_name.__

    C(3)__endsubprivatesubcmd_del_click()'单击“删除”按钮的代码onerrorgotoerror3ans=msgbox(“确定删除吗?”,vbYesNo+vbInformation,”操作提示!”)if(ans=vbyes)thendata1.recordset.__

    D(4)__data1.recordset.movenextifdata1.recordset.Eofthendata1.refreshendifexitsuberror3:msgboxerr.description,vbokonly,”错误提示!”endsubprivatesubcmd_ok_click()'单击确定按钮的代码onerrorgotoerror1data1.recordset.__

    E(5)__callenableop(false)exitsuberror1:msgboxerr.description,vbokonly,”错误提示!”data1,updatecontrolscallenableop(false)endsub'修改和取消按钮的程序代码略[15分]

  • 6. 试题一(15分,每空3分)阅读下列说明和流程图,将应填入__(n)__的字句写在答题纸的对应栏内。【流程图说明]下面的流程图描述了对8位二进制整数求补的算法。该算法的计算过程如下:从二进制数的低位(最右位)开始,依次向高位逐位查看,直到首次遇到“1”时,停止查看。然后,对该“1”位左面的更高位(如果有的话),逐位求反,所得的结果就是对原二进制数求补的结果。例如:对二进制整数10101000求补的结果时01011000。设8位二进制整数中的各位,从低位到高位,依次存放在整型数组BIT的BIT[1]~BIT[8]中。例如,二进制整数10101000存放在数组BIT后,就有BIT[1]=0,BIT[2]=0,…,BIT[7]=0,BIT[8]=1。若流程图中存在空操作,则用NOP表示。流程图中__(1)__处按“循环变量名:循环初值,增量,循环终值”格式描述。[15分]

    A(1)__处按“循环变量名:循环初值,增量,循环终值”格式描述。[15分]

  • 7. 试题六(15分,每空3分)阅读以下说明和C++程序,将应填入__(n)__处的字句写在答题纸的对应栏内【说明】以下程序的功能是计算三角形、矩形和正方形的面积并输出。程序由4个类组成:类Triangle,Rectangle和Square分别表示三角形、矩形和正方形;抽象类Finure提供了一个纯虚拟函数getArea(),作为计算上述三种图形面积的通用接口。【C++程序】#include#includeclassFigure{public:virtualdoublegetArea()=0;//纯虚拟函数};classRectangle:__(1)__{protected:doubleheight;doublewidth;public:Rectangle(){};Rectangle(doubleheight,doublewidth){This->height=height;This->width=width;}doublegetarea(){return__(2)__;}};classSquare:__(3)__{public:square(doublewidth){__(4)__;}};classtriangle:__(5)__{doublela;doublelb;doublelc;public:triangle(doublela,doublelb,doublelc){this->la=la;this->lb;this->lc;}doublegetArea(){doubles=(la+lb+lc)/2.0;returnsqrt(s*(s-la)**(s-lb)*(s-lc));}};viodmain(){figure*figures[3]={newtriangle(2,3,3),newRectangle(5,8),newSquare(5)};for(inti=0;igetarea()<<endl;}}};[15分]

    A(1)__{protected:doubleheight;doublewidth;public:Rectangle(){};Rectangle(doubleheight,doublewidth){This->height=height;This->width=width;}doublegetarea(){return__

    B(2)__;}};classSquare:__

    C(3)__{public:square(doublewidth){__

    D(4)__;}};classtriangle:__

    E(5)__{doublela;doublelb;doublelc;public:triangle(doublela,doublelb,doublelc){this->la=la;this->lb;this->lc;}doublegetArea(){doubles=(la+lb+lc)/2.0;returnsqrt(s*(s-la)**(s-lb)*(s-lc));}};viodmain(){figure*figures[3]={newtriangle(2,3,3),newRectangle(5,8),newSquare(5)};for(inti=0;igetarea()<<endl;}}};[15分]

  • 8. 试题八(15分,每空3分)阅读以下说明和Java程序,将应填入__(n)__处的字句写在答题纸的对应栏内【说明】以下程序的功能时三角形、矩形和正方形的面积输出。程序由5个类组成:areatest是主类,类Triangle,Rectangle和Square分别表示三角形、矩形和正方形,抽象类Figure提供了一个计算面积的抽象方法。【程序】publicclassareatest{publicstaticviodmain(stringargs[]){Figure[]Figures={NewTriangle(2,3,3),newrectangle(5,8),newsquare(5)};for(inti=0;i<Figures.length;i++){system.out.println(Figures+”area=”+Figures.getarea());}}}publicabstractclassfigure{publicabstractdoublegetarea();}publicclassrectangleextends__(1)__{doubleheight;doublewidth;publicrectangle(doubleheight,doublewidth){this.height=height;this.width=width;}publicstringtostring(){return”rectangle:height=”+height+”,width=”+width+”:”;}publicdoublegetarea(){return__(2)__}}publicclasssquareexends__(3)__{publicsquare(doublewidth){__(4)__;}publicstringtostring(){return”square:width=”+width”:”;}}publicclassrectangleentend__(5)__{doublela;doublelb;doublelc;publictriangle(doublela,doublelb,doublelc){this.la=la;this.lb=lb;this.lc=lc;}publicstringtostring(){return”triangle:sides=”+la+”,”+lb+”,”+lc+”:”;}publicdoublegetarea(){doubles=(la+lb+lc)/2.0;returnmath.sqrt(s*(s-la)*(s-lb)*(s-lc));}}[15分]

    A(1)__{doubleheight;doublewidth;publicrectangle(doubleheight,doublewidth){this.height=height;this.width=width;}publicstringtostring(){return”rectangle:height=”+height+”,width=”+width+”:”;}publicdoublegetarea(){return__

    B(2)__}}publicclasssquareexends__

    C(3)__{publicsquare(doublewidth){__

    D(5)};for(inti=0;i<Figures.length;i++){system.out.println(Figures+”area=”+Figures.getarea());}}}publicabstractclassfigure{publicabstractdoublegetarea();}publicclassrectangleextends__(1)__{doubleheight;doublewidth;publicrectangle(doubleheight,doublewidth){this.height=height;this.width=width;}publicstringtostring(){return”rectangle:height=”+height+”,width=”+width+”:”;}publicdoublegetarea(){return__(2)__}}publicclasssquareexends__(3)__{publicsquare(doublewidth){__

    E(5)};for(inti=0;i<Figures.length;i++){system.out.println(Figures+”area=”+Figures.getarea());}}}publicabstractclassfigure{publicabstractdoublegetarea();}publicclassrectangleextends__(1)__{doubleheight;doublewidth;publicrectangle(doubleheight,doublewidth){this.height=height;this.width=width;}publicstringtostring(){return”rectangle:height=”+height+”,width=”+width+”:”;}publicdoublegetarea(){return__(2)__}}publicclasssquareexends__(3)__{publicsquare(doublewidth){__(4)__;}publicstringtostring(){return”square:width=”+width”:”;}}publicclassrectangleentend__(5)__{doublela;doublelb;doublelc;publictriangle(doublela,doublelb,doublelc){this.la=la;this.lb=lb;this.lc=lc;}publicstringtostring(){return”triangle:sides=”+la+”,”+lb+”,”+lc+”:”;}publicdoublegetarea(){doubles=(la+lb+lc)/2.0;returnmath.sqrt(s*(s-la)*(s-lb)*(s-lc));}}[15分]

相关试卷
相关题库