| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 666 人关注过本帖
标题:C++程序,求高手指教,不胜感激!!!!!!!!!!
取消只看楼主 加入收藏
loveshuang
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
帖 子:270
专家分:1198
注 册:2010-11-14
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
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;
}
搜索更多相关主题的帖子: 感激 指教 
2010-11-18 16:51
loveshuang
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
帖 子:270
专家分:1198
注 册:2010-11-14
收藏
得分:0 
回复 3楼 laoyang103
谢谢啦!!!
2010-11-18 22:39
loveshuang
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
帖 子:270
专家分:1198
注 册:2010-11-14
收藏
得分:0 
回复 2楼 南国利剑
嗯,,,有违规的错误,呵呵呵。。
2010-11-18 22:39
快速回复:C++程序,求高手指教,不胜感激!!!!!!!!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012704 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved