用单向链表实现的一个管理系统

来源:互联网 发布:c语言中的数据类型 编辑:程序博客网 时间:2024/05/16 15:06
#include<iostream> #include<iomanip>#include<string> using namespace std;  struct student{double score;string name;string num;string classroom;int old;student* next;};int n=0;//学生的实际人数;void show(student* head){  student* p=head;   if(head==NULL)   cout<<"没有输入学生的信息:"<<endl;   else   do   {   cout<<"name:"<<" "<<p->name<<"  "<<"num:"<<" "<<p->num<<"  "<<"classroom:"<<" "<<p->classroom<<endl;   cout<<"old:"<<" "<<p->old<<"  "<<"score"<<"  "<<p->score<<endl;       p=p->next;   } while(p!=NULL);}student* insert(student*head){int der;student*p=head;student* p1;do{p1=new student;cout<<"输入你要插入学生的信息:"<<endl;cout<<"input name"<<endl;        cin>>p1->name;cout<<"input num"<<endl;cin>>p1->num;cout<<"input classroom"<<endl;cin>>p1->classroom;cout<<"input old:"<<endl;cin>>p1->old;cout<<"score:"<<endl;cin>>p1->score;while(p->next!=NULL){p=p->next;}p->next=p1;p1->next=NULL;n++;cout<<"是否继续插入:是请输入1,否则输入0"<<endl;cin>>der;}while(der);return head;}student* del(student*head)//{student *p1,*p;string name1;int der;if(head==NULL)cout<<"it is wrong"<<endl;elsedo{p=head;cout<<"输入你要删除学生的姓名:"<<endl;cin>>name1;while(p->name!=name1&&p->next!=NULL){   p1=p;p=p->next;}if(p->name!=name1)cout<<"没有这个学生:"<<endl;else{   if(head->name==name1)   head=p->next; elsep1->next=p->next;}cout<<"是否继续删除:是请输入1,否则输入0"<<endl;cin>>der;}while(der);return head;}student* creat()//这个函数是用来实现链表的,是最重要的一个函数;一定要是对的。{    student* head=NULL;   student* p1,*p2;int der;   p1=new student;            do{n++;if(n==1){head=p1;p2=p1;}else {p2->next=p1;p2=p1;}cout<<"input name"<<endl;        cin>>p1->name;cout<<"input num"<<endl;cin>>p1->num;cout<<"input classroom"<<endl;cin>>p1->classroom;cout<<"input old:"<<endl;cin>>p1->old;cout<<"score:"<<endl;cin>>p1->score;p1=new student;        cout<<"是否继续输入:是请输入1,否则输入0"<<endl;cin>>der;}while(der);            delete p1;//p2->next=NULL;//重要return head;}    void search(student*head){int der;string name1;student* p=head;do{cout<<"输入你要寻找学生的姓名:"<<endl;        cin>>name1;while(p->name!=name1&&p->next!=NULL)p=p->next;if(p->name!=name1)cout<<"没有这个学生:"<<endl;else{cout<<"输出这个学生的信息:"<<endl;   cout<<"name:"<<" "<<p->name<<"  "<<"num:"<<" "<<p->num<<"  "<<"classroom:"<<" "<<p->classroom<<endl;   cout<<"old:"<<" "<<p->old<<"  "<<"score"<<"  "<<p->score<<endl;}         cout<<"是否继续寻找:是请输入1,否则输入0"<<endl;cin>>der;}while(der);} void change(student* head){string name1;int der;student* p=head;if(head==NULL){cout<<"没有输入学生的信息:"<<endl;return ;}do{cout<<"输入你要修改学生的姓名:"<<endl;cin>>name1;while(p->name!=name1&&p->next!=NULL)p=p->next;if(p->name!=name1)cout<<"没有这个学生:"<<endl;else{ cout<<"请重新输入这个学生的有关信息:"<<endl;          cout<<"input name"<<endl;        cin>>p->name;cout<<"input num"<<endl;cin>>p->num;cout<<"input classroom"<<endl;cin>>p->classroom;cout<<"input old:"<<endl;cin>>p->old;cout<<"score:"<<endl;cin>>p->score;}cout<<"是否继续修改:是请输入1,否则输入0"<<endl;cin>>der;}while(der);}int main(){    int select;student* head;    while(1){system("cls");cout<<  "\t ******************欢迎使用******************\n";cout<<  "\t **************职工信息管理系统**************\n";cout<<  "\t *------------------------------------------*\n";cout<<  "\t *         1——录入职工信息                *\n";cout<<  "\t *         2——显示职工信息                *\n";cout<<  "\t *         3——查询职工信息                *\n";cout<<  "\t *         4——修改职工信息                *\n";cout<<  "\t *         5——添加职工信息                *\n";cout<<  "\t *         6——删除职工信息                *\n";cout<<  "\t *         0——退出                        *\n";cout<<  "\t *------------------------------------------*\n";cout<<  "\t 你要输入的编号是(0--6):";cin>>select;if(select==0) break;switch(select){case 1: head=creat(); //调用input函数录入数据system("pause");break;case 2:show(head); //调用show函数显示职工信息 system("pause");break;case 3:    search(head);  //调用search函数查询职工信息system("pause");break;case 4:change(head);  //调用change函数修改职工信息system("pause");break;case 5:    head=insert(head);     //调用add函数添加职工信息system("pause");break;case 6:    head=del(head);    // 调用del函数删除职工信息system("pause");break;default:cout<<"没有此选项,请重新选择!"<<endl;}}return 0;}

0 0
原创粉丝点击