niusouti.com

阅读下列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

题目

阅读下列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);

}

}


相似考题
更多“阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。 【说明】设单链表的结点类和链表类 ”相关问题
  • 第1题:

    试题三(共 15 分)

    阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。


    正确答案:

  • 第2题:

    阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。

    【C++代码】 #include using namespace std; class invoice{ public: (1){ cout<<"This is the content of the invoice!"<

    答案:
    解析:
    (1) virtual void printInvoice() (2) ticket->printInvoice() (3) Decorator::printInvoice() (4) Decorator::printInvoice() (5) &a
    【解析】

    试题分析
    1.Invoice类下,义虛函数,按类图,函数名是printInvoice
    2.前面定义对象名是ticket,那么在ticket不为空的时候调用函数printInvoice
    3.这部分填写发票的抬头,看类图应该实现函数printInvoice ,Decorator装饰模式使用该方法
    4.这部分是发票的脚注,看类图应该实现函数printlnvoice,Decorator装饰模式使用该方法
    5.FootDecorator a(NULL) ;脚步的装饰参数是a,调用a参数,

  • 第3题:

    阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。
    【说明】
    阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。
    【说明】
    某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种
    类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。






    答案:
    解析:

  • 第4题:

    阅读下列说明和 C ++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 6-1 所示。

    【C++ 代码】#includeusing namespace std;class BrakeBehavior{public:(1) ; /*其余代码省略*/};class LongWheelBrake : public BrakeBehavior{public:void stop(){cout <<"模拟长轮胎刹车痕迹! "<< end1;} /*其余代码省略*/};class ShortWheelBrake : public BrakeBehavior{public:void stop(){cout<"模拟短轮胎刹车痕迹! "<< end1;} /*其余代码省略*/};class Car{protected: (2) wheel;public:void brake(){ (3) ; } /*其余代码省略*/};class ShortWheelCar : public Car{public:ShortWheelCar(BrakeBehavior* behavior){ (4);} /*其余代码省略*/};int main(){BrakeBehavior* brake= new ShortWheelBrake();ShortWheelCar car1(brake):car1. (5) ;return 0;}


    答案:
    解析:
    1. virtual void stop( )=02. BrakeBehavior*3. Wheel->stop( )4. wheel=behavior5. brake( )

  • 第5题:

    阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 某文件管理系统中定义了类OfficeDoc和DocExplorer,当类OfficeDoc发生变化时,类DocExplorer的所有对象都要更新其自身的状态,现采用观察者(Observer)设计模式来实现该需求,所设计的类图如图6-1所示。



    答案:
    解析:
    1: void update()2: Observer3: obs.update()4: Subject5: Attach(this)