niusouti.com

阅读下面程序:include template class TAdd{private:T x, y;public:TAdd(T阅读下面程序: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

题目
阅读下面程序:include template class TAdd{private:T x, y;public:TAdd(T

阅读下面程序:

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;

}

写出该程序的运行结果:【 】。


相似考题
更多“阅读下面程序:include <iostream.h>template <class T>class TAdd{private:T x, y;public:TAdd(T ”相关问题
  • 第1题:

    以下程序的执行结果是()。includetemplateclass Sample{ T n;Public: Samp

    以下程序的执行结果是( )。 #include<iostream.h> template<class T> class Sample { T n; Public: Sample (T i){n=i;) void operator ++(); void disp() {cout<<"n="<<n<<endl;} }; template<class T> void Sample<T>:: opetat

    A.n=a

    B.a=O

    C.n=b

    D.a=b


    正确答案:C

  • 第2题:

    程序填空题二: 请在答题框中给出程序中红色下划线处应填入的代码。 #include<iostream> using namespace std; template<class T> class A{ private: T x; public: A(T _x); }; ________________________________:x(_x) { cout<<"调用构造函数"<<endl; } int main() { A<int> obj(0); }


    第一空: ByValmAsInteger,ByValnAsInteger 第二空: gcd=n 第三空: gcd(n,p)=1

  • 第3题:

    利用TAdd模板类实现两个整数5和6的求和运算,则对象A的定义形式是() # include <iostream.h> # include <math.h> template <class T> class TAdd { T x,y; public: TAdd(T a,T b) { x=a,y=b;} T add() { return x+y;} }; void main() { cout << "s1=" << A.add() << endl; }

    A.TAdd<int> A(5,6);

    B.TAdd A(5,6);

    C.TAdd int A(5,6);

    D.int TAdd A(5,6);


    D

  • 第4题:

    下面程序的输出结果是()。includeusing namespace std;templateT max(T x,T

    下面程序的输出结果是( )。 #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.编译出错


    正确答案:B
    解析:本道题考查函数模板以及函数模板重载的使用,max1=max(x,(int)c)语句会实例化Tmax(Tx,Ty)函数模板,返回两个int数据中的最大值;max2=max(a,b,(float)y);语句会实例化Tmax(Tx,Ty,T2)函数模板,返回3个float数据中的最大值。

  • 第5题:

    下列的模板说明中,正确的是()

    A.template <typename T1, typename T2>

    B.template <class T1, T2>

    C.template < T1 class, T2 class >

    D.template <typename T1; typename T2>


    【审题分析】(1)主要考查表结构的创建和主要的设置方法。(2)王要考查字段属性中“有效性规则”和有效文本设置,这里还涉及及关于“日期”、“时间”函数的使用。涉及的函数有dataserial0,,ear(1,date0。(3)主要考查表结构中主键的设置方法和主键字段分析方法。(4)主要考查默认字段的设置。是、否型的逻辑值。是:1,否:0,以及“掩码”的设置方法。(5)和(2)相同,主要是有效文本的设置。(6)考查表记录的添加。 【操作步骤】 步骤1:双击“sampl.mdb”数据库,单击“表”对象,双击“使用设计器创建表”。在表设计窗口中,输入字段名“编号”对应类型选择“文本”,修改“字段大小”为“5”。逐一输入字段选择对应的类型,修改字段的大小。 步骤2:单击“保存”按钮,保存输入“tTeaeher”表名。单击+确定”按钮,关闭设计视图。