软件水平考试(中级)软件设计师下午(应用技术)试题模拟试卷33

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

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

 【说明】下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toString方法输出中心点的值。在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。

 public class Point

 {

   private double xCoordinate;

   private double yCoordinate;

   public Point 0 }

   public Point(ouble x, double y)

   {

     xCoordinate = x;

     yCoordinate = y;

   }

   public String toString()

   {

    return "( + Double.toString(Coordinate)+ ","

        + Double.toString(Coordinate) + ");

   }

   //other methods

 }

 public class Ball

 {

    (1);   //中心点

   private double radius;  //半径

   private String colour;  ///颜色

   public Ball() { }

   public Ball(double xValue, double yValue, double r)// 具有中心点及半径的构造方法

   {

    center=(2);//调用类Point 中的构造方法

    radius = r;

   }

   public Ball(double xValue, double yValue, double r, String c)

      // 具有中心点、半径及颜色的构造方法

   {

    (3);//调用3个参数的构造方法

     colour = c;

   }

   public String toString()

   {

     return "A ball with center" + center, toString() + ", radius"

        + Double.toString(radius) + ", colour" + colour;

   }

   //other methods

 }

 public class MovingBall.  (4) 

 {

   private double speed;

   public MovingBall() { }

   public MovingBall(double xValue, double yValue, double r, String e, double s)

   {

    (5);// 调用父类Ball中具有4个参数的构造方法

    speed = s;

   }

   public String toString( )

   { return super, toString( ) + ", speed "+ Double.toString(speed); }

   //other methods

 }

 public class Tester{

   public static void main(String args[]){

   MovingBall mb = new MovingBall(10,20,40,"green",25);

   System.out.println(mb);

   }

 }

1

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

 【说明】函数int Toplogical(LinkedWDigraph G)的功能是对图G中的顶点进行拓扑排序,并返回关键路径的长度。其中图G表示一个具有n个顶点的AOE一网,图中顶点从1~n依次编号,图G的存储结构采用邻接表表示,其数据类型定义如下:

 typedef struct Gnode{      /*邻接表的表结点类型*/

  int adivex;          /*邻接顶点编号*/

  int weight;          /*弧上的权值*/

  bstmct Gonde*nextare;     /*指示下一个弧的结点*/

 }Gnode;

 typedef struct Adjlist{     /*邻接表的头结点类型*/

  char vdata;          /*顶点的数据信息*/

  struct Gnode*Firstadj;     /*指向邻接表的第1个表结点*/

 }Adjlist;

 typedef struct LinkedWDigraph{  /*图的类型*/

  int n, e;           /*图中顶点个数和边数*/

  struct Adjlist head;      /*指向图中第1个顶点的邻接表的头结点*/

 }LinkedWDigraph;

 【函数】

 int Toplogical(LinkedWDigraph G)

 { Gnode *p;

   int j,w,top=0;

   int *Stack,*ve,*indegree;

   ve=(int *)mallloc(G.n+1)* sizeof(int)};

   indegree=(int *)malloc((G.n+1)*sizeof(int));/*存储网中个顶点的入度*/

   Stack=(int *)malloc((G.n+1)*sizeof(int)); /*存储入度为0的顶点的编号*/

   if(!ve‖!indegree‖!Stack)

     exit(0);

   for(j=1;j<=G.n;j++){

     ve[j]=0; indegree[j]=0;

   }/*for*/

   for(j=1;j<=G.n;j++){     /*求网中各顶点的入度*/

     p=G.head[j].Firstadj;

     while(p){

     (1);  p=p->nextarc;

     }/*while*/

   }/*for*/

   for(i=1;j<=G.n;j++)   /求网中入度为0的顶点并保存其编号*/

   if(!indegree[j]) Stack[++top]=j;

 while(top>0){

  w=(2);

  printf("%c", G.head[w].vdata);

  p=G.head[w].Firstadj;

  while(p){

    (3);

   if(!indegree[p->adjvex])

    Stack[++top]=p->adjvex;

   if( (4) )

    ve[p->adjvex]=ve[w]+p->weight;

   p=p->nextarc;

  }/*while*/

  return (5);

 }/*Toplogical*/

1

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

 【说明】

 C++语言本身不提供对数组下标越界的判断。为了解决这一问题,在程序6中定义了相应的类模板,使得对厂任意类型的二维数组,可以在访问数组元素的同时,对行下标和列下标进行越界判断,并给出相应的提示信息。

 #include<iostream.h>

 template <class T> class Array;

 template <class T> class ArrayBody {

   friend   (1) 

   T* tpBody;

   int iRows, iColumns, iCurrentRow;

   ArrayBody (int iRsz, int iCsz) {

     tpBody =(2) 

     iRows = iRsz; iColumns =iCsz; iCurrentRow =-1;

   }

 public:

   T& operator[] (int j) {

   bool row_error, column_error;

   row_error=column_error=false;

   try{

     if (iCurrentRow < 0 || iCurrentRow >=iRows)

      row_error=true;

     if (j < 0 || j >=iColumns)

      column_error=true;

     if ( row_error==true || column_error == true)

       (3) 

   }

   catch (char) {

     if (row_error==true)

      cerr << "行下标越界[" << iCurrentRow << "] ";

     if (column_error== true )

      cerr << "列下标越界[" <<j << "]";

     cout << "\n";

   }

   return tpBody[iCurrentRow * iColumns +j];

   };

   ~ArrayBody ( ) { delete[] tpBody; }

 };

 template <class T> class Array {

   ArrayBody<T> tBody;

   public:

     ArrayBody<T> & operator[] (int i)  {

       (4) 

       return tBody;

     }

     Array (int iRsz, int iCsz) :(5) {}

 };

 void main()

 { Array<int>a1(10,20);

   Array<double>a2(3,5);

   int b1;

   double b2;

 b1=a1[-5][10];  //有越界提示:行下标越界[-5]

   b1=a1[10][15];  //有越界提示:行下标越界[10]

   b1=a1[1][4]; //没有越界提示

   b2=a2[2][6]; //有越界提示:列下标越界[6]

   b2=s2[10][20];  //有越界提示:行下标越界[10]列下标越界[20]

   b2=a2[1][4]; //没有越界提示

 }