下列程序将x、y和z按从小到大的顺序排列,请将下面的函数模板补充完整。 template<class T> void fun (______) { T a; 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; } }
A.T x,T y,T z
B.T x;y;z
C.T &x,T &y,T &z
D.T &x, &y, &z
第1题:
函数模板:template<class T> T add(T x,T y){return x+y;} 下列对add函数的调用不正确的是
A.add<>(1,2)
B.add<int>(1,2)
C.add(1,0,2)
D.add(1.0,2.0)
第2题:
下列函数模板定义中错误的是
A.template<class Q>
B.template<class Q> Q F(Q x){return Q+x;} Q F(Q x){return x+x;}
C.template<class T>
D.template<class T> T F(T x){return x * x;} bool F(T x){return x>1;}
第3题:
类模板template<class T>class x{…},其中,友元函数f对特定类型T(如int),使函数f(x<int>&=成为x<int>模板类的友元,则其说明为( )。
A.friend void f();
B.friend void f(x<T>&=;)
C.friend void A::f()
D.friend void C<T>::f(x<T>&=;)
第4题:
函数模板:template<class T> T add(T x, T y) {return x+y;} 下列对add函数的调用不正确的是
A.add<>(1,2)
B.add<int>(1,2)
C.add(1.0,2)
D.add(1.0,2.0)
第5题:
有如下函数模板的定义: template <class T> T func(T x,T y){ return x*x+y*y;} 在下列对func的调用中不正确的是
A.func(3,5);
B.func<>(3,5);
C.func(3,5.5);
D.func<int>(3,5.5);
第6题:
以下程序的运行结果是______。
include<iostream.h>
include<math.h>
template<class T>
class TAdd//定义类模板TAdd,T为类型
{
Tx,y;
public:
TAdd (Ta,Tb) {x=a,y=b;) //构造函数
Tadd() { retum x+y;}//成员函数
};
void main( )
{
TAdd<int>A (5,6);
第7题:
将下面程序补充完整。
include <iostream>
using namespace std;
class Base{
public:
【 】 fun(){return 0;} //声明虚函数
};
class Derived:public Base{
public:
x,y;
void SetVal(int a,int b){}
int fun(){return x+y;}
};
void 【 】 SetVal(int a,int b){x=a;y=b;} //类Derived成员函数
void main(){
Derived d;
cout<<d.fun()<<endl;
}
第8题:
阅读下面程序:
include <iostream.h>
template <class T>
class TAdd
{
private:
T x, y;
public:
TAdd(T a, T b)
{
x=a;
y=b;
}
T add()
{
return x +y;
}
};
void main( )
{
TAdd<int>a(5,6);
TAdd<double>b(2.4,5.8);
cout<<"s1 ="<<A. add()<<",";
cout<<"s2="<<B, add()<<end1;
}
写出该程序的运行结果:【 】。
第9题:
下面程序的输出结果是( )。 #include<iostream> using namespace std; template<class T> T max(T x,T y) { return(x>= y ? x:y);} template<class T> T max(T x,T y,T z) { T t; t=(x>=y ? x:y); return(t>=z ? t:z); } void main(){ int x = 10,y=18,maxi; float a = 1.2,b = 3.2,c = 2,max2; max1 = max(x,(int)c); max2 = max(a,b,(float)y); cout<<maxi<<endl; cout<<max2<<endl;
A.18 3.2
B.10 18
C.10 3.2
D.编译出错
第10题:
下列程序将x、y和z按从小到大的顺序排列,横线处应添加语句( )。 template<class T> void fun (______) { T a; 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; } }
A.Tx,Ty,Tz
B.Tx;y;z
C.T&x,T&y,T&z
D.T&x,&y,&z
第11题:
下面的函数模板定义中错误的是______ 。
A.template<class Q > QF (Q x){return Q +x;}
B.template<class Q > QF (Q x){returnx/x;}
C.template <class T > T F(T x) {return x*x;}
D.template <class T> bool F (T x) {return x>1;}
第12题:
假设有函数模板定义如下:template< typename T >Max(T a,T b,T&c){c=a+b;}下列选项正确的是()
第13题:
有如下函数模板定义: template<class t> T func(Tx,Ty){return x*x+y*y;} 在下列对func的调用中,错误的是
A.func(3,5);
B.func(3.0,5.5);
C.func(3,5.5);
D.func<int>(3,5.5)
第14题:
下列程序将x、y和z按从小到大的顺序排列,请将下面的函数模板补充完整。
template<class T>
void order( )
{
T al
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;
}
}
第15题:
下面的函数模板定义中错误的是
A.template <class Q> q F(Q x) {return Q+x;}
B.template <class Q> Q F(Q x){return x+x;}
C.template <class T> T F(Tx){return x*x;}
D.template <class T> bool F(Tx){return x>1;}
第16题:
有如下函数模板定义: template <class T> T func(T x, T y){return x*x*y*y;) 在下列对func的调用中,错误的是
A.func(3,5);
B.func(3.0,5.5);
C.func(3,5.5);
D.func<int>(3,5.5);
第17题:
已知程序的结果为1 2 3,请填空。
include<iostream.h>
template<class T>
class A
{
public:
T X, y, z;
void display( ) {cout < < x < < " " < < y < < " " < < z;}
};
void main( )
{
A<int>a1;
_____
_____
_____
a1.display( ) ;
}
第18题:
下列程序将x,y和z按从小到大的顺序排列,请将下面的函数模板补充完整。 template<class T> void fun(______) { T a; 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; } }
A.T x,T y,T z
B.T x;y;z
C.T &x,T &y,T &Z
D.T &x,&y,&z
第19题:
下面的函数模板定义中错误的是( )。
A.template<class Q>
B.template<class Q> QF(Qx){return Q-x;} QF(Qx){return x+x;}
C.template<class T>
D.template<class T> TF(Tx){return x*x;} boolP(Tx){return X>1;)
第20题:
类模板template<class T>class x(…),其中,友元函数f成为从该类模板实例化的每个模板类的友元,则其说明应为( )。
A.friend void f();
B.friend void f(x<T>&)
C.friend void A::f();
D.friend void C<T>::f(x<T>&):
第21题:
下列程序将X、Y和Z按从小到大的顺序排列,横线处应添加语句( )。
第22题:
下列关于函数模板的定义中,合法的是( )。
A.template class <T>T abs(T z) {return z<0 ?-z:z;}
B.template<typename T>T abs(T z) {return z<0 ?-z:z;}
C.template T<class T>abs(T z) {return z<0 ?-z:z;}
D.template T abs(Tz) {return z<0 ?z:z;}
第23题:
假设有函数模板定义如下,下列各选项中正确的是( )。 Template <class T> T Max(T a,T b,T c) { if(a<b) {if(b<c) return c; else return b;} else {if(a<c) return c; else return a;} }
A.float x,y,z;float max;max=Max(x,y,z);
B.float x;int y,z;float max;max=Max(x,y,z);
C.float x;double y,z;float max;max=Max(x,y,z);
D.三个选项都正确
第24题:
Tx,Ty,Tz
Tx;y;z
T&x,T&y,T&z
T&x,&y,&z