软件水平考试(初级)程序员下午(应用技术)模拟试卷1

0
收藏   分享
  • 卷面总分:75分
  • 试卷类型:模拟考试
  • 测试费用:免费
  • 答案解析:是
  • 练习次数:144次
  • 作答时间:150分钟
试卷简介
试卷预览
1

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。

 【说明】

 设计一个评选优秀教师和学生的程序,其类结构如图6所示。当输入一系列教师或学生的记录后,将优秀学生及教师的姓名列出来。

【程序】

 #include<iostream.h>

 #include<stdio.h>

 enum boolean {False,True}

 class base

 {

   protected:

   char name[8];

   public:

      void getname() {cout<<"姓名:" ;cin>>name; }

     void printname() {cout<<"姓名:"<<name<<endU3

     virtual boolean isgood() =0;

 }

 class student:(1) 

 {

   int num;

   public:

     void getnum()

       cout<<"考试成绩:" cin>>num;

     boolean isgood() {return (2);{

 };

 class teacher:(3) public base

   int num;

   public:

     void getnum()

       cout<<"每年发表论文数:" ;cin>>num;

     boolean isgood() {return (4);}

 };

 void main()

   base* p[50];

   student * pstud;

   teacher * ptech;

   char ch;

   int count =0;

   do

     cout<<"输入教师(t)或学生(s):"

     cin>>ch;

     if(ch =='s')

   {

       pstud = new student;

       pstud ->getname();

       pstud ->getnum();

       p[count ++ ] = pstud;

   }

   else if(ch == 't')

   {

       ptech = newteacher;

       ptech - >getname( )

      ptech ->getnum();

     p[count++]=ptech;

   }

   else

     cout<<"输入错误<<endl;

     cout<<"继续输入码(Y/n)";

     cin>>ch;

   } while(ch == 'y')

   for(int i=0;i<count;i++)

   {

     if((5))  //若为优秀,则输出

     p[i]->printname();

   }

 }

1

阅读以下说明和C代码,将应填入(n)处的字句写在对应栏内

  【说明】

 从文件IN.DAT中读取一篇英文文章存入到字符串数组XX中;请编写程序,其功能是:以行为单位把字符串中所有小写字母。左边的字符串内容移到该串的右边存放,然后把小写字母。删除,余下的字符串内容移到已处理字符串的左边存放。最后把已处理的字符串仍按行重新存入字符串数组XX中,最后调用函数WRITEDAT(),把结果XX输出到文件 OUT5.DAT中。

 例如:原文:You can create an index on any field.

       you have the correct record.

 结果:n any field.Yu can create an index

    rd. yu have the crreet res

 原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。

 【函数】

#include "stdio.h"

 #include "string.h"

 #include "conio.h"

 #include "ctype.h"

 #include "mem.h"

 unsigned char xx[50] [80]

 int maxline=0;

 int readdat(void);

 void writedat(void)

   /*将题目要求的字符串中所有小写字母o左边的字符串内容移到谊串的右边存放,即将串中“最后”一个字母o左右两侧的内容互换*/

  void StrOR(void)

 {

   inti;

   char*p1,* p2,t[80];

   for(i=0;i<maxline;i++)

   {  t[0]='/0';

      p2=xx[i];

      while(*p2)  /*找到最后一个别'o'*/

     {  if((1))p1=p2;

        p2++;

      }

      strcat(t,p1+1);

      *p1='\0';

      strcat(t,xx[i]);

      p1=xx[i];

      p2=t;

      while(*p2)   /*删去字符'o'*/

      {  if((2)) (3)=*p2;

        p2++;

      }

      (4);

   }

 }

 void main()

 {

   clrscr();

   if(readdat())

   {  printf("Can't open the file IN. DAT!\n");

      return;

   }

   StrOR();

   writedat();

 }

 int readdat(void)

 {

   FILE * fp;

   int i=0;

   char * p;

   if((fp=fopen("in.dat","r" ))==NULL)

   return 1;

   while(fgets(xx[i],80, fp)!=NULL)

   {  p=strchr(xx[i],'\n');

      if(p)

      *p=0;

     i++;

     }

     maxline:(5);

     fclose(fp);

     return 0;

   }

   void writedat (void)

   {  FILE * fp;

      int i;

      fp=fopen("in.dat',"w");

      for(i=0;i<maxline;i++)

      {  printf("%s\n",xx[i]);

        fprintf(fp," %s\n",xx[i]);

      }

      fclose(fp);

   }

   }

 }