I am a teacher!

导航

计算机等级考试二级C语言模拟试卷(二)

一、选择题(每小题1分,共40分)

  (1)下列叙述中,正确的是

  A)线性表的链式存储结构与顺序存储结构所需要的存储空间是相同的

  B)线性表的链式存储结构所需要的存储空间一般要多于顺序存储结构

  C)线性表的链式存储结构所需要的存储空间一般要少于顺序存储结构

  D)上述三种说法都不对

  (2)下列叙述中正确的是

  A)在栈中,栈中元素随栈底指针与栈顶指针的变化而动态变化

  B)在栈中,栈顶指针不变,栈中元素随栈底指针的变化而动态变化

  C)在栈中,栈底指针不变,栈中元素随栈顶指针的变化而动态变化

  D)上述三种说法都不对

  (3)软件测试的目的是

  A)评估软件可靠性                                           B)发现并改正程序中的错误

  C)改正程序中的错误                                            D)发现程序中的错误

  (4)下面描述中,不属于软件危机表现的是

  A)软件过程不规范                                         B)软件开发生产率低

  C)软件质量难以控制                                          D)软件成本不断提高

  (5)软件生命周期是指

  A)软件的开发过程

  B)软件的运行维护过程

  C)软件从需求分析、设计、实现到测试完成的过程

       D)软件产品从提出、实现、使用维护到停止使用退役的过程

       (6)面向对象方法中,继承是指

  A)一组对象所具有的相似性质                  B)一个对象具有另一个对象的性质

  C)各对象之间的共同性质                           D)类之间共享属性和操作的机制

  (7)层次型、网状型和关系型数据库划分原则是

  A)记录长度                                                               B)文件的大小

  C)联系的复杂程度                                                D)数据之间的联系方式

  (8)一个工作人员可以使用多台计算机,而一台计算机可被多个人使用,则实体工作人员与实体计算机之间的联系是

  A)一对一                    B)一对多                             C)多对多                          D)多对一

  (9)数据库设计中反映用户对数据要求的模式是

  A)内模式             B)概念模式                 C)外模式                   D)设计模式

      (10)有三个关系R、S和T如下:

       
  则由关系R和S得到关系T的操作是

  A)自然连接        B)交                               C)投影                       D)并

   (11)下列关于结构化程序设计的叙述中,正确的是

  A)一个结构化程序必须同时由顺序、分支、循环三种结构组成

  B)结构化程序使用goto语句会很便捷

  C)在C语言中,程序的模块化是利用函数实现的

  D)由三种基本结构构成的程序只能解决小规模的问题

  (12)下列关于简单程序设计的步骤和顺序的说法中,正确的是

  A)确定算法后,整理并写出文档,最后进行编码和上机调试

  B)首先确定数据结构,然后确定算法,再编码,并上机调试,最后整理文档

  C)先编码和上机调试,在编码过程中确定算法和数据结构,最后整理文档

  D)先写好文档,再根据文档进行编码和上机调试,最后确定算法和数据结构

  (13)下列叙述中,错误的是

  A)C程序在运行过程中所有计算都以二进制方式进行

  B)C程序在运行过程中所有计算都以十进制方式进行

  C)所有C程序都需要编译链接无误后才能运行

  D)C程序中整型变量只能存放整数,实型变量只能存放浮点数

  (14)有以下定义:int  a; long  b; double  x,y;则以下选项中正确的表达式是

  A)a% (x-y)                                                           B)a=x!=y;

  C)(a*y)%b                                                           D)y=x+y=x

  (15)以下选项中能表示合法常量的是

  A)O115                 B)0118                           C)-5e1.5                     D)115L

       (16)表达式a+=a-=a=9的值是

  A)-9                       B)0                               C)9                              D)18

  (17)若变量已正确定义,在if  (W)  printf(”%d\n,k”);中,以下不可替代W的是

  A)a<>b+c             B)ch=getchar()            C)a==b+c                   D)a++

   (18)有以下程序

  #include  <stdio.h>

  main()

      {

            int  a=1,b=0;

      if(!a) b++;

      else  if(a==0)

            if(a)b+=2;

       else  b+=3;

      printf(”%d\n”,b);

  }

  程序运行后的输出结果是

  A)0                        B)1                                  C)2                              D)3

  (19)若有定义语句int a, b;double x;则下列选项中没有错误的是

  A)switch(x%2)                                   B)switch((int)x/2.0)

     {  case 0: a++; break;                        {  case 0: a++; break;

        case 1: b++; break;                            case 1: b++; break;

        default : a++; b++;                             default : a++; b++;

     }                                                          }

  C)switch((int)x%2)                            D)switch((int)(x)%2)

     {  case 0: a++; break;                        {  case 0.0: a++; break;

        case 1: b++; break;                            case 1.0: b++; break;

        default : a++; b++;                             default : a++; b++;

     }                                                          }

   (20)有以下程序

  #include  <stdio.h>

  main()

     {

int a=1,b=2;

          while(a<6){b+=a;a+=2;b%=10;}

         printf(”%d,%d\n”,a,b);

  }

  程序运行后的输出结果是

  A)6,1                     B)7,1                              C)5,11                        D)7,11

  (21)有以下程序

  #include  <stdio.h>

  main()

     int y=10;

      while(y--);

      printf(”y=%d\n”,y);

  }

  程序执行后的输出结果是

  A)y= -1                  B)y=0                             C)y=9                          D)10

       (22)有以下程序

  #include  <stdio .h>

  main()

     {  

            char  s[]=”abxyz”;

      printf(”%c\n”,*s+2);

  }

  程序运行后的输出结果是

  A)a                        B)c                                  C)x                                      D)xyz

  (23)有以下程序

  #include  <stdio.h>

  #include  <string.h>

  main()

     {

            char  x[]=”STRING”;

      x[0]=’0’;x[1]=’\0’;x[2]=0;

      printf(”%d  %d\n”,sizeof(x),strlen(x));

  }

  程序运行后的输出结果是

  A)6  1                 B)6  3                           C)7  0                       D)7  1

  (24)有以下程序

  #include  <stdio.h>

   int  f(int  x)

  { return  x*2; }

  main()

     {

            int  n=1,m;

      m=f(f(f(n)));

            printf(”%d\n”,m);

  }

  程序运行后的输出结果是

  A)1                        B)2                                  C)4                              D)8

  (25)以下程序段完全正确的是

  A)int  *p;  scanf(”%d”,&p);

  B)int  *p;  scanf(”%d”,p);

  C)int  k, *p=&k;   scanf(”%d”,p);

       D)int  k, *p;    *p= &k;   scanf(”%d”,p);

  (26)有定义语句:int *p[4]; 以下选项中与此语句等价的是

  A)int  p[4];        B)int  **p;                  C)int  *(p[4]);                 D)int  (*p)[4];

  (27)下列定义数组的语句中,正确的是

  A) int  N=10;                      B)#define N 10

      int  x[N];                            int  x[N];

  C) int  x[0..10];                      D)int  x[];

  (28)若要定义一个具有5个元素的整型数组,以下错误的定义语句是

  A)int  a[5]=﹛0﹜;                                                 B)int  b[]={0,0,0,0,0};

  C)int  c[2+3];                                                   D)int  i=5,d[i];

  (29)有以下程序

  #include  <stdio.h>

  void  f(int *p)

  { p=p+3;printf(”%d,”,*p);}

  main()

      {

            int  a[5]={1,2,3,4,5},*r=a;

      f(r);

            printf(”%d\n”;*r);

  }

  程序运行后的输出结果是

  A)1,4                     B) 3,1                             C) 4,1                                 D) 4,4

  (30)有以下程序

        #include  <stdio.h>

        void  fun(int *a,int n)

        {

             int  i,j,k,t;

             for (i=0;i<n-1;i+=2)

            {

                   k=i;

                   for (j=i;j<n;j+=2)

                        if (a[j]>a[k]) k=j;

                    t=a[i]; a[i]=a[k]; a[k]=t;

           }

        }

        void main()

       {

              int aa[10]={1,2,3,4,5,6,7},i;

              fun(aa,7);

              for (i=0;i<7; i++) printf("%d,",aa[i]);

              printf("\n");

       }       

  程序运行后的输出结果是

  A) 1,6,3,4,5,2,7         B) 1,7,3,5,6;2,1      C) 7,2,5,4,3,6,1            D) 7,6,5,4,3,2,1

  (31)下列选项中,能够满足“若字符串s1等于字符串s2,则执行ST”要求的是

  A)if(strcmp(s2,s1)==0) ST;                              B)if(sl==s2) ST;

  C)if(strcpy(s l ,s2)==1) ST;                             D)if(sl-s2==0) ST;

  (32)以下不能将s所指字符串正确复制到t所指存储空间的是

  A)while (*t=*s){t++;s++;}                        B)for (i=0;t[i]=s[i];i++);

  C)do{*t++=*s++;}while(*s);                    D)for (i=0,j=0;t[i++]=s[j++];);

       (33)有以下程序( strcat函数用以连接两个字符串)

  #include  <stdio.h>

  #include  <string.h>

  main()

  {  char a[20]=“ABCD\0EFG\0”,b[]=”IJK”;

        strcat(a,b);  printf(”%s\n”,a);

  }

  程序运行后的输出结果是

  A) IJK                                                                    B) EFGIJK

  C) ABCDIJK                                                         D) ABCDE\0FG\0IJK

  (34)有以下程序

#include  <stdio.h>

void main()

{

    int i,n[]={0,0,0,0,0};

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

    {

           n[i]=n[i-1]*3+1;

           printf("%d  ",n[i]);

    }

}

  程序运行后的输出结果是

  A)0  0  0  0           B)1  4  7  10             C) 1  4  13  40                D)4  7  10  13

  (35)有以下程序

#include  <stdio.h>

void  fun(int x)

{

    if (x/2>1)  fun(x/2);

    printf("%d",x);

void main()

{

    fun(7);

    printf("\n");

}       

  程序运行后的输出结果是

  A)1 3 7                  B) 3 7                         C)7 3                                D) 7 3 1

  (36)有以下程序

  #include  <stdio.h>

  int fun()

  { static  int x=1;

       x+=1;

           return x;

  }

  main()

  {  int  i,s=1;

      for (i=1;i<=5;i++) s+=fun();

      printf(”%d\n”,s);

  }

  程序运行后的输出结果是

  A) 6                       B) 11                          C) 21                                       D)120

  (37)有以下程序

  #inctude  <stdio.h>

  #include  <stdlib.h>

  main()

      {

            int *a,*b,*c;

      a=b=c=(int*)malloc(sizeof(int));

      *a=1;*b=2,*c=3;

      a=b;

      printf(”%d,%d,%d\n”,*a,*b,*c);

  }

  程序运行后的输出结果是

  A) 1,1,3                  B) 1,2,3                     C) 2,2,3                              D) 3,3,3

  (38)有以下程序

  #include  <stdio.h>

  main()

      {

             int  s,t,A=10;double B=6;

        s=sizeof(A);  t=sizeof(B);

        printf(”%d,%d\n”,s,t);

  }

  在Visual Studio 2010平台上编译运行,程序运行后的输出结果是

  A)2,4                    B)4,4                         C)4,8                               D)10,6

  (39)若有以下语句

  typedef  struct  S

  {int g;  char h;}T;

  以下叙述中正确的是

  A)可用S定义结构体变量                           B)可用T定义结构体变量

  C)S是struct类型的变量                         D)T是struct S类型的变量

  (40)有以下程序

  #include  <stdio.h>

  main()

  {   short c=124;

       c=c_______;

       printf(”%d\n”,C);

  }

  若要使程序的运行结果为248,应在下划线处填入的是

        A)>>2                  B)|248                       C)&0248                         D)<<1 

二、程序填空题(18分)

程序通过定义学生结构体数组,存储若干名学生的学号、姓名和三门课的成绩。函数fun的功能是:将存放学生数据的结构体数组,按姓名的字典序(从小到大)排序。

请在下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。

注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!

试题程序:

#include  <stdio.h>
#include  <string.h>
struct student {
  long  sno;
  char  name[10];
  float  score[3];
};
void fun(struct student  a[], int  n)
{
/**********found**********/
 __1__ t;
  int  i, j;
/**********found**********/
  for (i=0; i<__2__; i++)
    for (j=i+1; j<n; j++)
/**********found**********/
      if (strcmp(__3__) > 0)
      {  t = a[i];   a[i] = a[j];  a[j] = t;  }
}
main()
{
  struct student  s[4]={{10001,"ZhangSan", 95, 80, 88},{10002,"LiSi", 85, 70, 78},
                    {10003,"CaoKai", 75, 60, 88}, {10004,"FangFang", 90, 82, 87}};
  int  i, j;
  printf("The original data :\n");
  for (j=0; j<4; j++)
  {  printf("\nNo: %ld  Name: %-8s      Scores:  ",s[j].sno, s[j].name);
     for (i=0; i<3; i++)  printf("%6.2f ", s[j].score[i]);
     printf("\n");
  }
  fun(s, 4);
  printf("The data after sorting : \n");
  for (j=0; j<4; j++)
  {  printf("\nNo: %ld  Name: %-8s      Scores:  ",s[j].sno, s[j].name);
     for (i=0; i<3; i++)  printf("%6.2f ", s[j].score[i]);
     printf("\n");
  }
}

三、程序修改题(18分)

下列给定程序中函数fun的功能是:根据以下公式求π值,并作为函数值返回。

例如,当给指定精度的变量eps输入0.0005时,应输出Pi=3.140578。

π/2=1+1/3+1/3×2/5+1/3×2/5×3/7+1/3×2/5×3/7×4/9+······

请改正程序中的错误,使它能得出正确的结果。

注意:部分源程序在文件MODI1.C中,不得增行或删行,也不得更改的程序的结构!

试题程序:

#include <math.h>
#include <stdio.h>
double fun(double  eps)
{  double  s,t;int  n=1;
   s=0.0;
/************found************/
   t=0;
   while( t>eps)
   {  s+=t;
      t=t * n/(2*n+1);
      n++;
   }
/************found************/
   return(s);
}
main()
{  double  x;
   printf("Please enter a precision: "); scanf("%lf",&x);
   printf("\neps=%lf, Pi=%lf \n",x,fun(x));
}

四、程序设计题

学生的记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组s中。请编写函数fun,其功能是:把指定分数范围内的学生数据放在b所指的数组中,分数范围内的学生人数由函数值返回。

例如,输入的分数是60、69,则应当把分数在60~69的学生数据输出,包含60分和69分的学生数据。主函数中把60放在low中,把69放在heigh中。

注意:部分源程序在文件PROG1.C中。

请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。

试题程序:

#include <stdio.h>
#define N 16
typedef  struct
{  char  num[10];
   int   s;
} STREC;
int  fun( STREC  *a,STREC *b,int l, int h )
{


}
main()
{  STREC  s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
                {"GA001",96},{"GA007",72},{"GA008",64},{"GA006",87},
                {"GA015",85},{"GA013",94},{"GA012",64},{"GA014",91},
                {"GA011",90},{"GA017",64},{"GA018",64},{"GA016",72}};
   STREC  h[N],tt;FILE *out ;
   int  i,j,n,low,heigh,t;
   printf("Enter 2 integer number low & heigh :  ");
   scanf("%d%d", &low,&heigh);
   if ( heigh< low )
   { t=heigh;heigh=low;low=t; }
   n=fun( s,h,low,heigh );
   printf("The student's data between %d--%d :\n",low,heigh);
   for(i=0;i<n; i++)
     printf("%s  %4d\n",h[i].num,h[i].s);
   printf("\n");
   out = fopen("out.dat","w") ;
   n=fun( s,h,80,98 );
   fprintf(out,"%d\n",n);
   for(i=0;i<n-1;i++)
     for(j=i+1;j<n;j++)
       if(h[i].s>h[j].s) {tt=h[i] ;h[i]=h[j]; h[j]=tt;}
   for(i=0;i<n; i++)
     fprintf(out,"%4d\n",h[i].s);
   fprintf(out,"\n");
   fclose(out);
}
一、选择题
( 1)~(10)  : B C D A D  D D C C A
(11)~(20) : C B B B D   B A A C B
(21)~(30) : A B D D C   C B D C C
(31)~(40) : A C C C B   C D C B D
二、程序填空题
    (1) struct student
    (2) n-1
    (3) a[i].name, a[j].name 
三、程序改错题
    (1)  t=1.0;
    (2)  return (2*s);
四、程序设计题
            int i,j=0;
        for (i=0;i<N;i++)
           if (a[i].s>=l && a[i].s<=h)
               b[j++]=a[i];
        return j;
参考答案:

posted on 2022-11-08 06:44  aTeacher  阅读(576)  评论(0编辑  收藏  举报