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

题目内容 (请给出正确答案)
阅读下面程序: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 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;}写出该程序的运行结果:【 】。 ” 相关考题
考题 下列程序段中,A_class的成员函数Variance()可求出两数的平方差,请改写该程序段,把Variance()函数从A_class类中分离出来,用友元函数来实现该函数的功能。class A_class {private:intx,y,t;public:A_class(int i,int j):x(i),y(j) {if(yx){t=x;x=y;y=t;}}intVariance(){return x*x-y*y;}//其它函数从略};void main() {A_classA_obj(3,5);coutResult:A_obj.Variance()endl;}

考题 下列程序的运行结果是【 】。 include class SomeClass { public: SomeClass(int va 下列程序的运行结果是【 】。include <iostream. h>class SomeClass{public:SomeClass(int value) { some_value=value;};void show_data(void) { cout<<data<<"<<~some_value<<endl; };static void set_data(int value) {data=value; }private:static int data;int some_value};int SomeClass::datavoid main(void){SomeClass my_class(1001),your_class(2002);your_class. set_data(4004);my_elass. show_data()}

考题 阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】设单链表的结点类和链表类的定义如下,链表不带有表头结点。请填空:include<iostream.h>include<assert.h>template<class T>class List;template<class T>class ListNOde{friend (1);private:T data;ListNode<T> *link;public:ListNode():link(NULL)()ListNOde(const T item,ListNOde<T>*next=NULL):data(item),link(next){}};template<class T>class List{private:ListNode<T>*first;void createList(T A[],int n,int i,ListNOde<T>*p);void printList(ListNOde<T>*p);public:List();~List();friend ostream operator<<(ostream ost,List<T>L);friend istream operator>>(istream ist,List<T>L);};template<class T>istream operator>>(istream ist,List<T>1){int i,n; ist>>n;T A[n];for(i=0;i<n;i++) (2);createList(A,n,0,first);}template<class T>void List<T>::createList(TA[],int n,int i,ListNOde<T>* p){//私有函数:递归调用建立单链表if(i==n)p=NULL;else{p=new ListNode<T>(A[i]);assert(p !=NULL);createList((3));}}template<class T>ostream operator<<(ostream ost,List<T> L){(4);}template<class T>void List<T>::printList(ostream ost,ListNode<T>*p){if(p!=NULL){ost<<p->data;(5);}}

考题 以下程序的运行结果是______。 include include template class TA 以下程序的运行结果是______。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);

考题 以下程序的执行结果是()。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>:: opetatA.n=aB.a=OC.n=bD.a=b

考题 下面程序的输出结果是()。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.2B.10 18C.10 3.2D.编译出错

考题 程序填空题二: 请在答题框中给出程序中红色下划线处应填入的代码。 #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); }

考题 下列的模板说明中,正确的是()A.template <typename T1, typename T2>B.template <class T1, T2>C.template < T1 class, T2 class >D.template <typename T1; typename T2>

考题 利用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);