《基于单链表的学生信息管理系统源代码》由会员分享,可在线阅读,更多相关《基于单链表的学生信息管理系统源代码(8页珍藏版)》请在人人文库网上搜索。
1、学生信息管理系统#include#include#include#define NULL 0#define LEN sizeof(struct student)/建立动态链表.cppusing namespace std;struct studentint num;char name20;char sex5;float math;float english;int order;struct student *next;int n;int male=0;int famale=0;struct student *creat(void)struct student *head,*p1,*p2;n=0。
2、;p1=p2=(struct student *)malloc(LEN);coutp1-nump1-namep1-sexp1-mathp1-english;head=NULL;while(p1-num!=0)if(strcmp(p1-sex,男)=0) male+;else famale+;n+;if(n=1)head=p1;else p2-next=p1;p2=p1;p1=(struct student*)malloc(LEN);cinp1-nump1-namep1-sexp1-mathp1-english;p2-next=NULL;if(head=NULL)coutnumnamesexma。
3、thenglishmath+p-englishnext;while(p!=NULL);/链表结点的删除操作struct student *del(struct student *head)if(n=0)coutnum;while(num!=0)struct student *p1,*p2;p1=head;while(num!=p1-num&p1-next!=NULL)p2=p1;p1=p1-next;if(num=p1-num) if(p1=head)if(strcmp(p1-sex,男)=0) male-;else famale-;head=p1-next;elseif(strcmp(p1-。
4、sex,男)=0) male-;else famale-;p2-next=p1-next;coutnum;if(n=0)coutstu-numstu-namestu-sexstu-mathstu-english;while(stu-num!=0)if(strcmp(stu-sex,男)=0) male+;else famale+;n+;struct student *p0,*p1,*p2;p1=head;p0=stu;if(head=NULL)head=p0;p0-next=NULL;elsewhile(p0-nump1-num&p1-next!=NULL)p2=p1;p1=p1-next;i。
5、f(p0-numnum)if(head=p1)head=p0;else p2-next=p0;p0-next=p1;else p1-next=p0;p0-next=NULL;stu=(struct student*)malloc(LEN);cinstu-numstu-namestu-sexstu-mathstu-english;return head;/根据学号查找void SearchNum(struct student *head)int num;struct student *p;p=head;coutnum;while(p-num!=num&p-next!=NULL)p=p-next;。
6、if(p-num=num)coutordernumnamesexmathenglishmath+p-englishname;while(strcmp(p-name,name)!=0&p-next!=NULL)p=p-next;if(strcmp(p-name,name)=0)coutordernumnamesexmathenglishmath+p-englishnext;max=(p2-math+p2-english);while(p0-next!=NULL)while(p1!=NULL)if(p1-math+p1-english)max)max=(p1-math+p1-english);p2。
7、=p1;p1=p1-next; p2-order=+NO;max=p2-order;p2-order=p0-order;p0-order=max;max=p2-num;p2-num=p0-num;p0-num=max;max=p2-math;p2-math=p0-math;p0-math=max;max=p2-english;p2-english=p0-english;p0-english=max;strcpy(temp,p2-name);strcpy(p2-name,p0-name);strcpy(p0-name,temp);strcpy(temp,p2-sex);strcpy(p2-sex。
8、,p0-sex);strcpy(p0-sex,temp);p0=p0-next;p2=p0;p1=p2-next;max=(p2-math+p2-english);if(p0-next=NULL)p2-order=+NO;coutordernumnamesexmathenglishmath+p-englishnext;No+;while(p!=NULL);couta;if(a=0)cout6)cout无该选项,请从0-6中选择endlendlendl;switch(a)case 1:head=creat();head=sort(head);print2(head);break;case 2:SearchNum(head);break;case 3:SearchName(head);break;case 4:head=del(head);head=sort(head);print2(head);break;case 5:head=insert(head);head=sort(head);print2(head);break;case 6:cout此时总人数n人 其中男生male人 女生famale人endlendlendl;break;return 0。