填空题

以下程序的功能是;实现一个队列的简单管理,每一个队列结点包括一个学生的基本信息(姓名,数学、物理和英语成绩)。成员函数add()建立一个新结点,并将该结点加入队尾。成员函数remove()从队首取下一个结点,并通过参数将所取结点中的数据返回。成员函数Print()输出队列中各个结点的值。当队列非空时,析构函数~Queue()依次删除队列上的各个结点。
[程序]
#include
#include
class Node{
public:
Node(char nam[],int m,int p,int e)
{strcpy(name,nam);math=m;phy=p;eng=e;}
Node(){}
private:
char name[10]; //姓名
int math,phy,eng; //数学,物理,英语成绩
Node *nextItem;
friend class Queue;
};
class Queue{
public:
Queue(){front=NULL;back=NULL;)
~Queue();
void remove(char *,int &,int &,int &);
void add(char [],int,int,int);
int is_empty(){return back==NULL;}
//输出队列中各个结点的值
void Print()
{
Node *p=front;
while(p){
cout p=p->nextItem;
}
}
private:
Node *front;
Node *back;
};
//Queue的成员remove()实现从队列头取下一个结点,并返回该结点的值
void Queue::remove(char n[],int &m,int &p,int &e)
{
Node *pFront; //指向头结点的临时指针
pFront=front;
strcpy(n,front->name);
m=front->math;p=front->phy;e=front->eng;
() ;
delete pFront;
}
//Queue的函数成员add()实现在队列中增加一个项,即增加一个结点
void Queue::add(char n[],int m,int P,int e)
{
Node *pNew=new Node;
strcpy(pNew->name,n);
pNew->math=m;pNew->phy=p;pNew->eng=e;
pNew->nextItem=NULL;
if(front==NULL) ();
else{
() ;
back=pNew;
}
}
Queue::~Queue()
{
Node *p=front,*q;
while(p!=NULL){
();
delete P;
p=q;
}
}
//主函数完成对各成员函数的简单测试
void main(void)
{
Queue q1;
int m,p,e;
char str[10];
cout<<"输入队列中学生的姓名、数学、物理,英语成绩(以0结束);";
cin>>str>>m>>p>>e;
while(strcmp(str,"O")!=0){
q1.add(str,m,P,e);
cout<<"输入队列中一个项的值(以0结束);";
cin>>str>>m>>p>>e;
}
cout<<"队列中各项为;\n";
q1.Print ();
q1.remove(str,m,p,e);
cout<<"队列中移下项的值为;"<
cout<<"队列中各项为;\n";
q1.Print();
}

【参考答案】

front=front->nextItem;front=back=pNew;back->nextItem=pNew;q=......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)