一起答
主观

阅读下列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]; //没有越界提示

 }

参考答案
查看试卷详情
相关试题
  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);

       }

     }

  2. 阅读下列函数说明和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*/

  3. 阅读下列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]; //没有越界提示

     }

  4. 阅读下列说明和流程图,回答问题1至问题3。

      【说明】

     某考务处理系统具有以下功能:

     (1)输入报名单;

     (2)自动编制准考证号;

     (3)输出准考证;

     (4)输入成绩清单;

     (5)输出成绩通知单;

     (6)输出成绩分布表;

     (7)输入合格标准、输出录取通知单;

     (8)试题难度分析,并输出试题难度分析表。

     这里给出了实现上述要求的部分不完整的数据流图,其中部分数据流的组成如下所示。

     报名单=报名号+姓名+通信地址

     考生名册=报名号+准考证号+姓名+通信地址

     成绩册=准考证号+(课程号+成绩)(其中{W}表示W重复多次)

     准考证=报名号+姓名+准考证号

                   

     【问题1】

     指出0层图中可以删去的部分。

     【问题2】

     在加工1子图中将遗漏的数据流添加在答题纸上。

     【问题3】

     加工2子图分解成如图所示的4个子加工及相关的文件(即数据存储)。试在此基础上将相关的DFD成份添加在答题纸上,以完成该加工子图。

      

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

      【说明】

     某公司的用品采购流程如下所述。

     (1)由营业部门提出需求用品清单。

     (2)将需求用品清单交采购部门建立采购采买单据。

     (3)采购部门建立采购采买单据后,交财务部门,向财务部申请款项,预支定金。

     (4)财务部建立应付帐款单据后,核支款项。

     (5)采购部门再收到款项后,进行采买。

     (6)采买完成,执行:

     ①发票核剩余款项交财务部,即由财务部门处理。

     ②用品点交营业部门发放,即由营业部门处理。

     (7)进行财务结算处理,执行:

     ①采购部门:采购单据结案。

     ②财务部门:帐款冲销结案。

     【问题】

     完成下面的UML活动图对象流分析,1~11为活动,设计此采购活动的流程。

     

  6. 阅读下列说明,回答问题1至问题3。

      【说明】

     请设计一个图书馆数据库,此数据库中对每个借阅者保存的读者记录包括:读者号、姓名、地址、性别、年龄、单位。对每本书存有:书号、书名、作者、出版社。对每本书被借出的书存有读者号、借出日期和应还日期。

                        

     【问题1】

     给出E-R图

     【问题2】

     转换成关系模型

     【问题3】

     给其中任何一个表用SQL语句建表。