网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

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

【程序1说明】

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

【程序1】

include < iostream. h >

template < class T > class Array2D;

template < class T > class Array2DBody {

friend (1);

T * tempBody;

int iRows, iColumns, iCurrentRow;

Array2DBody(int Rows,int Cols) {

tempBody =(2);

iRows = Rows;

iColumns = Cols;

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( colmnn_error = = true)

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

cout < < "\n";

}

return tempBody[ iCurrentRow * iColumns + j ];

}

~ Array2 DBody ( ) { delete [ ] tempBody; } }; template < class T > class Array2D {

Array2DBody < T > tBody;

public:

Array2DBody < T > & operalor[ ] (int i) {

tBody, iCurreutRow = i;

(4);

Array2D(int Rows,int Cols): (5) {} };

void main( )

{

Array2D <int> al ( 10,20 );

Array2D <double> a2(3,5);

int bl;

double b2;

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

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

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

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

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

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

}


参考答案

更多 “ 阅读下列说明和C++程序,将应填入(n)处的字句写在对应栏内。【程序1说明】程序1中定义了数组的类模板,该模板使得对于任意类型的二维数组,可以在访问数组元素的同时,对行下标和列下标进行越界判断,并给出相应的提示信息(C++语言本身不提供对下标越界的判断)。【程序1】include < iostream. h >template < class T > class Array2D;template < class T > class Array2DBody {friend (1);T * tempBody;int iRows, iColumns, iCurrentRow;Array2DBody(int Rows,int Cols) {tempBody =(2);iRows = Rows;iColumns = Cols;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( colmnn_error = = true)cerr< <"列下标越界[" < <j< <"]";cout < < "\n";}return tempBody[ iCurrentRow * iColumns + j ];}~ Array2 DBody ( ) { delete [ ] tempBody; } }; template < class T > class Array2D {Array2DBody < T > tBody;public:Array2DBody < T > operalor[ ] (int i) {tBody, iCurreutRow = i;(4);Array2D(int Rows,int Cols): (5) {} };void main( ){Array2D <int> al ( 10,20 );Array2D <double> a2(3,5);int bl;double b2;b1=a1[-5][10];//有越界提示:行下标越界[-5]b1=a1[10][15];//有越界提示:行下标越界[10]b1=a1[1][4];//没有越界提示b2=a2[2][6];//有越界提示:列下标越界[6]b2=a2[10][20];//有越界提示:行下标越界[10]列下标越界[20]b2=a2[1][4];//没有越界提示} ” 相关考题
考题 阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】StringEditor类的功能是:已知一个字符串,返回将字符串中的非字母字符都删除后的字符串。public (1) {public static String removeNonLetters( (2) ){StringBuffer aBuffer=(3);char aCharacter;for(int i=0; i<original.length();i++){aCharacter=(4);if(Character.isLetter(aCharacter))aBuffer.append( (5) );}return new String(aBuffer);}}public class StringEditorTester{public static void main(String args[]){String riginal="Hi!, My Name is Mark, 234I think you are my classmate?!!";System.out.println(StringEditor.removeNonLetters(original));}}

考题 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include include 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include < string. h >define Max 1000class Bank{int index;char date [Max] [10]; // 记录交易日iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱int rest[ Max]; // 记录每次交易后余额static iht sum; // 账户累计余额public:Bank( ) {index =0;}void deposit( char d[ ] , int m) //存入交易{strcpy ( date [ index ], d);amount[ index] = m;(1);rest[ index] = sum;index++;}void withdraw (char d[ ], int m) //取出交易{strcpy( date[ index] ,d);(2);(3);rest[ index] = sum;index++;}void display( );};int Bank:: sum = 0;void Bank:: display ( ) //输出流水{int i;printf("日期 存入 取出 余额\n");for (4){printf(" %8s" ,date[i] );if (5)printf(" %6d" , -amount[i] );elseprintf( "%6d ",amount[i] );printf( "% 6d\n" ,rest[i] );} }void main( ){Bank object;object. deposit ( "2006.2.5", 1 00 );object. deposit( "2006.3.2" , 200);object. withdraw( "2006.4.1", 50);object. withdraw( "2006.4.5", 80);object. display ( );}本程序的执行结果如下:日期 存入 取出 余额 2006.2.5 100 1002006.3.2 200 3002006.4.1 50 2502006.4.5 80 170

考题 阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序为求行列式X(5,5)的值S。【Visual Basic代码】Private Function col ( byval x ( 5,5 ) as integer ) as longdim fesult as longdim temp as longdim I as integerdim j as integerdim k as imegerresult = 0for I = to 5(1)for j = 1 to 5if I+j>6 thenk= ( 1+j ) mod 5elsek=1endiftemp=temp*x ( k,j )(2)result=(3)(4)(5)End function

考题 阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回答相应问题。比较下面两段程序的优缺点。①for (i=0; i<N; i++ ){if (condition)//DoSomething…else//DoOtherthing…}②if (condition) {for (i =0; i<N; i++ )//DoSomething}else {for (i=0; i <N; i++ )//DoOtherthing…}

考题 阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。[说明]以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。[JAVA代码]//定义自己的异常类class CCircleException extends Exception{}// 定义类 CCircleclass CCircle{private double radius;public void setRadius ( double r ) (1){if ( r<0 ) {(2)}else(3)}Public void show ( ) {System. out. println ( "area="+3.14*radius*radius );}}public class ciusample{public static void main ( String args[] ){CCircle cir=new CCircle( );(4) {cir. setRadius ( -2.0 )}(5){System. out. println ( e+" throwed" ) ;}cir. show( ) ;}}

考题 ●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

考题 试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

考题 阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。 【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

考题 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 某文件管理系统中定义了类OfficeDoc和DocExplorer,当类OfficeDoc发生变化时,类DocExplorer的所有对象都要更新其自身的状态,现采用观察者(Observer)设计模式来实现该需求,所设计的类图如图6-1所示。

考题 阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。 【说明】 某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种 类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。