2015.5.26

来源:互联网 发布:聚宝盆营销软件 编辑:程序博客网 时间:2024/05/15 08:45
<img src="http://img.blog.csdn.net/20150602175721050?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamlqaWNodWNodQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /><img src="http://img.blog.csdn.net/20150602175609121?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamlqaWNodWNodQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />#include<stdio.h>                                                                                                                                                                                                                                                                                   #include <iostream>#include<string>using namespace std;class student{public:        string name;  string num;  string duixiang;  student(string n,string m,string d):name(n),num(m),duixiang(d)  {      }      virtual void display()  {}      //.char dept[100];};class benkesheng:public student{public: virtual void creatlb() {}benkesheng(string n,string m,string d):student(n,m,d){} virtual void display() { cout<<"学生信息:"<<endl; cout<<"本科生:"<<endl; cout<<"学号:"<<num<<endl; cout<<"姓名:"<<name<<endl;  cout<<endl; }string getname(){ return name;} };class yanjiusheng:public student{public:   string ds;  virtual void creatlb() {}yanjiusheng(string n,string m,string d,string s):student(n,m,d),ds(s){}virtual void display()  {cout<<"学生信息:"<<endl;cout<<"研究生:"<<endl; cout<<"学号:"<<num<<endl; cout<<"姓名:"<<name<<endl; cout<<"导师姓名:"<<ds<<endl; cout<<endl; }};typedef struct _studentlist{        student *data;        struct _studentlist * next;}studentlist,*studentlis;int creatklb(studentlist *&L){ L= new studentlist; if(!L) {    return 0;  }    L->next = NULL;    return 1;  } studentlis CreateList(studentlis L,student **ptr)   {    studentlist* p = new studentlist;  p->data=*ptr;p->next = NULL;    p->next=L->next; L->next=p; return L; } void displays(student *ptr){ptr->display();}studentlis caidan(studentlis &L,student **ptr){studentlis l=L;string n1,m1,d1,d2;char slect;do {cout<<"创建学生,类型(c)本科生,(g)研究生,(e)结束,(x)遍历链表内容"<<endl;cin>>slect;switch(slect){case 'c':cout<<"本科生:"<<endl;cout<<"学号:";cin>>n1;cout<<"姓名:";cin>>m1;d1="bks";*ptr=new benkesheng(m1,n1,d1);CreateList(l,ptr); cout<<"创建成功";displays(*ptr);break;case 'g':cout<<"研究生:"<<endl;cout<<"学号:";cin>>n1;cout<<"姓名:";cin>>m1; cout<<"导师姓名:";cin>>d2;d1="bks";*ptr=new yanjiusheng(m1,n1,d1,d2);CreateList(l,ptr);cout<<"创建成功";displays(*ptr);break;case 'e':cout<<"销毁链表";while(l->next){l->data=NULL;delete l;}break;case 'x':cout<<"遍历链表内容:"<<endl;studentlis lwl =l;while(lwl->next ){lwl=lwl->next;lwl->data->display();cout<<endl;}break;}}while(slect!='e');return L;}int main(){studentlist *l;student *ptr;creatklb(l);caidan(l,&ptr);return 0;}

0 0
原创粉丝点击