《基于单链表的学生信息管理系统源代码》.docVIP

  • 21
  • 0
  • 约1.3万字
  • 约 8页
  • 2016-12-11 发布于贵州
  • 举报

《基于单链表的学生信息管理系统源代码》.doc

//学生信息管理系统 #includeiostream #includemalloc.h #includeiomanip #define NULL 0 #define LEN sizeof(struct student) //建立动态链表.cpp using namespace std; struct student{int num;char name[20];char sex[5];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; p1=p2=(struct student *)malloc(LEN); cout下面开始创建链表:endl; cout学号 姓名 性别 数学 英语 endl; cinp1-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) {cout创建失败,请重建:endl;head=creat(); } return head; }//输出链表的函数 void print(struct student *head) { cout此时链表的内容为:endl; cout学号 姓名 性别 数学 英语 总分endl; struct student *p; p=head; if(head!=NULL) do {cout setiosflags(ios_base::left)setw(3)p-numsetw(6)p-namesetw(5)p-sexsetw(5)p-mathsetw(4)p-englishsetw(5)p-math+p-englishresetiosflags(ios_base::left)endl;p=p-next; }while(p!=NULL); } //链表结点的删除操作 struct student *del(struct student *head) {if(n==0){cout无链表可删除endl;exit(0);}int num; cout请输入要删除的序号:; cinnum; while(num!=0) { struct student *p1,*p2;p1=head;while(num!=p1-nump1-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;}else{if(strcmp(p1-sex,男)==0) male--;else famale--;p2-next=p1-next;}coutnum号已被删除endl;n--;}else cout未找到此数据!endl;cout请输入要删除的序号; cinnum; } if(n==0){cout此时链表已为空!endl;exit(0);} return head; }//插入结点 struct student *insert(struct student *head) { struct student *stu; stu=(struct student*)malloc(LEN); cout学号 姓名 性别 数学 英语 endl; cinstu-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; } else { whi

文档评论(0)

1亿VIP精品文档

相关文档