网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
若有类T说明class T{inti;friend void fFriend(T&,int);};,则函数fFriend的错误定义是()
- A、void fFriend(T &objT,int k){objT.i=k;}
- B、void fFriend(T &objT,int k){k=objT.i;}
- C、void T::fFriend(T &objT,int k){k+=objT.i;}
- D、void fFriend(T &objT,int k){objT.i+=k;}
参考答案
更多 “若有类T说明class T{inti;friend void fFriend(T,int);};,则函数fFriend的错误定义是()A、void fFriend(T objT,int k){objT.i=k;}B、void fFriend(T objT,int k){k=objT.i;}C、void T::fFriend(T objT,int k){k+=objT.i;}D、void fFriend(T objT,int k){objT.i+=k;}” 相关考题
考题
请将下列模板类Data补充完整。 template class Data{ public: void put(T v){va
请将下列模板类Data补充完整。template <typename T>class Data{public:void put(T v){val=v;}______get( ){return val;} //返回数据成员val的值,返回类型不加转换private:T val;};
考题
试题八(共15分)阅读以下说明和Java程序代码,将应填入(n) 处的字句写在答题纸的对应栏内。[说明]在下面的 Java 程序代码中,类SalesTicket 能够完成打印票据正文的功能,类HeadDecorator 与FootDecorator 分别完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!------------------------这是票据的台头!这是票据的脚注![Java程序代码]public class SalesTicket {public void printTicket() {System.out.println("这是票据正文!");}}public class Decorator extends SalesTicket{SalesTicket ticket;}}public class FootDecorator extends Decorator{public FootDecorator(SalesTicket t) {(2) ;}public void printTicket() {super.printTicket();System.out.println("这是票据的脚注!");}}public class Main {public static void main(String[] args) {T = new HeadDecorator( (3) );T. (4) ;System.out.println("------------------------");T = new FootDecorator( (5) );T.printTicket();}}public Decorator(SalesTicket t){ticket = t;}public void printTicket(){if(ticket != null)ticket.printTicket();}}public class HeadDecorator extends Decorator{public HeadDecorator(SalesTicket t) {(1) ;}public void printTicket() {System.out.println("这是票据的台头!");super.printTicket();
考题
设有以下类的定义:class Ex{ int x;public:void setx(int t=0);};若在类外定义成员函数setx( ),以下定义形式中正确的是A.void setx(int t){…}B.void Ex::setx(int t){…}C.Ex::void setx(int t){…}D.void Ex::setx( ){…}
考题
下面程序段的输出结果是______。 class Test{ public static void main(String args[ ]){ MyThread t=new MyThread( ); t.displayOutput("t has been created"); t.start( ); } } class MyThread extends Thread{ public void display Output(String s){ System.out,println(s); } public void run( ){ displayOutput("t is running"); } }A.t has been created t is runningB.t has been createdC.t is runningD.编译错误
考题
已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?()
A.t.fB.this.nC.Test.mD.Test.n
考题
为使下列程序的正确输出结果为: Now is 2004-7-6 12:12:12 那么应该在程序划线处填入的语句是( )。 #include <iostream> using namespace std; class TIME; class DATE { public: DATE(int y=2004,int m=1,int d=1) { year=y; month=m; day=d; } void DateTime(TIME t); private: int year,month, day; }; class TIME { public: TIME(int h=0,int m=0,int s=0) { hour=h; minute=m; second=s; } ______________; //将类 DATE 中成员函数 DateTime 声明为类 TIME 的友元函数 private: int hour,minute, second; }; void DATE: :DateTime(TIME t) { cout<<"Now is "<<year<<'-'<<month<<'-'<<day<< ' '<<t.hour<<":"<<t.minute<<': '<<t.seoond<<'.'<<end1; } int main ( ) { DATE d(2004,7,6); TIME t (12, 12, 12); d. DateTime (t); return 0; }A.friend void DateTime(TIME t);B.friend void DATE::DateTime(TIME 0;C.void DateTime(TIME t);D.friend void DateTime(TIME t);
考题
类clasg one在声明func成员函数时发生错误,出错原因是______。class oneprivate:int a;public:void func(two);};class two{private:int b;friend vold one::func(two);};void one::func(twor){a=r.b;}
考题
下列程序中声明了两个类AA和BB,其中函数“print”是类AA的成员函数,但是类BB的友元函数。请在①、②和⑧处各填入正确的内容,使程序能正常运行。include<iostream.h>【 】;class AA{int t;public:AA(int x){t=x;}void print(BB b) ;};class BB{int s;public:BB(int y){s=y;}friend void 【 】 print(BB );};void 【 】{ cout<<"AA:"<<t<<"BB: "<<w.s<<end1;}<void main(){AA m(6);BB n(8);m.print(n);}输出结果为:AA:6;BB:8
考题
阅读下列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);}}
考题
类模板templateclass x{...},其中,友元函数f对特定类型T(如int),使函数 f(x);成为
类模板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<D:: f(x<T>);
考题
为了使程序的输出的正确结果为: Now is 2004.7.10 10:10:10. 那么应在下列程序划线处填入的正确语句是( )。 那么应在下列程序划线处填入的正确语句是( )。 #include <iostream> using namespace std; class TIME; class DATE { public: DATE(int y=2004,int m=1,int d=1) { year=y; month=m; day=d; } friend void DateTime(DATE d, TIME t); private: int year, month, day; }; class TIME { public: TIME(iht h=0, int m=0,int s=0) { hour=h; minute=m; second=s; } friend void DateTime(DATE d,TIME t); private: int hour,minute, second; }; ______________________ //函数 DateTime 的首部 { cout<<"Now is"<<d.year<<'.'<<d.month<<'.'<<d.day<< ' '<<t.hour<<":"<<t.minute<<':'<<t.second<<'.'<<end1; } int main ( ) { DATE d(2004,7,10); TIME t(10, 10, 10); DateTime(d,t); return 0; }A.void DateTime(DATE d,TIME t)B.void TIME::DateTime(DATE d,TIME t) constC.friend void DateTime(DATE d,TIME t)D.void DATE::DateTime(DATE d,TIME t)
考题
已知有下列类的说明,则下列哪个语句是正确的?public class Test { private float f=1.0f; int m=12; static int n=1; public static void main(String arg[]) { Test t= new Test(); }}A.t.f;B.this. nC.Test.m;D.Test.f;
考题
类模板templateclass x{…},其中,友元函数f对特定类型T(如int),使函数f(x=成
类模板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>=;)
考题
若要把函数void f()定义为aClass的友元函数,则应该在类aClass的定义中加入的语句是( )。A.void f();B.static voidf();C.friend f();D.friend void f();
考题
类模板templateclass x{…},其中友元函数f对特定类型T(如int),使函数f(x)成为x
类模板template<class T>class x{…},其中友元函数f对特定类型T(如int),使函数f(x<int>)成为x<int>模板类的友元,则其说明为( )。A.friend voidf();B.friend voidf(x<T>);C.friend voidA::f();D.friend void C<T>::f(x<T>);
考题
以下程序的执行结果是()。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
考题
类模板templateclass x(…),其中,友元函数f成为从该类模板实例化的每个模板类的友元,则
类模板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>):
考题
类class one 在声明func 成员函数时发生错误,出错原因是【 】。Class one{private:int a;public:void func(two )};class two{private:int b;friend void one: :func(two );};void one: : func(two r)a=r.b;}
考题
以下程序的执行结果是()。includetemplateclass Sample{T n:public:Sample
以下程序的执行结果是( )。 #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>::operator++() { n+=1; // 不能用n++, 因为double型不能用++ } void main() { Sample<char>s('a'); s++; s.disp(); }A.n=aB.a=0C.n=bD.a=b
考题
试题五(共15分)阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰( Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】include iostreamusing namespace std;class invoice{public:(1) {cout《 This is the content of the invoice!《 endl;}};class Decorator : public invoice {Invoice *ticket;public:Decorator(lnvoice *t) { ticket = t; }void printinvoice(){if(ticket != NULL)(2);}};class HeadDecorator : public Decorator{public:HeadDecorator(lnvoice*t): Decorator(t) { }void printinvoice0 {cout《 This is the header of the invoice! endl;(3) ;}};class FootDecorator : public Decorator{public:FootDecorator(invoice *t): Decorator(t) { }void printlnvoice() {(4) ;cout《 This is the footnote of the invoice!《 endl;}};int main(void) {Invoice t;FootDecorator f(t);HeadDecorator h(f);H.printlnvoice();cout “_____” endl;FootDecorator a(NULL);HeadDecorator b( (5) );B.printinvoice();return 0;}程序的输出结果为:This is the header of the invoice!This is the content of the invoice!This is the footnote of the invoice!----------------------------This is the header of the invoice!This is the footnote of the invoice!
考题
试题六(共15分)阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰( Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。【java代码】class invoice{public void printInvoice(){:System.out.println ( This is the content of the invoice!);}}class Decorator : extends Invoice {protected Invoice ticket;public Decorator(lnvoice t){ticket = t;}public void printinvoice(){if(ticket != NULL)(1);}}class FootDecorator extends Decorator{public FootDecorator(lnvoice t){super(t);}public void printinvoice (){Systent.out.println( This is the header of the invoice! );(2) ;}}class FootDecorator extends Decorator {public FootDecorator(invoice t):{super(t);}public void printlnvoice(){(3) ;Systent.out.println( This is the header of the invoice! );}}Class test {public static void main(string[] args){Invoice t =new invioce();Invoice ticket;Ticket= (4) ;Ticket. Printinvoice();Systent.out.println(“--------------“)Ticket= (5) ;Ticket. Printinvoice();}}程序的输出结果为:This is the header of the invoice!This is the content of the invoice!This is the footnote of the invoice!----------------------------This is the header of the invoice!This is the footnote of the invoice!
考题
阅读以下说明和C++程序代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】在下面的C++代码中,类SalesTicket能够完成打印票据正文的功能,类HeadDec- orator与FootDecorator分别能够完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!---------------这是票据的台头!这是票据的脚注!【C++程序代码】#includeusing namespace std;class SalesTicket {public:(1) printTicket() { cout " 是票据正文!" endl;}class Decorator : public SalesTicket{SalesTicket *ticket;public:Decorator(SalesTicket *t){ ticket = t; }void printTicket(){if(ticket != NULL)ticket->printTicket();}};class HeadDecorator : public Decorator{public:HeadDecorator(SalesTicket *t): (2) { }void printTicket() {sour "这是票据的台头!" endl;Decorator::printTicket();}};class FootDecorator :public Decorator{public:FootDecorator(SalesTicket *t): (3)void printTicket() {Decorator::printTicket();cout "这是票据的脚注!" endl;}};void main(void) {SalesTicket t;FootDecorator f(t);HeadDecorator h( (4) );h.printTicket();cout "-------------------------" endl;FootDecorator a(NULL);HeadDecorator b( (5) );b.printTicket();}
考题
阅读下列说明和java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。
【java代码】
class invoice{
public void printInvoice( ){
System.out.println ( "This is the content of the invoice!");
}
}
class Decorator extends Invoice {
protected Invoice ticket;
public Decorator(lnvoice t){
ticket = t;
}
public
void printInvoice( ){
if(ticket != null)
(1) ;
}
}
class HeadDecorator extends Decorator{
public HeadDecorator(lnvoice t){
super(t);
}
public void printInvoice ( ){
Systent.out.println( "This is the header of the invoice! ");
(2) ;
}
}
class FootDecorator extends Decorator {
public FootDecorator(Invoice t){
super(t);
}
public void printlnvoice( ){
( 3) ;
Systent.out.println( "This is the footnote of the invoice! ");
}
}
Class test {
public static void main(String[] args){
Invoice t =new Invioce( );
Invoice ticket;
ticket= (4) ;
ticket.printInvoice( );
Systent.out.println(“------------------“);
ticket= (5) ;
ticket.printInvoice( );
}
}
程序的输出结果为:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
考题
阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰( Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。
【C++代码】
#include
using
namespace std;
class Invoice{
public:
(1) {
coutinvoice!" }
};
class
Decorator : public Invoice {
Invoice *ticket;
public:
Decorator(lnvoice *t) { ticket = t; }
void printInvoice( ){
if(ticket != NULL)
(2);
}
};
class
HeadDecorator : public Decorator{
public:
HeadDecorator(lnvoice*t): Decorator(t) { }
void printInvoice( ) {
coutheader of the invoice! " (3) ;
}
};
class FootDecorator : public Decorator{
public:
FootDecorator(Invoice *t): Decorator(t) { }
void printlnvoice( ){
(4) ;
coutfootnote of the invoice!" }
};
int main(void)
{
Invoice t;
FootDecorator f(
HeadDecorator h(
h.printInvoice( );
cout FootDecorator a(NULL) ;
HeadDecorator b( (5) );
b.printInvoice( );
return 0;
}
程序的输出结果为:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
考题
若有类Z说明class Z{staticint a;public:static void fStatic(Z);};int Z::a=0;Z objZ;,则函数fStatic中访问数据a错误的是()。A、void Z::fStatic(){obj Z.a=1;}B、void Z::fStatic(){a=1;}C、void Z::fStatic(){this-a=0;}D、void Z::fStatic(){Z::a=0;}
考题
若有类W说明class W{int a;public:voidfConst(int)const;};,则函数fConst的正确定义是()A、void W::fConst(intk)const{k=a;}B、void W::fConst(intk)const{k=a++;}C、void W::fConst(intk)const{cina;}D、void W::fConst(intk)const{a=k;}
考题
单选题若有类T说明class T{inti;friend void fFriend(T,int);};,则函数fFriend的错误定义是()A
void fFriend(T objT,int k){objT.i=k;}B
void fFriend(T objT,int k){k=objT.i;}C
void T::fFriend(T objT,int k){k+=objT.i;}D
void fFriend(T objT,int k){objT.i+=k;}
热门标签
最新试卷