一起答

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

  • 卷面总分:75分
  • 浏览次数:0
  • 测试费用:免费
  • 答案解析:是
  • 练习次数:8次
  • 作答时间:150分钟
试卷简介
部分试题预览
  1. 阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。

     【说明】

     本程序根据输入的月份数,输出它是哪个季节。

     【代码】

     import java.io.*;

     public class season

     {

       public static void main(String[] args)

       {

         String strln="";

          (1) in=new InputStreamReader(System.in);

         BufferedReader buffln=new BufferedReader(in);

         System.out.print("Please enter a month(1-12):");

         try

         {

           strln=buffln.readLine();//从命令行读入数据

         }catch((2))

         {

           System.out.println(e.toStdng());

         }

         int month=(3)(strln);//将字符串转换成整数型

         int season=0;

         if(month<12 && month>0)

            eseason=((month+10)%12)/3+1;//计算季节的公式

            (4) (season)

           {

            case 1:

               System.out.println("the season is Springl");

               break;

            case 2:

               System.out.println("the season is Summer!");

            case 3:

               System.out.println("the season is Fall!");

            case 4:

               System.out.println("the season is Winter!");

               break;

             (5);

               System.out.println("this is not correct month!");

          }

       }

     }

  2. 阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。

      【说明】

     在矩形类中重载关系运算符“>=”,采用友元,比较的依据是矩形面积的大小。重载算术运算符“+=”,采用成员函数,更新矩形对象的长与宽,分别加上形参矩形的长与宽。重载算术运算符+,利用构造函数,采用友元。

     【代码】

     class Crect

     {

       int length,witdth;

       public;

       CRect(int l,int w){

         length=l;

         width=w;

       }

       friend int operator>=(CRect& r1, CRect& r2)

       {

         return (1)>=(2);//比较面积

       }

       void operator+=(CRect& r){

          (3);//求长

          (4);//求宽

       }

       friend operater+(CRect& r1, CRect& r2){

         return CRect((5)); //利用构造函数

       }

     }

  3. 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

      【说明】

     编写程序,生成一个新文本文件,它由一个已知文本文件的所有偶数行组成。要求已知文本文件名和新文本文件名均从键盘输入。请填空完善程序。

     【C语言程序】

     #include<stdio.h>

     main()

     {

       FILE *oldf,*newf;

       char ch,fname[20];

       int i;

       do{

         printf("Enter name of existed text file to be read:");

         scanf("%s",fname);

         if((oldf=fopen(fname,"r"))==NULL)

           printf("File %s can't open!\n",fname);

       }while(oldf==NULL);

       do{

         printf("Enter mane of new text file to be written:");

         scanf("%s",fname);

         if(((1)==NULL)

           printf("File %s can't open!\n",fname);

       }while((2));

       i=1;

       while(!feof(oldf))

       {

         while((ch=fgetc(oldf))!=(3))

         {

           if(i%2==(4))

           fputc(ch,newf);

         }

         fputc('\n',newf);

          (5);

       }

       fclose(oldf);

       fclose(newf);

     }

  4. 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

      【说明】

     给定函数fun的功能是:将从键盘上输入的每个单词的第一个字母转换为大写字母,输入时各单词必须用空格隔开,用“.”结束输入。

     【函数】

     int fun(char *c,int status)

     {

       if((1)=='')

         return 1;

       else

       {

         if((2)&&(3)&&(4))

           (5)='A'-'a';

         return 0;

       }

     }

     main()

     {

       int flag=1;

       char ch;

       printf("请输入一字符串,用点号结束输入!\n");

       do {

         ch=getchar();

         flag=fun(&ch,flag);

         putchar(ch);

       }while(ch!='.');

       printf("\n");

     }

  5. 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

      【说明】

     设有n个人围坐一圈并按顺时针方向从1到n编号,从第s个人开始进行1到m的报数,报数到第m个人,则此人出圈,再从他的下一个人重新开始1到m的报数,如此进行下去,直到所有的人都出圈为止。

     现要求按出圈次序,每10人一组,给出这n个人的顺序表。

     设n=100,s=1,m=10。

     (1)将1到n个人的序号存入一维数组p中;

     (2)若第i个人报数后出圈,则将p置于数组的倒数第i个位置上,而原来第i+1个至倒数第i个元素依次向前移动一个位置:

     (3)重复第(2)步,直至圈中只剩下p[1]为止。

     #include<stdio.h>

     #define N 100

     #define S 1

     #define M 10

     void main()

     {

       int p[100],n,s,m;

       m=M;

       n=N;

       s=S;

       int i,j,s1,w;

       s1=s;

       for(i=1;(1);i++)

          (2)=i;

       for(i=n;i>=2;i--)

       {

         s1=(3);

         if(s1==0)s1=i;

         w=(4);

         for(j=s1;j<i;j++)

           p[j-1]=p[j];

         p[i-1]=(5);

         printf("%4d",p[i])}

     }

  6. 阅读下列算法说明和算法,将应填入(n)处的语句写在对应栏内。

      【说明】

     本程序可以将字符串s1中出现的所有s2子串替换成s3,形成一个新串,但不破坏字符串s1。

     【代码】

     #include<stdio.h>

     #include<stdlib.h>

     #include<string.h>

     char*replace(char *s1, char *s2,char *s3)

     {  char *p, *q, *r, *s; int |2,|3, i=0;

        |2=strlen(s2);

        |3=strlen(s3);

        p=s1;

        while((p=strstr(p,s2))!=NULL)

        {  i++;  /* 统计s2串出现的次数*/

           (1);

        }

        i=(2);

        s=r=(char*)malloc(i);  /*分配动态内存存放新字符串*/

        p=s1;

        while(1)

        {  q=strstr(p, s2);  /* s2串是否在s1中出现,q是首次出现的位置*/

          if(q!=NULL)

          {  i=q-p;

             (3);

             r+=i;

             (4);

             r+=|3;

             p=q+|2;   /*将指向s1串的指针移到s2子串出现的位置后,

                     为下一次循环做好准备*/

          }

          else    /*q为空,表示剩余的s1串中已经没有s2*/

          {   (5);

             break;    /*终止循环*/

          }

        }

        return(s);    /*返回指向所形成的新串的指针*/

     }

     void main()

     {  char *a="sabcababde", *b="ab", *c="efg", *d;

        d=replace(a, b, c); printf("result=%s\n", d); free(d);

     }