2020年下半年程序员考试_2004年下半年程序员下午试题及答案

软件试题库 2025-07-30 网络整理 可可

【shitiku.jxxyjl.com--软件试题库】

试题一(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分,每空3分)

  阅读下列说明和流程图,将应填入__(n)__的字句写在答题纸的对应栏内。

  【函数说明】

  函数sort(int a[],int n)的功能时对数组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],则将两者交换;第三趟对偶数下标,第四趟对奇数下标,…,依次类推,直至整个数组元素有序排列为止。

  【函数]

  void sort (int a[],int n)
  {
    int i ,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分,每空3分)

   阅读下列说明和流程图,将应填入__(n)__的字句写在答题纸的对应栏内。

   【函数说明]   函数movetoend(linkedlist la int i)的功能时:将线性表示a的第i个元素移到

表尾。若移动成功,则返回0,否则返回-1。线性表a采用带头结点的单链表表示,la为表a的头指针,如下图所示。

 

  链表结点的类型定义为:

  typedef struct node {    
   int key;
   struct node *next;
  }*linkedlist
  【函数]
  int movetoend(linkedlist la,int i)
  {
   linkedlist p ,q,prep;
   int k=1;
   p=la->next;prep=la;
   while(__(1)__){      /*查找第i个元素并使指针p指向该结点*/
    prep=p; p=->next;k++
   }
   if (!p||k>i)return -1;
   if (__(2)__)        /*第i个元素结点已经是表尾结点,则无需移动*/
   return 0;
   q=p;
   while(__(3)__)q=q-﹥next; /*查找表尾并使q指向表尾结点*/
   __(4)__=p->next;
   p->next=null;
   __(5)__;
   return 0;
  }

从下列的2道试题(试题四至试题五)中任选1道解答。如果解答的试题数超过1道,则号小的1道解答有效。

试题四(15分,每空3分)

  阅读下列说明和流程图,将应填入__(n)__的字句写在答题纸的对应栏内。

  【说明]

  某单位举办了一场知识竞赛,参加竞赛的选手为300名,依次从1~300进行编号。竞赛时间为9:00~11:00。8道竞赛题目依次从‘a’~‘h’编号,选手可按任意次序答题,每完成一道题目,可立即提交答案。若答题正确(y),则选择其他题目进行解答,否则,可继续做该题目或选择其他题目进行解答,直至竞赛结束。

  选手提交答案的情况及判定结果由专人即时录入,录入的数据如下表1所示,对竞赛情况进行统计和排名的结果如表2所示。

表1:输入数据

提交时间

选手编号

题目编号

是否正确

09:37

14

a

n

09:50

8

a

y

09:51

9

b

n

09:52

14

a

n

10:14

5

a

n

10:16

9

b

n

10:23

5

a

y

10:23

8

b

y

10:27

14

a

y

表2:输出结果

名次

选手编号

完成题目数量

总用时(分钟)

1

8

2

133

2

5

1

103

3

14

1

127

  统计和排名的规则如下:

  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的选手不参加排名。 

  函数void statistic()的功能是:读取输入数据,进行统计、排名并输出结果。

  #define maxn 300
  typedef struct {
   int no;          /*选手编号*/
   int num;        /*完成的题目数量*/
   int time;        /*完成题目的总用时*/
   int d[8];        /*d用于记录提交第i个题目错误答案的次数*/
   int a[8];        /*a用于记录第i个题目是否已经提交正确答案*/
  }info;
 【函数】
  void statistic () {
   char ch,pass;
   int i,j,k,h,m,t,time,maxindex;
   info r[maxn+1];
   for(i=1;i<=maxn;i++){         /*数组r的元素置初值0*/
    r no=0; r num=0; r time=0;
    for(j=0;j<8;j++){r.d[j]=0;r.a[j]=0;}
   }/*for*/
   maxindex=0;
   while(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+=__(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 || __(3)__ t=j;)
    if(__(4)__) { r[0]=r[t];r[t]=r;r=r[0];}
   }  /*for*/
   k=1;r[0]=r[1];
   for(i=1;i<=maxindex;i++)                 /*输出排名情况*/
   if(r[i].num>0){ 
    if (r num!=r[0] num || r time!=r[0] time) k++;
    r[0]=__(5)__;
    printf(“%d: %3d %4d %5d ”,k,r no,r num r time);
   } /*if*/
  } /*statistic*/

 

试题五(15分,每空3分)

  阅读下列说明及visual basic程序代码,将应填入__(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输出。单击“关闭”按钮时退出应用程序。

  在开发过程中,需要编写的部分程序代码如下:

  【程序代码]

  private type info
   no as integer   ’选手编号
   num as integer ’完成题目数量
   time as integer ’完成题目的总用时
   d(8) as integer  ’d用于记录提交第i个题目错误答案的次数
   a(8) as boolean ’a用于记录第i个题目是否已经提交正确答案
  end type
  dim r(301) as info  ’r[j]用于统计编号为j的选手提交答案的情况
  dim maxindex as integer ’maxindex记录提交答案的选手中编号最大者

  private sub from_load ()
   for  i=1 to 8
    combo1.additem chr(__(1)__)
   next
   combol.text = combol.list(0):  txt_time .text=””:  txt_player.text=””
   for i=1 to 300
    r(i).num=0:  r(i).time=0: r(i).no=i
    for  j=1 to 8
     r(i).d(j)=0: r(i).a(j)=false
   next j,i
  end sub

  private sub cmd_confirm_click()
   dim h, m,k, time as integer,ch ,pass,s1 as string
   k= instr(txt _time .text,”:”):if k<2 then goto error1
   h=val(left(txt_time.text,k-1)):m=val(mid(txt_time.text,k+1))
   if h>11 or h=11 and m>0 or m>=60 then goto error1
   time =__(2)__  ’计算答题时间,以分钟为单位
   if  txt_plater.text<1 or txt_player .text>300 then goto error1
   ch=  __(3)__ 
   pass=iif(chk_yn.__(4)__ =0,”n”,”y”)
   s1=txt_time.text+space(4)+txt_player.text
   s1=s1+space(10-len(txt_player.text))+ch+space(8)+pass
   list1.additem s1
   k= val(txt_player.text)      "k为选手编号
   r(k).no=k    "编号为k的选手的提交信息记录在下标为k的数组元素中
   if k >maxindex then maxindex=k
   m = asc(ch)-asc(“a”)
   if pass <>”y” then         "编号为k的选手提交第m个题目的解答不正确
    r(k).d(m)=r(k).d(m)+1
   else if r(k).a(m)<>true then  "已经提交正确的题目的解答不再计算
     r(k).a(m)=true:r(k).num=r(k).num+1
     r(k).time=r(k).time +  __(5)__  
     call statistic       "调用过程statistic进行实时排名和输出
   end if
   exit sub
   error1:msgbox”录入信息有错误!”,vbokonly
  end sub

从下列的3道试题(试题六至试题八)中任选1道解答。如果解答的试题数超过1道,则题号小的1道解答有效。

试题六(15分,每空3分)

  阅读以下说明和c++程序,将应填入 __(n)__处的字句写在答题纸的对应栏内

  【说明】

  以下程序的功能是计算三角形、矩形和正方形的面积并输出。

  程序由4个类组成:类triangle,rectangle和square分别表示三角形、矩形和正方形;抽象类finure提供了一个纯虚拟函数getarea(),作为计算上述三种图形面积的通用接口。

  【c++程序】
   #include<iostream.h>
   #include<math.h>

  class figure{
   public:
   virtual double getarea()=0;  //纯虚拟函数
  };

  class rectangle:__(1)__ {
   protected:
   double height;
   double width;
   public:
   rectangle(){};
   rectangle(double height,double width){
    this->height=height;
    this->width=width;
   }
   double getarea(){
    return  __(2)__ ;
   }
  };

  class square:__(3)__ {
   public:
   square(double width){
    __(4)__ ;
   }
  };

  class triangle:__(5)__ {
   double la;
   double lb;
   double lc;
   public:
   triangle(double la ,double lb,double lc){
    this ->la=la;  this->lb;  this->lc;
   }
   double getarea(){
    double s=(la +lb+lc)/2.0;
    return sqrt(s*(s-la)**(s-lb) *(s-lc));
   }
  };

  viod main(){
   figure* figures[3]={
    new triangle(2,3,3),new rectangle(5,8),new square(5)};
    for (int i=0;i<3;i++){
     cout<<”figures[“<<i<<”]area= “<<(figures)->getarea()<<endl;
    }
   }
   }

第七题(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)后,弹出对话框,再单击确定按钮,当前记录被删除。

  【程序代码】

  private sub enableop(isenabled as boolean)
   txt_name.enabled=isenabled :txt _phone.enabled=isenabled
   txt_email.enabled=isenabled
   cmd_ok.enabled= isenabled: cmd_cancel.enabled= isenabled
   cmd_add.enabled= not isenabled: cmd_del.enabled= not isenabled
   cmd_end.enabled= not isenabled: cmd_modify.enabled= not isenabled
  end sub

  private sub form_load()
   call enableop(false)
   detal.refresh
   if data1.recordset.recordcount=0 then
    cmd_del.enabled= false: cmd_modify.enabled= __(1)__
   end if
  end sub

  private sub cmd_add_click()   "单击“增加”按钮的代码
   call enableop( __(2)__ )
   data1.recordset.addnew    "在数据库表中添加一个新记录
   txt_name.__(3)__
  end sub

  private sub cmd_del_click()  "单击“删除”按钮的代码
   on error goto error3
   ans=msgbox(“确定删除吗?”,vbyesno+vbinformation,” 操作提示!”)
   if (ans=vbyes) then
    data1.recordset.__(4)__
    data1.recordset.movenext
    if data1.recordset.eof then data1.refresh
   end if
   exit sub
   error3:
   msgbox err.description,vbokonly,”错误提示!”
  end sub

  private sub cmd_ok_click()    "单击确定按钮的代码
   on error goto error1
   data1.recordset.__(5)__
   call enableop(false)
   exit sub
   error1:
   msgbox err.description,vbokonly,”错误提示!”
   data1,updatecontrols
  call enableop(false)
  end sub
  "修改和取消按钮的程序代码略

试题八(15分,每空3分)

  阅读以下说明和java程序,将应填入__(n)__处的字句写在答题纸的对应栏内

  【说明】

  以下程序的功能时三角形、矩形和正方形的面积输出。

  程序由5个类组成:areatest是主类,类triangle,rectangle和square分别表示三角形、矩形和正方形,抽象类figure提供了一个计算面积的抽象方法。

  【程序】

  public class areatest{
   public static viod main(string args[]){
    figure[]figures={
     new triangle(2,3,3),new rectangle(5,8),new square(5)
    };
    for (int i= 0;i< figures.length;i++){
     system.out.println(figures+”area=”+ figures.getarea());
    }
   }
  }

     public string tostring(){
    return”rectangle: height=”+ height +”, width=”+ width +”:”;
   }
   public double getarea(){
    return  __(2)__  
   }
  }
  public class square exends  __(3)__  
  {
   public square(double width) {
    __(4)__ ;
   }

   public string tostring(){
    return” square:width=”+width”:”;
   }
  }

  public class rectangle  entend  __(5)__  
  {
   double la;
   double lb;
   double lc;
   public triangle(double la ,double lb,double lc){
    this.la=la;  this.lb=lb;  this.lc=lc;
   }
   public string tostring(){
    return” triangle:sides=”+la+”, ”+lb+”, ”+lc+”:”;
   }
   public double get area(){
    double s=(la+lb+lc)/2.0;
    return math.sqrt(s*(s-la) *(s-lb) *(s-lc));
   }
  }

答案

 

试题一      

(1)i:1,1,8
(2)1→sw
(3) 0→bit[i]
(4)nop,或空操作
(5)1→bit[i]

试题二

(1)j%2,及其等价形式
(2)i+=2,及其等价形式
(3)tag>2,或tag==3或tag>=3,及其等价形式
(4)9
(5)45     

试题三

(1)p && k<i,及其等价形式
(2)!p->next,及其等价形式
(3)q->next
(4)prep->next
(5)q->next=p

试题四

(1)(h-9)*60+m,及其等价形式
(2)time + r[k].d[ch-"a"]*20 其中ch-"a"可以表示为ch-97,r[k]可以表示为r[r[k].no]
(3)r[t].num == r[j].num && r[t].time > r[j].time,及其等价形式
(4)t!=i,及其等价形式,表达式的值为真也正确
(5)r[i],及其等价形式

试题五

(1)asc("a")+i-1,或64+i,及其等价形式
(2)(h-9)*60+m,及其等价形式
(3)combol.text
(4)value
(5)time+r(k).d(m)*20 其中m可表示为asc(ch)-asc("a")或asc(ch)-65,k可表示为r(r(k).no)
  
试题六 (c++)

(1)public figure
(2)height*width
(3)public rectangle
(4)this->height=this->width=width
(5)public figure 若填public rectangle只给1分

试题七

(1)false
(2)true
(3)setfocus
(4)delete
(5)update

试题八 (java)

(1)figure
(2)height*width
(3)rectangle
(4)super(width,width)
(5)figure

本文来源:https://shitiku.jxxyjl.com/ruanjianshitiku/49014.html

Copyright @ 2011- 考试题库网 All Rights Reserved. 版权所有

免责声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。

 站长统计