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

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

阅读以下说明和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;

}


参考答案

更多 “ 阅读以下说明和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;} ” 相关考题
考题 ●试题七阅读以下说明和C++程序,将应填入(n)处的字句写在答题纸的对应栏内。【说明】以下程序的功能是设计一个栈类stackT,并建立一个整数栈。【程序】#includeiostream.h#includestdliB.hconst int Max=20;∥栈大小templateclass Tclass stack{∥栈元素数组T s[Max];∥栈顶下标int top;public:stack(){top=-1;∥栈顶初始化为-1}void push(const T &item);∥item入栈T pop();∥出栈int stackempty()const;∥判断栈是否为空};templateclass Tvoid stackT::push(const T &item){if(top== (1) ){cout"栈满溢出"endl;exit (1) ;}top++;s[top]=item;}templateclass TT stackT::pop(){T temp;if(top== (2) ){cout″栈为空,不能出栈操作″endl;exit (1) ;}temp=s[top];top--;return temp;}templateclass Tint stackT::stackempty()const{return top==-1;}void main(){stackintst;int a[]={1,2,3,4,5 };cout"整数栈"endl;cout"入栈序列:"endl;for(int i=0;i4;i++){couta[i]" ";(3) ;}coutendl"出栈序列:";while( (4) )cout (5) " ";coutendl;}

考题 阅读以下说明和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

考题 阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。【说明】已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:

考题 阅读以下说明及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)处的字名写在的对应栏内。[说明] 以下函数完成求表达式的值,请填空使之完成此功能。float sum ( float x ){ float s=0.0;int sign = 1;(1);for(inti=1;(2); i+ +){t=t*x;s=s+(3);sign = - sign;(4);}

考题 阅读下列程序说明和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…}

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

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

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