C++程序,求高手指教,不胜感激!!!!!!!!!!
为什么执行中collegestudent的信息无法输出???#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct information{
string name;
string address;
string IDNO;
string position;
struct information* next;
};
class person{
private:
information* list;
public:
person(){}
person(information* L){list=L;}
void traverse();
void destroy();
~person(){cout<<"析构函数被调用,person类的对象被释放!"<<endl;}
};
void person::traverse()
{
information* p;
cout<<"该组人员的信息为:"<<endl;
while(p)
{
p=list->next;
cout<<left<<setw(10)<<p->name
<<setw(10)<<p->address
<<setw(10)<<p->IDNO
<<setw(10)<<p->position<<endl;
list=list->next;
}
}
void person::destroy()
{
information* p;
while(list)
{
p=list;
list=list->next;
delete p;
}
}
class collegestudent:virtual public person
{
public:
collegestudent(){}
collegestudent(string s1,information* k):person(k){schoolnumber=s1;}
string get1(){return schoolnumber;}
private:
string schoolnumber;
};
class proffessor:virtual public person
{
public:
proffessor(){}
proffessor(string s2){marrycondition=s2;}
proffessor(information* k):person(k){}
string get2(){return marrycondition;}
private:
string marrycondition;
};
class Doctor:public collegestudent,public proffessor
{
public:
Doctor(){}
Doctor (string s1,string s2,information* k):collegestudent(s1,k),proffessor(s2){}
~Doctor(){cout<<"析构函数被调用,Doctor类对象被释放!";}
};
int main()
{
struct information*head1,*head2,*head3,*head4,*p,*q,*r,*s;
int n,i;
cout<<"现在设计第一组person的信息,请输入第一组人的人数:";
cin>>n;
head1=new information();
head1->next=NULL;
cout<<"请输入第一组人的相关信息:"<<endl;
for(i=0;i<n;i++)
{
p=new information;
cout<<"姓名:";
cin>>p->name;
cout<<"地址:";
cin>>p->address;
cout<<"身份证号:";
cin>>p->IDNO;
cout<<"身份:";
cin>>p->position;
p->next=head1->next;
head1->next=p;
cout<<endl;
}
person p1(head1);
p1.traverse();
p1.destroy();
cout<<"现在设计第一组collegestudent的信息,请输入第一组人的人数:";
cin>>n;
head2=new information();
head2->next=NULL;
cout<<"请输入第一组collegestudent的相关信息:"<<endl;
for(i=0;i<n;i++)
{
q=new information;
cout<<"姓名:";
cin>>q->name;
cout<<"地址:";
cin>>q->address;
cout<<"身份证号:";
cin>>q->IDNO;
cout<<"身份:";
cin>>q->position;
q->next=head2->next;
head2->next=q;
cout<<endl;
}
collegestudent p2("0904681325",head2);
p2.traverse();
cout<<"学号:"<<p2.get1();
p2.destroy();
cout<<"现在设计第一组proffessor的信息,请输入第一组人的人数:";
cin>>n;
head3=new information;
head3->next=NULL;
cout<<"请输入第一组proffessor的相关信息:"<<endl;
for(i=0;i<n;i++)
{
r=new information();
cout<<"姓名:";
cin>>r->name;
cout<<"地址:";
cin>>r->address;
cout<<"身份证号:";
cin>>r->IDNO;
cout<<"身份:";
cin>>r->position;
r->next=head3->next;
head3->next=r;
cout<<endl;
}
proffessor p3("未婚");
proffessor p4(head3);
p4.traverse();
cout<<"婚姻状况:"<<p4.get2();
p4.destroy();
cout<<"现在设计第一组Doctor的信息,请输入第一组人的人数:";
cin>>n;
head4=new information();
head4->next=NULL;
cout<<"请输入第一组Doctor的相关信息:"<<endl;
for(i=0;i<n;i++)
{
s=new information;
cout<<"姓名:";
cin>>s->name;;
cout<<"地址:";
cin>>s->address;
cout<<"身份证号:";
cin>>s->IDNO;
cout<<"身份:";
cin>>s->position;
s->next=head4->next;
head4->next=s;
cout<<endl;
}
Doctor p5("0904681326","已婚",head4);
p5.traverse();
cout<<"学号:"<<p5.get1()<<endl;
p5.destroy();
return 0;
}