cout <<_________<< endl ;
}
50.下列程序?qū),y,z按從小到大的順序排列并將結(jié)果返回給實(shí)參,在橫線處填入正確的內(nèi)容。
template < class T >
void order(_________)
{
_________;
if(x >y) {a =x;x =y;y =a;}
if(y >z) {a =y;y =z;z =a;}
if(x >y) {a =x;x =y;y =a;}
}
五、程序分析題(本大題共2小題,每小題5分,共10分)
51.給出下面程序的輸出結(jié)果
#include < iostream >
using namespace std;
template < class T >
T F(T x)
{
return x > 5;
}
void main( )
{
int a = 15;
cout << F(a) << " \n";
double b = - 5.8976;
cout << F(b) << " \n";
cout << F(5) <<" \n";
}
52.給出下面程序的輸出結(jié)果
#include < iostream >
using namespace std;
class A
{
private: int X, Y;
public : A ( int myx, int myy) { X = myx; Y = myy ;}
void show ( ) { cout << "X =" << X << " Y = " << Y << endl;}
};
class B : public A
{
private : int H, W;
public: B ( int myx, int myy, int myh, int myw) : A ( myx, myy) [ H = myh ; W = myw;}
void show ( ) { cout << "H = " << H << " ; W = " << W << endl; }
};
void main( )
{
B d(1,2,3,4) ;
d. show ( ) ;
}
六、程序設(shè)計(jì)題(本大題共1小題,共10分)
53.定義隊(duì)列類模板queue(先進(jìn)先出),隊(duì)列的大小由使用者確定。要求該類模板對(duì)外提供如下二種基本操作:(1)insert(入隊(duì)列)(2)front(出隊(duì)列),用數(shù)組來(lái)實(shí)現(xiàn)
#include < iostream >
using namespace std;
template < class T, int size >
class queue {
T x [ size ] ;
int current, front, rear;
public :
queue ( ) { current = 0 ; front = 0 ; rear = 0 ;}
. . . .insert(. . . .);
. . . .front(. . . .);
};
請(qǐng)寫出兩個(gè)函數(shù)的過(guò)程(如果需要形式參數(shù),請(qǐng)給出形參類型和數(shù)量,以及返回值類型)