基于单链表的学生信息管理系统源代码
- 格式:doc
- 大小:231.50 KB
- 文档页数:20
3、4、7、#include <iostream>using namespace std;//实现线性表的链式存储结构的类型定义typedef int Elemtype;#define OK 1;#define ERROR -1;struct NODE //结点类型{Elemtype elem;NODE *next;};struct LINK_LIST //链表类型{NODE *head;};//典型操作的算法实现//初始化链表Lint InitList(LINK_LIST *L){L->head = (NODE*)malloc(sizeof(NODE)); //为头结点分配存储单元if (L->head) {L->head->next=NULL; return OK;}else return ERROR ;}//销毁链表Lvoid DestoryList(LINK_LIST *L){NODE *p;while (L->head) //依次删除链表中的所有结点{p=L->head; L->head=L->head->next;free(p);}}//清空链表Lvoid ClearList(LINK_LIST *L){NODE *p;while (L->head->next){ //p指向链表中头结点后面的第一个结点p=L->head->next;L->head->next=p->next; //删除p结点free(p); //释放p结点占据的存储空间}}//求链表L的长度int ListLength(LINK_LIST L){NODE *p;int len;len=0;for(p=L.head;p->next!=NULL; p=p->next)len++ ;return(len);}// 判链表L空否。
C语⾔链表实现学⽣管理系统本⽂实例为⼤家分享了C语⾔链表实现学⽣管理系统的具体代码,供⼤家参考,具体内容如下#include<stdio.h>#include<ctype.h>#include<fstream>#include<stdlib.h>#include<string.h>#include<iostream>using namespace std;typedef struct ndoe{char id[10];char name[10];char sex[3];char num[10];struct node *next;}student;struct Student{student data;struct Student *next;};/********创建学⽣信息**********/Student * insert(Student * head){Student * s,*r;head=(Student *)malloc(sizeof(Student));printf("请输⼊学⽣的个数:");int n;scanf("%d",&n);r=head;printf("按照“学号姓名性别(M or G) ⼿机号”的形式输⼊每个学⽣的信息\n");for(int i=0;i<n;i++){s=(Student *)malloc(sizeof(Student));/*scanf("%s",s->data.id);scanf("%s",s->);scanf("%s",s->data.sex);scanf("%s",s->data.num);*/scanf("%s%s%s%s",s->data.id,s->,s->data.sex,s->data.num);r->next=s;r=s;}r->next=NULL;printf("录⼊成功\n");return head;}/********增加学⽣************/void add(Student *head){Student *s;s=head->next;while(s->next!=NULL)s=s->next;Student *ad=(Student *)malloc(sizeof(Student));ad->next=NULL;s->next=ad;//printf("输⼊新学⽣的信息:\n");scanf("%s%s%s%s",ad->data.id,ad->,ad->data.sex,ad->data.num);printf("添加成功\n");return ;}/*************修改学⽣信息********************/void change(Student * head){printf("输⼊1,按学号搜索学⽣,并修改改学⽣的信息\n");printf("输⼊2,按姓名搜索学⽣,并修改改学⽣的信息\n");Student * s;int n;scanf("%d",&n);switch(n){case 1:{printf("请输⼊学号:");char number[10];scanf("%s",number);s=head->next;while(s!=NULL){if(strcmp(s->data.id,number)==0){printf("请输⼊要修改的信息:");char phone[10];scanf("%s",phone);strcpy(s->data.num,phone);printf("修改成功\n");break;}s=s->next;}break;}case 2:{printf("请输⼊姓名:");char nam[10];scanf("%s",&nam);s=head->next;while(s!=NULL){if(strcmp(s->,nam)==0){printf("请输⼊要修改的信息:");char phone[10];scanf("%s",phone);strcpy(s->data.num,phone);printf("修改成功\n");break;}s=s->next;}break;}}return ;}/**********删除学⽣信息******************/void del(Student * head){printf("输⼊1,按学号搜索学⽣,并删除该学⽣的信息\n"); printf("输⼊2,按姓名搜索学⽣,并删除该学⽣的信息\n"); Student * s,*r;int n;scanf("%d",&n);switch(n){case 1:{printf("请输⼊学号:");char number[10];scanf("%s",number);s=head->next;r=head;while(s!=NULL){if(strcmp(s->data.id,number)==0){r->next=s->next;free(s);printf("删除成功\n");break;}r=s;s=s->next;}break;}case 2:{printf("请输⼊姓名:");char nam[10];scanf("%s",&nam);s=head->next;r=head;while(s!=NULL){if(strcmp(s->,nam)==0){r->next=s->next;free(s);printf("删除成功\n");break;}r=s;s=s->next;}break;}}return ;}/**********查询学⽣的信息**********************/void check(Student * head){printf("输⼊1,按学号搜索学⽣,并展⽰该学⽣的信息\n");printf("输⼊2,按姓名搜索学⽣,并展⽰该学⽣的信息\n");Student * s,r;int n;scanf("%d",&n);switch(n){case 1:{printf("请输⼊学号:");char number[10];scanf("%s",number);s=head->next;while(s!=NULL){if(strcmp(s->data.id,number)==0){printf("%s %s %s %s\n",s->data.id,s->,s->data.sex,s->data.num); break;}s=s->next;}break;}case 2:{printf("请输⼊姓名:");char nam[10];scanf("%s",&nam);s=head->next;while(s!=NULL){if(strcmp(s->,nam)==0){printf("%s %s %s %s\n",s->data.id,s->,s->data.sex,s->data.num); break;}s=s->next;}break;}}if(s==NULL)printf("该学⽣不存在\n");return ;}int main(){Student *head=NULL;Student *a;printf("***欢迎进⼊学⽣管理系统***\n");printf("***1:请录⼊学⽣信息***\n");printf("***2:请修改学⽣信息***\n");printf("***3:请删除学⽣信息***\n");printf("***4:请查询学⽣信息***\n");printf("***5:请添加新学⽣信息**\n");printf("***6: 退出管理系统 ***\n");printf("*************************\n");printf("请输⼊命令:");int n;while(scanf("%d",&n)&&n!=6){switch(n){case 1:{printf("请录⼊学⽣信息:\n");head=insert(a);break;}case 2:{printf("请改学⽣信息:\n");change(head);break;}case 3:{cout<<"请删除学⽣信息:"<<endl;del(head);break;}case 4:{cout<<"请查询学⽣信息:"<<endl;check(head);break;}case 5:{cout<<"请添加新学⽣信息:"<<endl;add(head);break;}default :break;}printf("请继续输⼊命令:");}Student *s,*r;s=head->next;while(s!=NULL){r=s->next;free(s);s=r;}free(head);return 0;}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
#include <stdio.h>#include <string.h>/* 谭法建立单链表和输出单链表*/#include <malloc.h>#include <stdlib.h>typedef struct node{ int num;char name[20];struct node *next;}STD;#define LEN sizeof(STD)int menu_select();void handle_menu1();void game4();void game2();STD *insert(STD *head,STD *stud);STD *insert2(STD *head,STD *stud); void game3();void game5();STD *delete(STD*head,long num);void game1();void game6();STD *search(STD*head,long num);STD *head1,*head2;int n=0;/*追加法建表*/void creat1(void){ STD *p1,*p2;system("CLS");head1=NULL;p1=(STD *)malloc(LEN);p2=p1;printf("建表方法1追加法建表!\n");printf("输入学号姓名,若输入学号为0则退出建表!\n");scanf("%d%s",&p1->num,p1->name);while(p1->num!=0){ n++;if(n==1)head1=p1;elsep2->next=p1;p2=p1;p1=(STD *)malloc(LEN);scanf("%d%s",&p1->num,p1->name);}free(p1); p2->next=NULL;scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");return ;}/* 插入法建表*/void creat2(void){ STD *p1;head2=NULL;system("CLS");p1=(STD *)malloc(LEN);printf("建表方法2插入法建表!\n");printf("输入学号姓名(输入学号以0结束)!\n");scanf("%d%s",&p1->num,p1->name);while(p1->num!=0){ p1->next=head2;head2=p1;p1=(STD *)malloc(LEN);scanf("%d%s",&p1->num,p1->name);}scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");free(p1);return ;}/* 链表输出*/void print(STD *head){ STD *p;p=head;while (p!=NULL){ printf("学号%3d 姓名%s\n",p->num,p->name); p=p->next;} printf("链表为空!\n");scanf("%*c");printf("按回车键继续!\n");getchar();system("CLS");}/*-------------------------------------------------*//*--------------表1插入结点函数-------*//*-------------------------------------------------*/void game4(){char ch;STD *stud,*head=head1;system("CLS");printf("\t仅限在表1中插入!\n");printf("\t输入要插入结点的学号和姓名(以空格隔开):");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);if(stud->num<0){ printf("\t输入的学号不能为负数,请重新选择插入!\n");return;}while(stud->num>=0){head1=insert(head,stud);printf("\t继续插入新结点吗?(y/n):");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入新结点学号姓名:(输入n结束插入)");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2插入结点函数-------*//*-------------------------------------------------*/void game2(){char ch;STD *stud,*head=head2;system("CLS");printf("\t仅限在表2中插入!\n");printf("\t输入要插入结点的学号和姓名(以空格隔开):");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);if(stud->num<0){ printf("\t输入的学号不能为负数,请重新选择插入!\n");return;}while(stud->num>=0){head2=insert2(head,stud);printf("\t继续插入新结点吗?(y/n):");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入新结点学号姓名:(输入n结束插入)");stud=(STD *)malloc(LEN);scanf("%*c");scanf("%d%s",&stud->num,&stud->name);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 插入模块*//**************************************/STD *insert(STD *head,STD *stud){STD *p0,*p1,*p2;p1=head;p0=stud;if(head==NULL){head=p0;p0->next=NULL;}else{while((p0->num>p1->num)&&(p1->next!=NULL)){p2=p1; p1=p1->next;}if(p0->num<=p1->num){if(head==p1)head=p0;else p2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;}}n=n+1;printf("按回车键继续!\n");getchar();system("CLS");return (head);}/**************************************//* 插入模块2 *//**************************************/STD *insert2(STD *head,STD *stud){STD *p0,*p1,*p2;p1=head;p0=stud;if(head==NULL){head=p0;p0->next=NULL;}else{while((p0->num<p1->num)&&(p1->next!=NULL)){p2=p1; p1=p1->next;}if(p0->num>=p1->num){if(head==p1)head=p0;else p2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;}}n=n+1;printf("按回车键继续!\n");getchar();system("CLS");return (head);}/*-------------------------------------------------*//*--------------表1删除学生信息-------*//*-------------------------------------------------*/void game3(){ int num;char ch;STD *head=head1;printf("\t仅限在表1中删除!\n");printf("\t输入要删除的学号:");scanf("%*c");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新选择删除!\n");return;}while(num>=0){head=head1;head1=delete(head,num);printf("\t继续删除吗?(y/n):");scanf("%*c");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要删除的学号:(输入n结束删除!)");scanf("%*c");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2删除学生信息-------*//*-------------------------------------------------*/void game5(){ int num;char ch;STD *head=head2;printf("\t仅限在表2中删除!\n");printf("\t输入要删除的学号:");scanf("%*c");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新选择删除!\n");return;}while(num>=0){head=head2;head2=delete(head,num);printf("\t继续删除吗?(y/n):");scanf("%*c");ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要删除的学号:(输入n结束删除!)");scanf("%*c");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 删除模块*//**************************************/STD *delete(STD*head,long num){STD *p1,*p2;if (head==NULL) {printf("\n没有找到该学号!\n");return head;} p1=head;while(num!=p1->num&&p1->next!=NULL){p2=p1;p1=p1->next;}if(num==p1->num){if(p1==head)head=p1->next;else p2->next=p1->next;printf("\n删除:%ld\n",num);n=n-1;}elseprintf("\n 没有发现此项! \n",num);system("CLS");return(head);}/*-------------------------------------------------*//*--------------表1查找学生信息-------*//*-------------------------------------------------*/void game1(){ int num;char ch;STD *head=head1;printf("\t仅限在表1中查找!\n");printf("\t输入要查找的学号:");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新查找!\n");return;}while(num>=0){head=head1;head1=search(head,num);printf("\t继续查找吗?(y/n):");scanf("%d",&num);ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要查找的学号:(输入n结束查找)");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/*-------------------------------------------------*//*--------------表2查找学生信息-------*//*-------------------------------------------------*/void game6(){ int num;char ch;STD *head=head2;printf("\t仅限在表2中查找!\n");printf("\t输入要查找的学号:");scanf("%ld",&num);if(num<0){ printf("\t输入的学号不能为负数,请重新查找!\n");return;}while(num>=0){head=head2;head2=search(head,num);printf("\t继续查找吗?(y/n):");scanf("%d",&num);ch=getchar();if(ch=='y'||ch=='Y'){ printf("\t输入要查找的学号:(输入n结束查找)");scanf("%ld",&num);}elsebreak;}printf("\t输入回车键返回!\n");getchar();system("CLS");printf("\n");}/**************************************//* 查找模块*//**************************************/STD *search(STD*head,long num){STD *p1,*p2;if (head==NULL) {printf("\n没有找到该学号!\n");return head;} p1=head;while(num!=p1->num&&p1->next!=NULL){p2=p1;p1=p1->next;}if(num==p1->num)printf("\n%d %s\n",p1->num,p1->name);elseprintf("\n 没有发现此项! \n",num);return(head);}/* void main(){printf(" *** 运行结果***\n");printf("输入学号姓名(输入学号以0结束)!\n");creat1();print(head1);creat2();print(head2);} *///******************************//* select.cpp:主程序文件*//******************************void main(){handle_menu1();}//*****************************//* 菜单处理函数*//*****************************void handle_menu1(){int h;for(;;){h=menu_select();switch(h){ case 1:/* printf("\t进入追加法建表\n"); */creat1();break; /* 调用功能模块*/case 2:/* printf("\t进入插入法建表\n"); */creat2();break;case 3:/* printf("\t输出追加法链表的结果\n"); */print(head1);break;case 4:/* printf("\t输出插入法链表的结果\n"); */print(head2);break;case 5:/* printf("\t链表1插入\n"); */game4();break;case 6:/* printf("\t链表2插入\n"); */game2();break;case 7:/* printf("\t链表1删除\n"); */game3();break;case 8:/* printf("\t链表2删除\n"); */game5();break;case 9:/* printf("\t链表1查找\n"); */game1();break;case 10:/* printf("\t链表2查找\n"); */game6();break;case 11:printf("\t再见,欢迎再次使用本系统!谢谢!\n");return;}}}//**********************************//* 菜单选择函数: int menu_select()*//**********************************int menu_select(){int cn;for(;;){printf("\ \n");printf("\t1.追加法建表\n");printf("\ \n");printf("\t2.插入法建表\n");printf("\ \n");printf("\t3.输出链表1\n");printf("\ \n");printf("\t4.输出链表2\n");printf("\ \n");printf("\t5.插入链表1 \n");printf("\ \n");printf("\t6.插入链表2 \n");printf("\ \n");printf("\t7.删除链表1 \n");printf("\ \n");printf("\t8.删除链表2 \n");printf("\ \n");printf("\t9.查找链表1 \n");printf("\ \n");printf("\t10.查找链表2 \n");printf("\ \n");printf("\t11.退出系统\n");printf("\ \n");printf("\t请您选择1-11:");scanf("%d",&cn);//gets(s);//cn=atoi(s);if(cn<1||cn>11)printf("\n\t输入错误,重选1-11:");elsebreak;}return cn;}。
#include <stdio.h>#include <string.h>#include <stdlib.h>#define N 15 //学号位数#define M 15 //姓名字节数#define L 4 //成绩的科数int aa=0;//记录筛选时打开的文void printf_(struct stu *); //输出单个的学生数据struct stu * scanf1_(); //接收单个的学生数据,返回指针,struct stu * scanf_(); //得到学生的数据,并放入到链表中void print_(struct stu *); //输出链表中的学生信息struct stu *num_paixu(struct stu *); //用链表给学生排序void chaxun(struct stu *); //根据学生的学号查询学生的信息,并把学生的数据输出struct stu * charu(struct stu *); //将学生的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。
struct stu * shanchu(struct stu *); //删除数据void xiugai(struct stu *); //修改学生的信息。
void fprint_(struct stu *); //把数据写入到文件int to_ji(struct stu *); //统计学生的总人数int t_ji_tj(struct stu *); //统计成绩在某一区间内的人数struct stu * ch_ji_paixu(struct stu *); //按成绩排序,默认的是按总成绩排序struct s *shaixuan(struct stu *); //筛选符合条件的数据,得到符合条件的结构体数据的指针。
void shuchu_shai(struct s *); //输出筛选出来的数据void fb_shu_shai(struct s *); //将筛选出来的数据输入到文件中void avrage(struct stu *head,float *); //计算平均成绩void fb_avrage(float *); //将平均成绩放在文件的最后面//建立学生结构体struct stu{char num[N];char name[M];int ch_ji[L];struct stu *next;};//建立一个链表,存放学生结构体的指针struct s{struct stu *p;struct s *ps;};void main(){int i,n,x=1,k=0;float a[L]={0};struct stu *head=NULL;struct s *shead=NULL;char ch;while(x){ system("cls");printf("********************************************************************* **********\n");printf(" 0---退出系统1---录入数据\n");printf(" 2---保存文件3---按成绩排序\n");printf(" 4---查看信息5---按学号排序\n");printf(" 6---统计人数7---按条件筛选\n");printf(" 8---查询信息9---显示筛选结果\n");printf(" 10---插入数据11---保存筛选结果\n");printf(" 12---删除数据13---计算平均成绩\n");printf(" 14---修改数据15---保存平均成绩\n");printf(" 16---按条件统计人数\n");printf("********************************************************************* **********\n");scanf("%d",&n);getchar();//有啥作用switch(n){case 0:x=0;break;case 1:head=scanf_();break;case 2:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}elsefprint_(head);break;case 3:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{head=ch_ji_paixu(head);break;}case 4:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}elseprint_(head);break;case 5:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{head=num_paixu(head);printf("是否显示排序结果Y/N ?");ch=getchar();getchar();if(ch=='y'||ch=='Y'){printf("\n");print_(head);}}case 6:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{k=to_ji(head);printf("总共有%3d 名学生",k);getchar();break;}case 7:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{shead=shaixuan(head);if(shead!=NULL&&shead->ps!=NULL){printf("是否显示筛选结果Y/N ?");ch=getchar();if(ch=='y'||ch=='Y'){printf("\n");shuchu_shai(shead);getchar();}}break;}case 8:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();}else{chaxun(head);getchar();break;}case 9:if(head==NULL||head->next==NULL) {printf("请先录入学生的数据!");getchar();break;}else{printf("\n");shuchu_shai(shead);getchar();break;}case 10:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}elsehead=charu(head);break;case 11:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{fb_shu_shai(shead);getchar();break;}if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{head=shanchu(head);break;}case 13:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{avrage(head,a);printf("平均值计算成功!\n是否显示平均成绩Y/N ?");ch=getchar();if(ch=='y'||ch=='Y'){printf("\n 语文数学英语总成绩\n");printf("%-8.2f%-8.2f%-8.2f%-8.2f",a[0],a[1],a[2],a[L-1]);getchar();}break;}case 14:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{xiugai(head);break;}case 15:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{fb_avrage(a);printf("平均值保存成功!");getchar();break;}case 16:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{k=t_ji_tj(head);if(k>0){printf("符合条件的有%3d 名学生!",k);getchar();}else if(k==0){printf("没有符合条件的学生!");getchar();}else if(k==-2)getchar();break;}default :printf("输入有误,请重新输入!");getchar();break;}}}//输出单个的学生数据void printf_(struct stu *p0){int i;printf("学号:");puts(p0->num);printf("姓名:");puts(p0->name);printf("语文数学英语总成绩\n");for(i=0;i<L;i++)printf("%-8d",p0->ch_ji[i]);printf("\n");}//接收单个的学生数据,返回指针,struct stu * scanf1_(){int i,sum=0;struct stu *p0;p0=(struct stu *)malloc(sizeof(struct stu));printf("请输入学生的学号:");gets(p0->num);printf("请输入学生的姓名:");gets(p0->name);printf("请输入学生的三科成绩(语文、数学、英语):");for(i=0;i<L-1;i++){scanf("%d",&p0->ch_ji[i]);sum+=p0->ch_ji[i];}getchar();p0->ch_ji[L-1]=sum;return p0;}//得到学生的数据,并放入到链表中struct stu * scanf_(){struct stu *p1,*p2,*head;int i,sum=0,n=0;printf("注意:当学生学号为0 时输入结束\n\n");p1=(struct stu *)malloc(sizeof(struct stu)); /*得到学生信息*/head=p2=p1;do{ printf("请输入学生的学号:");gets(p1->num);if(strcmp(p1->num,"0")==0)break;printf("请输入学生的姓名:");gets(p1->name);printf("请输入学生的三科成绩(语文、数学、英语):");for(i=0;i<L-1;i++){scanf("%d",&p1->ch_ji[i]);sum+=p1->ch_ji[i];}getchar();printf("\n");p1->ch_ji[L-1]=sum;sum=0;p1=(struct stu *)malloc(sizeof(struct stu));p2->next=p1;p2=p1;n++;}while(1);p1->next=NULL;printf("成绩输入结束!\n");getchar();/*学生的数据被放在链表中*/return head;}/*输出链表中的学生信息*/void print_(struct stu *head){int i;struct stu *p1,*p2;p1=p2=head;while(p1->next!=NULL){printf("学号:");puts(p1->num);printf("姓名:");puts(p1->name);printf("语文数学英语总成绩\n");for(i=0;i<L;i++)printf("%-8d",p1->ch_ji[i]);printf("\n");p1=p2->next;p2=p1;}getchar();}/*用链表给学生排序*/struct stu *num_paixu(struct stu *head){struct stu *p1,*p2,*p3,*p4,*p5,*p6,*p7;int x=1;for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next){p3=p1;for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next){if(strcmp(p3->num,p2->num)>0){p3=p2;p5=p7;}}if(p3!=p1){if(x&&p1==head){p6=p1->next;p1->next=p3->next;p3->next=p6;p5->next=p1;head=p3;p1=p3;x=0;}else{p6=p1->next;p1->next=p3->next;p3->next=p6;p4->next=p3;p5->next=p1;p1=p3;}}printf("排序成功!\n");return head;}//根据学生的学号查询学生的信息,并把学生的数据输出void chaxun(struct stu *head){char a[N];struct stu *p1;printf("请输入要查询的学号:");gets(a);p1=head;while(p1->next!=NULL){if(strcmp(p1->num,a)==0)break;p1=p1->next;}if(p1->next==NULL)printf("没有找到学号为%s 的学生!\n",a);else{printf("要查询的学生信息如下:\n\n");printf_(p1);}}//将学生的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。
#include <stdio.h>#include <string.h>#include <stdlib.h>#define N 15 //学号位数#define M 15 //姓名字节数#define L 4 //成绩的科数int aa=0;//记录筛选时打开的文void printf_(struct stu *); //输出单个的学生数据struct stu * scanf1_(); //接收单个的学生数据,返回指针,struct stu * scanf_(); //得到学生的数据,并放入到链表中void print_(struct stu *); //输出链表中的学生信息struct stu *num_paixu(struct stu *); //用链表给学生排序void chaxun(struct stu *); //根据学生的学号查询学生的信息,并把学生的数据输出struct stu * charu(struct stu *); //将学生的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。
struct stu * shanchu(struct stu *); //删除数据void xiugai(struct stu *); //修改学生的信息。
void fprint_(struct stu *); //把数据写入到文件int to_ji(struct stu *); //统计学生的总人数int t_ji_tj(struct stu *); //统计成绩在某一区间内的人数struct stu * ch_ji_paixu(struct stu *); //按成绩排序,默认的是按总成绩排序struct s *shaixuan(struct stu *); //筛选符合条件的数据,得到符合条件的结构体数据的指针。
void shuchu_shai(struct s *); //输出筛选出来的数据void fb_shu_shai(struct s *); //将筛选出来的数据输入到文件中void avrage(struct stu *head,float *); //计算平均成绩void fb_avrage(float *); //将平均成绩放在文件的最后面//建立学生结构体struct stu{char num[N];char name[M];int ch_ji[L];struct stu *next;};//建立一个链表,存放学生结构体的指针struct s{struct stu *p;struct s *ps;};void main(){int i,n,x=1,k=0;float a[L]={0};struct stu *head=NULL;struct s *shead=NULL;char ch;while(x){ system("cls");printf("******************************************************************* ************\n");printf(" 0---退出系统 1---录入数据\n");printf(" 2---保存文件 3---按成绩排序 \n");printf(" 4---查看信息 5---按学号排序 \n");printf(" 6---统计人数 7---按条件筛选 \n");printf(" 8---查询信息 9---显示筛选结果 \n");printf(" 10---插入数据 11---保存筛选结果 \n");printf(" 12---删除数据 13---计算平均成绩 \n");printf(" 14---修改数据 15---保存平均成绩 \n");printf(" 16---按条件统计人数\n");printf("******************************************************************* ************\n");scanf("%d",&n);getchar();//有啥作用switch(n){case 0:x=0;break;case 1:head=scanf_();break;case 2:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}elsefprint_(head);break;case 3:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{head=ch_ji_paixu(head);break;}case 4:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}elseprint_(head);break;case 5:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{head=num_paixu(head);printf("是否显示排序结果 Y/N ?");ch=getchar();getchar();if(ch=='y'||ch=='Y'){printf("\n");print_(head);}}case 6:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{k=to_ji(head);printf("总共有%3d 名学生",k);getchar();break;}case 7:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{shead=shaixuan(head);if(shead!=NULL&&shead->ps!=NULL){printf("是否显示筛选结果 Y/N ?");ch=getchar();if(ch=='y'||ch=='Y'){printf("\n");shuchu_shai(shead);getchar();}}break;}case 8:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();}else{chaxun(head);getchar();break;}case 9:if(head==NULL||head->next==NULL) {printf("请先录入学生的数据!");getchar();break;}else{printf("\n");shuchu_shai(shead);getchar();break;}case 10:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}elsehead=charu(head);break;case 11:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{fb_shu_shai(shead);getchar();break;}case 12:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{head=shanchu(head);break;}case 13:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{avrage(head,a);printf("平均值计算成功!\n是否显示平均成绩 Y/N ?");ch=getchar();if(ch=='y'||ch=='Y'){printf("\n 语文数学英语总成绩\n");printf("%-8.2f%-8.2f%-8.2f%-8.2f",a[0],a[1],a[2],a[L-1]);getchar();}break;}case 14:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{xiugai(head);break;}case 15:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{fb_avrage(a);printf("平均值保存成功!");getchar();break;}case 16:if(head==NULL||head->next==NULL){printf("请先录入学生的数据!");getchar();break;}else{k=t_ji_tj(head);if(k>0){printf("符合条件的有%3d 名学生!",k);getchar();}else if(k==0){printf("没有符合条件的学生!");getchar();}else if(k==-2)getchar();break;}default :printf("输入有误,请重新输入!");getchar();break;}}}//输出单个的学生数据void printf_(struct stu *p0){int i;printf("学号:");puts(p0->num);printf("姓名:");puts(p0->name);printf("语文数学英语总成绩\n");for(i=0;i<L;i++)printf("%-8d",p0->ch_ji[i]);printf("\n");}//接收单个的学生数据,返回指针,struct stu * scanf1_(){int i,sum=0;struct stu *p0;p0=(struct stu *)malloc(sizeof(struct stu));printf("请输入学生的学号:");gets(p0->num);printf("请输入学生的姓名:");gets(p0->name);printf("请输入学生的三科成绩(语文、数学、英语):");for(i=0;i<L-1;i++){scanf("%d",&p0->ch_ji[i]);sum+=p0->ch_ji[i];}getchar();p0->ch_ji[L-1]=sum;return p0;}//得到学生的数据,并放入到链表中struct stu * scanf_(){struct stu *p1,*p2,*head;int i,sum=0,n=0;printf("注意:当学生学号为 0 时输入结束\n\n");p1=(struct stu *)malloc(sizeof(struct stu)); /*得到学生信息*/ head=p2=p1;do{ printf("请输入学生的学号:");gets(p1->num);if(strcmp(p1->num,"0")==0)break;printf("请输入学生的姓名:");gets(p1->name);printf("请输入学生的三科成绩(语文、数学、英语):");for(i=0;i<L-1;i++){scanf("%d",&p1->ch_ji[i]);sum+=p1->ch_ji[i];}getchar();printf("\n");p1->ch_ji[L-1]=sum;sum=0;p1=(struct stu *)malloc(sizeof(struct stu));p2->next=p1;p2=p1;n++;}while(1);p1->next=NULL;printf("成绩输入结束!\n");getchar();/*学生的数据被放在链表中*/return head;}/*输出链表中的学生信息*/void print_(struct stu *head){int i;struct stu *p1,*p2;p1=p2=head;while(p1->next!=NULL){printf("学号: ");puts(p1->num);printf("姓名: ");puts(p1->name);printf("语文数学英语总成绩\n");for(i=0;i<L;i++)printf("%-8d",p1->ch_ji[i]);printf("\n");p1=p2->next;p2=p1;}getchar();}/*用链表给学生排序*/struct stu *num_paixu(struct stu *head){struct stu *p1,*p2,*p3,*p4,*p5,*p6,*p7;int x=1;for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next){p3=p1;for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next){if(strcmp(p3->num,p2->num)>0){p3=p2;p5=p7;}}if(p3!=p1){if(x&&p1==head){p6=p1->next;p1->next=p3->next;p3->next=p6;p5->next=p1;head=p3;p1=p3;x=0;}else{p6=p1->next;p1->next=p3->next;p3->next=p6;p4->next=p3;p5->next=p1;p1=p3;}}printf("排序成功!\n");return head;}//根据学生的学号查询学生的信息,并把学生的数据输出void chaxun(struct stu *head){char a[N];struct stu *p1;printf("请输入要查询的学号:");gets(a);p1=head;while(p1->next!=NULL){if(strcmp(p1->num,a)==0)break;p1=p1->next;}if(p1->next==NULL)printf("没有找到学号为 %s 的学生!\n",a);else{printf("要查询的学生信息如下:\n\n");printf_(p1);}}//将学生的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。
软件学院项目报告书课程:专业实训项目名称: 学生信息管理系统专业年级: 软件工程Java2级姓名: ××学号: ×××××指导教师: ××2011年06月14日目录第1章问题描述 (2)1.1 课题背景 (2)1.2需求分析 (3)1.2.1 功能需求 (3)1.2.2 性能需求 (4)1.3本章小结 (4)第2章总体设计 (5)2.1系统介绍 (5)2.2主程序执行流程图 (6)第3章代码设计 (7)3.1程序运行结果截图 (7)3.2程序源代码 (11)3.3本章小结 (17)第4章总结 (18)参考文献 (19)第1章问题描述1.1 课题背景管理系统是使用电子计算机执行管理和决策功能的服务系统,是六十年代以后,随着系统科学,信息技术以及计算机科学的进展,适应现代化管理的需要而形成的一门边缘学科。
它是将计算机硬件,软件,人工规程,管理制度,决策模拟以及管理人员等组合在一起的一个人--机系统。
学生信息管理系统,是针对目前学生信息处理工作的实际情况,结合数据技术,设计开发的学生信息管理系统;能够实现创建、添加、插入、排序、查找、修改学生信息等。
学生信息管理系统是典型的信息管理系统,其开发主要包括前端应用程序的开发和后台数据库的建立和维护两个方面。
对前者要求应用功能完备,容易使用,界面友好等;而对后者则要求建立起数据库一致性和完整性强,数据安全性好的数据库。
学生信息管理系统是教育单位不可缺少的部分,它的内容对于学校的决策者和管理者来说至关重要,能够为学校的管理者提供充足的学生信息和快捷的查询手段。
1.2 需求分析1.2.1 功能需求(1)本系统具有很强的可靠行,可以对录入的学生信息进行效验,对数据进行修改、删除,可以方便管理员的修改与维护。
(2)本系统操作方便、灵活、简单。
操作人员只需录入学生的基本信息和考试成绩的数据。
(3)本系统可高效、快速的查询到学生的基本信息和考试成绩,便于管理员管理工作的开展。
(4)本系统主要用于学校学生信息管理,总体任务是实现学生信息关系的系统化、规范化和自动化,其主要任务是用计算机对学生各种信息进行日常管理,如查询、修改、添加,另外还考虑到学生考试成绩,针对这些要求设计了学生信息管理系统。
本系统主要包括信息录入、信息维护、信息查询、报表打印、关闭系统这几部分。
其功能主要有:⒈有关学生信息的录入,包括录入学生基本信息、学生考试成绩等。
⒉学生信息的维护,包括添加修改学生基本信息、考试成绩信息。
⒊学生信息的查询,包括查询学生的个人基本信息、科目考试成绩。
⒋信息的报表打印,包括学生的基本信息的报表打印、考试成绩的报表打印。
1.2.2 性能需求本项目是一个学生信息管理系统,运行环境VC++6.0,项目运行速率正常,可以满足用户需求。
1、时间特性要求:响应时间要低于5秒2、便捷性:在程序运行过程中,系统自动提示用户进行每一步操作,程序功能明了简洁!1.3 本章小结本章介绍了学生信息管理系统的背景意义,并对本系统功能需求和性能需求进行了分析,可以清晰看到学生信息管理系统在进行信息管理时的优越性。
第2章总体设计2.1 系统介绍1.学生信息管理系统主要涉及到查询等各的功能,需要通过磁盘读写数据,虽然本系统仅实现了简单的功能,但也需要按照系统整体性来设计。
程序可以查询、修改、增添、删除学生信息,并将之保存在磁盘文件中,信息数据不易丢失;2.为了提高系统的稳定性和可重用性,程序采用子函数调用的形式完成各项功能,并用单向动态链表存储从磁盘文件读取到的信息;3.屏幕设计:屏幕作为信息的显示,通过输出格式的控制,界面更简洁、合理!第3章代码设计3.1 程序运行结果截图主界面:创建学生链表:按学号查询:按姓名查询:删除学生(删后自动排序):添加学生(添后自动排序):计算总人数及男女生人数:程序的退出:3.2 程序源代码//学生信息管理系统#include<iostream>#include<malloc.h>#include<iomanip>#define NULL 0#define LEN sizeof(struct student)//建立动态链表.cppusing 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;cin>>p1->num>>p1->name>>p1->sex>>p1->math>>p1->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);cin>>p1->num>>p1->name>>p1->sex>>p1->math>>p1->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->num<<setw(6)<<p->name<<setw(5)<<p->sex< <setw(5)<<p->math<<setw(4)<<p->english<<setw(5)<<p->math+p->english<<resetiosflags( 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<<"请输入要删除的序号:";cin>>num;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;}else{if(strcmp(p1->sex,"男")==0) male--;else famale--;p2->next=p1->next;}cout<<num<<"号已被删除"<<endl;n--;}else cout<<"未找到此数据!"<<endl;cout<<"请输入要删除的序号";cin>>num;}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;cin>>stu->num>>stu->name>>stu->sex>>stu->math>>stu->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{while(p0->num>p1->num&&p1->next!=NULL){p2=p1;p1=p1->next;}if(p0->num<p1->num){if(head==p1){head=p0;}else p2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;}}stu=(struct student*)malloc(LEN);cin>>stu->num>>stu->name>>stu->sex>>stu->math>>stu->english;}return head;}//根据学号查找void SearchNum(struct student *head){int num;struct student *p;p=head;cout<<"请输入要查找的学生的“学号”:";cin>>num;while(p->num!=num&&p->next!=NULL){p=p->next;}if(p->num==num){cout<<"该生的信息为:"<<endl;cout<<"名次 "<<"学号 "<<"姓名 "<<"性别 "<<"数学 "<<"英语 "<<"总分"<<endl;cout<<""<<setiosflags(ios_base::left)<<setw(4)<<p->order<<setw(4)<<p->num<<setw(6)<<p->nam e<<setw(5)<<p->sex<<setw(5)<<p->math<<setw(4)<<p->english<<setw(5)<<p->math+p->engl ish<<resetiosflags(ios_base::left)<<endl<<endl<<endl;}else cout<<"无该生!"<<endl<<endl<<endl;}//根据姓名查找void SearchName(struct student *head){struct student *p;p=head;char name[20];cout<<"请输入要查找的学生的“姓名”:";cin>>name;while(strcmp(p->name,name)!=0&&p->next!=NULL){p=p->next;}if(strcmp(p->name,name)==0){cout<<"该生的信息为:"<<endl;cout<<"名次 "<<"学号 "<<"姓名 "<<"性别 "<<"数学 "<<"英语 "<<"总分"<<endl;cout<<""<<setiosflags(ios_base::left)<<setw(4)<<p->order<<setw(4)<<p->num<<setw(6)<<p->nam e<<setw(5)<<p->sex<<setw(5)<<p->math<<setw(4)<<p->english<<setw(5)<<p->math+p->engl ish<<resetiosflags(ios_base::left)<<endl<<endl<<endl;}else cout<<"无该生!"<<endl<<endl<<endl;}//按成绩排序struct student *sort(struct student *head){struct student *p1,*p2,*p0;float max;char temp[20];int NO=0;p0=head;p2=head;p1=p2->next;max=(p2->math+p2->english);while(p0->next!=NULL){while(p1!=NULL){if((p1->math+p1->english)>max){max=(p1->math+p1->english);p2=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,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;return head;}//链表的输出void print2(struct student *head){cout<<"此时链表的内容为:"<<endl;cout<<"名次 "<<"学号 "<<"姓名 "<<"性别 "<<"数学 "<<"英语 "<<"总分"<<endl;struct student *p;p=head;int No=1;if(head!=NULL)do{cout<<""<<setiosflags(ios_base::left)<<setw(4)<<No<<setw(4)<<p->num<<setw(6)<<p->name<<set w(5)<<p->sex<<setw(5)<<p->math<<setw(4)<<p->english<<setw(5)<<p->math+p->english<<r esetiosflags(ios_base::left)<<endl;p=p->next;No++;}while(p!=NULL);cout<<endl<<endl<<endl;}//主函数int main(){struct student *head;int a;cout<<endl<<endl<<endl<<" 欢迎使用学生信息管理系统"<<endl<<endl<<endl;cout<<" 1、创建链表并按总成绩排序"<<endl;cout<<" 2、根据学号来查询学生信息"<<endl;cout<<" 3、根据姓名来查询学生信息"<<endl;cout<<" 4、删除学生(删后自动排序)"<<endl;cout<<" 5、添加学生(添后自动排序)"<<endl;cout<<" 6、计算总人数及男女生人数"<<endl;cout<<" 0、结束程序"<<endl<<endl<<endl<<endl<<endl;while(a){cout<<"请输入操作序号: 1创建 2按号查找 3按名查找 4删除 5添加 6总数 0结束程序:";cin>>a;if(a==0)cout<<"已经退出程序!"<<endl;if(a>6)cout<<"无该选项,请从0~6中选择"<<endl<<endl<<endl;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<<"人"<<endl<<endl<<endl;break;}}return 0;}3.3 本章小结本章是效果展示,并附加了实现本效果的关键代码,通过实现效果便于用户对本系统有个初步的了解。