程序员考试试题及答案|2004年下半年程序员试题及答案(下午)2

计算机技术 2021-01-15 网络整理 可可

【shitiku.jxxyjl.com--计算机技术】

 

  窗口中的两个文本框为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;  file://纯虚拟函数
  };

  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 abstract class figure{
   public  abstract  double  getarea();
  }
  public  class rectangle  extends  __(1)__  {
   double height;
   double width;
   public rectangle  (double height, double width){
    this.height= height;
    this. width = width;
   }
   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/jisuanjijishu/950.html

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

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

 站长统计