模拟试题

3773考试网计算机等级考试模拟试题正文

计算机等级考试二级C++模拟试题二及参考答案(上机)

来源:fjzsksw.com 2010-1-27 16:35:48

 

  三、综合应用题

  使用VC6打开考生文件夹下的工程kt6_3,此工程包含一个源程序文件kt6_3.cpp,其中定义了用于表示考生的类Student,请按要求完成下列操作,将程序补充完整。

  (1)定义私有数据成员code、english分别用于表示考生的编号、英语成绩、它们都是int型的数据。请在注释“//**1**”之后添加适当的语句。

  (2)完成成员函数voidStudent::inputinformation()的定义,该函数用于用户输入一个考生对象的信息,输入格式如下所示:

  输入编号:

  英语成绩:

  计算机成绩:

  请在注释“//**2**”之后添加适当的语句。

  (3)利用已实现的类Student的成员函数,完成函数voidfirstname(Student*A[],intnum)的定义,该函数根据考生信息A[],输出num个考生中总分最高者的编号及其相应的总分,在此不考虑总分相同的情况。请在注释“//**3**”之后添加适当的语句。

  注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。

  源程序文件kt6_3.cpp清单如下:

  #include

  classStudent

  {//**1**

  intcomputer;

  inttotal;

  public:

  voidgetinformation();

  voidcomputesum();

  intgetcode();

  intgettotalscore();

  ~Student();};

  voidStudent::getinformation()

  {//**2**

  cout<<"英语成绩:";

  cin>>english;

  cout<<"计算机成绩:";

  cin>>computer;}

  voidStudent::computesum()

  {total=english+computer;

  cout<<"编号"<

  intStudent::getcode()

  {returncode;}

  intStudent::gettotalscore()

  {returntotal;}

  voidfirstname(Student*A[],intnum)

  {

  //**3**

  tempsum=(*A[0]).gettotalscore();

  for(inti=1;i

  {

  if(((*A[i]).gettotalscore())>tempsum)

  {tempcode=(*A[i]).getcode();

  tempsum=(*A[i]).gettotalscore();}

  }

  cout<<"总分最高者--"<

  }

  voidmain()

  {Student*A[3];

  inti,n=3;

  for(i=0;i

  {A[i]=newStudent;

  A[i]->getinformation();}

  for(i=0;i

  {A[i]->computesum();}

  firstname(A,3);}

  【参考答案】

  (1)int code;

  int english;

  (2)cout<<"输入编号:";

  cin>>code;

  (3)int tempcode,tempsum;

  tempcode=(*A[0]).getcode();

  【试题解析】

  本题是对C++程序设计的综合考查,其设计类的成员及成员函数的定义与调用,数据的输入输出,for循环语句,if条件判断语句等多个知识点,其中(3)中为指针数组的使用,指针数组是一组指针,每一个成员都按照指针的操作规则,但是整个访问规则仍然使用数组下标方式,如A[0]指的是第一个指针,而* A[0]是取出第一个指针指向的内容。

 

上一页  [1] [2] [3] 

触屏版 电脑版
3773考试网 琼ICP备12003406号-1