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

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

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

【说明】

 以下程序的功能是设计一个栈类stack<T>,并建立一个整数栈。

 【程序】

 #include < iostream. h >

 #include < stdlib. h >

 const int Max =20;           //栈大小

 template < class T >

 class stack{              //栈元素数组

 T s[Max];                //栈顶下标

 int top;

 public:

   stack( )

   {

     top =-1;            //栈顶初始化为-1

   }

   void push( const T &item);     //item入栈

   T pop( );              //出栈

   int stackempty( ) const;      //判断栈是否为

 };

 template < class T >

 void stack <T >::push(const T &item)

 {

   if(top==(1))

   {

     cout <<"栈满溢出" <<endl;

     exit(1);

   }

   top ++

   s[top] = item;

 }

 template < class T >

 T stack<T> ::pop()

 {

   T temp;

   if(top==(2))

   {

     cout <<"栈为空,不能出栈操作" < < endl;

     exit(1);

   }

   temp =s[top];

   top --;

   return temp;

 }

 template < class T >

 int stack < T >:: stackempty( ) const

 {    return top == -1;

 {

 void main( )

 {

   stack <int> st;

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

   cout <<"整数栈" <<endl;

   cout <<"入栈序列:" <<endl;

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

   {

     cout <<a[i] <<" ";

      (3);

   }

   cout << endl <<"出栈序列";

   while((4))

   tout<<(5)<<" ";

   cout< < endl;

 }

1

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

【说明】

 将一正整数序列{K1,K2,…,K9}重新排列成一个新的序列,新序列中,比K1小的数都在K1的前面(左面),比K1大的数都在K1的后面(右面),最后调用writeDat()函数的新序列输出到文件out.dat中。

 在程序中已给出了10个序列,每个序列有9个正整数,并存入数组a[10][9]中,分别求出这10个新序列。

 例:序列{6,8,9,1,2,5,4,7,3}

 经重排后成为{3,4,5,2,1,6,8,9,7}

 【函数】

 #include < stdio. h >

 #include < conio. h >

 void jsValue( int a [10] [9] )

 { int i,j,k,n,temp;

   int b[9];

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

   { temp=a[i] [0];

    k=8;n=0;

    for(j=8;j=0;j--)

     { if(temp < a[i] [j]) (1)=a[i][j];

       if(temp >a[i] [j]) (2)=a[i][j];

       if(temp =a[i] [j]) (3)= temp;

     }

     for(j=0;j<9;j++) a[i][j] =b[j];

   }

 }

 void main( )

   int a[10] [9] = {{6,8,9,1,2,5,4,7,3},{3,5,8,9,1,2,6,4,7},

         {8,2,1,9,3,5,4,6,7}, {3,5,1,2,9,8,6,7,4},

         {4,7,8,9,1,2,5,3,6}, {4,7,3,5,1,2,6,8,9},

         {9,1,3,5,8,6,2,4,7}, {2,6,1,9,8,3,5,7,4},

         {5,3,7,9,1,8,2,6,4}, {7,1,3,2,5,8,9,4,6}

   };

   int i,j;

    (4);

   for(i=0;i<10;i++) {

     for(j=0;j<9;j++) {

       printf("%d",a[i] [j] );

       if((5))printf(",");

     }

     printf(" \n" );

   }

   getch( );

 }

1

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

【说明】

 函数DelA_InsB(LinkedList La,LinkedList Lb,int key1,int key2,int len)的功能是:将线性表A中关键码为key1的结点开始的len个结点,按原顺序移至线性表B中关键码为key2的结点之前,若移动成功,则返回0;否则返回-1。线性表的存储结构为带头结点的单链表,La为表A的头指针,Lb为表B的头指针。单链表结点的类型定义为

 typedef struct node {

   int key;

   struct node * next;

 } *LinkedList;

 【函数】

 int DelA_InsB ( LinkedList La, LinkdeList Lb,int key1,int key2,,int len)

 { LinkedList p,q,s,prep,pres;

   int k;

   if( ! La->next || ! Lb-> next ||| en <=0)return-1;

   p = La -> next;prep = La;

   while(p&&p- >key != key1) {  /*查找表A中键值为key1的结点*/

    prep = p;p = p -> next;

   }

   if( ! p) return - 1;     /*在表A中不存在键值为key1的结点*/

   q=p;k=1;

   while(q &&(1))}  /*表A中不存在要被删除的len个结点*/

     (2);k++;

   }

   if( ! q)return -1;      /*表A中不存在要被删除的len个结点*/

   s = Lb -> next;(3);

   while(s && s -> key != key2) { /*查找表B中键值为key2的结点*/

     pres =s;s =s->next;

   }

   if( ! s) return - t;     /*表B中不存在键值为key2的结点*/

   (4)=q-> next;   /*将表A中的len个结点删除*/

   q->next=(5);

   pres -> next = p;       /*将len个结点移至表B */

   return 0;

 }