C语言学生信息管理系统实验报告.doc
C语言学生信息管理系统实验报告C语言课程设计 学生信息管理系统 姓 名 洪伟生 院 系 计 算 机 学 院 日 期 2015 年 7 月 5 日 目 录第一章 设计要求 第二章 算法分析1. 理论依据2. 主要实现方法2.1 整体流程图2.2 函数功能和函数之间的调用关系第三章 代码(源代码)第四章 分析说明第五章 总结第一章、 设计要求1、利用所学的知识、理论和实际结合,利用资源,采用模块化的结构,使用模仿修改自主设计相结合的方法,锻炼学生综合分析解决实际问题的编程能力;07eJRJJ。2、通过C语言各个函数功能来实现对学生信息的管理,学生信息包括学生姓名,学号,各科成绩;管理方式包括对学生信息的录入,保存,排序,查找、修改、删除等功能。k4v1jtb。第二章、 算法分析1、程序理论依据通过C语言的程序设计基础的掌握,对学生成绩管理系统进行编写程序。首先,通过链表这一数据结构来对学生的信息进行录入以及操作,在其过程中,通过各个功能语句以及选择结构,循环结构等方式的结合来达到所要实现的程序功能。最后通过对C语言中对文件的操作,对已有学生成绩的读取和新建学生成绩的录入保存。GfdlZgd。2、主要实现方法2.1整体流程图学生信息管理系统学生信息删除返回主菜单学生信息增加学生信息修改学生信息查找学生信息浏览学生信息录入进入退出hydkekn。2.2、函数功能和函数之间的调用关系2.2.1、函数功能:void Menu_1(); /主菜单MFOeshz。void Menu_2(); /二级菜单Vb4dQfB。void s student * phead,struct student * pback); / 链表节点互换piEvrKd。void Save(struct student * head); / 写入磁盘cmvv2ib。void Search(struct student * head); / 查找学生信息cEDqt3J。void Read(struct student * head); / 显示学生信息XwMSrop。void Sort(struct student * head); / 链表节点排序zXFP6AO。struct student * Create(); / 学生信息手动录入V46DnXC。struct student * Readpoint(); / 磁盘文件写入内存Bp2MjnR。struct student * Modify(struct student * head); / 链表结构体成员修改HsJ0eOa。struct student * Add(struct student * head); / 链表节点插入1vVufxn。struct student * Delete(struct student * head); / 链表节点删除HiUimc7。2.2.2、函数之间的调用关系:通过switch语句进行指令选择:case 1: 学生信息录入 调用函数 Create( )、Save( )、Menu_1( )、Menu_2( ) case 2: 学生信息浏览调用函数 Readpoint( )、Sort( )、Read( )、Save( )、Menu_1( )、Menu_2( ) AVJTre8。case 3: 学生信息查找 调用函数 Search( )、Readpoint( )、Menu_1( )、Menu_2( )case 4: 学生信息修改 调用函数 Modify( )、Readpoint( )、Save( )、Menu_1( )、Menu_2( )nVJ7X7d。case 5: 学生信息增加调用函数 Add( )、 Readpoint( )、Save( )、Menu_1( )、Menu_2( )Jnv8Rgi。case 6: 学生信息删除调用函数 Delete( ) 、Readpoint( )Save( )、Menu_1( )、Menu_2( )nXtAzAe。case 0: 返回主菜单调用函数 Menu_1( )第三章、 代码(源代码)/* 学生信息管理系统*/#include<stdio.h>#include<stdlib.h>#include<string.h>struct student /定义结构体Nw4iupe。int num;char name24;char sex5;int Chinese;int Math;int English;struct student * next;void Menu_1(); /主菜单void Menu_2(); /二级菜单void s student * phead,struct student * pback); / 链表节点互换0KfiWxl。void Save(struct student * head); / 写入磁盘hMmmE8a。void Search(struct student * head); / 查找学生信息3STy5Oj。void Read(struct student * head); / 显示学生信息xMtado6。void Sort(struct student * head); / 链表节点排序4g49e1r。struct student * Readpoint(); / 磁盘文件写入内存1zN1JR7。struct student * Create(); /学生信息手动录入OvarGMx。struct student * Modify(struct student * head); / 链表结构体成员修改HXS7fLB。struct student * Add(struct student * head); / 链表节点插入sCi2YK4。struct student * Delete(struct student * head); / 链表节点删除aGSkDJm。int main(void)Menu_1(); return 0;void Menu_1()int num;printf("tttt 学生信息管理系统ttttn");printf("ttt 1: 进入学生信息管理n"); /主菜单BjNdLq5。printf("ttt 0: 退出学生信息管理n");printf("请您输入指令:");scanf("%d",&num);switch(num)case 1:Menu_2();break;default:printf("-您已退出学生信息管理系统-n");MUDevVt。break;/*-*/e6U8E5B。void Menu_2() struct student * head;int num;printf("ttt 欢迎进入n");printf("-n");2rw8AOK。printf("ttt 1: 学生信息录入n");printf("ttt 2: 学生信息浏览n");printf("ttt 3: 学生信息查找n");printf("ttt 4: 学生信息修改n"); /二级菜单a2mSUWf。printf("ttt 5: 学生信息增加n");printf("ttt 6: 学生信息删除n");printf("ttt 0: 返回主菜单n");printf("-n");wf2cdzG。printf("请您输入指令:");scanf("%d",&num);switch(num)case 1:head = Create(); Save(head);printf("n");printf("ttt 1: 返回主菜单n"); /手动录入学生数据hte0m3B。printf("ttt 2: 返回二级菜单n");printf("n");printf("请您输入指令:");scanf("%d",&num);switch(num)case 1:Menu_1();break;case 2:Menu_2();break;default :printf("输入无效,返回二级菜单!n");Menu_2();break; break;case 2:head = Readpoint(); /写入链表,返回头指针iW5pSeN。Sort(head);printf("ttt 以学号升序排列n");Read(head); / 链表数据写入文件cCNXhrX。Save(head);printf("n");printf("ttt 1: 返回主菜单n");printf("ttt 2: 返回二级菜单n");printf("n");printf("请您输入指令:");scanf("%d",&num);switch(num)case 1:Menu_1();break;case 2:Menu_2();break;default :printf("输入无效,返回二级菜单!n");Menu_2();break; break;case 3:head = Readpoint();Search(head);/查找学生信息printf("n");printf("ttt 1:返回主菜单n");printf("ttt 2:返回二级菜单n");printf("n");printf("请您输入指令:");scanf("%d",&num);switch(num)case 1:Menu_1();break;case 2:Menu_2();break;default :printf("输入无效,返回二级菜单!n");Menu_2();break; break;case 4:head = Readpoint();Modify(head);/修改结构体成员并保存到文件Save(head);printf("n");printf("ttt 1: 返回主菜单n");printf("ttt 2: 返回二级菜单n");printf("n");printf("请您输入指令:");scanf("%d",&num);switch(num)case 1:Menu_1();break;case 2:Menu_2();break;default :printf("输入无效,返回二级菜单!n");Menu_2();break; break;case 5:head = Readpoint();Add(head);/增加学生信息并保存到文件Save(head);printf("n");printf("ttt 1:返回主菜单n");printf("ttt 2:返回二级菜单n");printf("n");printf("请您输入指令:");scanf("%d",&num);switch(num)case 1:Menu_1();break;case 2:Menu_2();break;default :printf("输入无效,返回二级菜单!n");Menu_2();break; break;case 6:head = Readpoint(); head = Delete(head);/删除学生信息并保存到文件Save(head);printf("n");printf("ttt 1:返回主菜单n");printf("ttt 2:返回二级菜单n");printf("n");printf("请您输入指令:");scanf("%d",&num);switch(num)case 1:Menu_1();break;case 2:Menu_2();break;default :printf("输入无效,返回二级菜单!n");Menu_2();break; break;case 0: Menu_1();break;default :printf("请重新输入n");Menu_2(); break;/*-*/1YzjeNN。struct student * Create() /学生信息手动录入nIKyFTY。 struct student *head,* p,* q;int n;p = q = (struct student *)malloc(sizeof(struct student);jfGxX4e。printf("请输入学生的姓名、学号、性别、语文成绩、高等数学成绩、英语成绩:n");scanf("%s",q->name);scanf("%d %s %d %d %d",&q->num,&q->sex,&q->Chinese,&q->Math,&q->English); B61X2JV。 n = 0; head =NULL;while (q->num != 0)n = n+1;if (n = 1)head = q;elsep->next = q;p = q;q = (struct student *)malloc(sizeof(struct student);jN1ap0c。scanf("%s",q->name);scanf("%d %s %d %d %d",&q->num,q->sex,&q->Chinese,&q->Math,&q->English);BuAFpVj。p->next = NULL;printf("学生信息录入成功!n");return head;/*-*/hDjLVNq。struct student * Readpoint() /学生信息写入内存,便于操作nE2RZP0。FILE * fp1; struct student *head,* p,* q;int n;if(fp1 = fopen("E:test.txt","rb") = NULL) printf("open !n");exit(0);p = q = (struct student *)malloc(sizeof(struct student);yhwSOJW。fscanf(fp1,"%s %d %s %d %d %d",q->name,&q->num,q->sex,&q->Chinese,&q->Math,&q->English);L3anAmP。n = 0;head =NULL;while( !feof(fp1)n = n+1;if (n = 1)head = q;elsep->next = q;p = q;q = (struct student *)malloc(sizeof(struct student);cZZxWt3。fscanf(fp1,"%s %d %s %d %d %d",&q->name,&q->num,&q->sex,&q->Chinese,&q->Math,&q->English);mBpVDpd。p->next = NULL;fclose(fp1);return head;/*-*/PK7oecr。void S student * phead, struct student * pback) /链表元素数据交换VdvU1RA。struct student * temp = (struct student *)malloc(sizeof(struct student);NaDsBQn。strcpy(temp->name,phead->name);temp->num = phead->num;strcpy(temp->sex,phead->sex);temp->Chinese = phead->Chinese;temp->Math = phead->Math;temp->English = phead->English; strcpy(phead->name,pback->name);phead->num= pback->num;strcpy(phead->sex,pback->sex);phead->Chinese = pback->Chinese;phead->Math = pback->Math;phead->English = pback->English; strcpy(pback->name,temp->name);pback->num = temp->num;strcpy(pback->sex,temp->sex);pback->Chinese = temp->Chinese;pback->Math = temp->Math;pback->English = temp->English;free(temp);/*-*/0g9pu7y。void Sort(struct student * head) / 学号排序w2z8tsD。 struct student * phead = (struct student *)malloc(sizeof(struct student);z66ZXcY。struct student * pback = (struct student *)malloc(sizeof(struct student);LzTIrtU。 phead = head;while (phead)int Num = phead->num;pback = phead->next;while(pback) if( Num > pback->num)S);Num = phead->num;pback = pback->next; phead = phead->next;/*-*/pXqRgQ3。void Read(struct student * head) /学生信息读取QtZn35b。 struct student * p;p = head;printf("-n");2w3YcgY。printf("学生的姓名 、 学号 、 性别 、语文成绩 、 高等数学成绩 、 英语成绩:n");eS3yQJQ。while(p != NULL)printf(" %s t%dt%s t %d t %d tt %dn",p->name,p->num,p->sex,p->Chinese,p->Math,p->English);pscoCGh。p = p->next;printf("-n");6ylUvEv。/*-*/KMWhdsL。void Save(struct student * head) /学生信息保存到文件OW1puMD。struct student * p;FILE * fp;if(fp = fopen("E:test.txt","wb") = NULL) printf("open !n");exit(0);p = head;while(p !=NULL)fprintf(fp,"%s %d %s %d %d %d",p->name,p->num,p->sex,p->Chinese,p->Math,p->English);8nzzSat。fprintf(fp,"%s","rn");p = p->next;fclose(fp);/*-*/h3ZO3r1。void Search(struct student * head) /学生信息查找TqO87iQ。int n;struct student * p;char name24;int num;char sex5;int Chinese;int Math;int English;printf("您想以何种方式进行查找:n");printf("1;姓名n");printf("2:学号n");printf("3:性别n");printf("4:语文成绩n");printf("5:数学成绩n");printf("6:英语成绩n");printf("0:返回二级菜单n"); scanf("%d",&n);switch(n)case 1:printf("请输入姓名:"); /按姓名查找Knx8ES5。scanf("%s",name);p = head;while(strcmp(name,p->name)!=0 && p->next != NULL)p = p->next;if(strcmp(name,p->name)=0)printf("%s %d %s %d %d %dn",p->name,p->num,p->sex,p->Chinese,p->Math,p->English);gUBGc50。elseprintf("查无此人!n"); break;case 2:printf("请输入学号:"); /按学号查找8W3lFy9。scanf("%d",&num);p = head;while(num != p->num && p->next != NULL)p = p->next;if(num = p->num)printf("%s %d %s %d %d %dn",p->name,p->num,p->sex,p->Chinese,p->Math,p->English);CFGUCyR。elseprintf("查无此人!n"); break; case 3:printf("请输入性别:"); /按性别查找QBQRbRS。scanf("%s",sex);p = head;while(p!= NULL)if(strcmp(sex,p->sex)=0)printf("%s %d %s %d %d %dn",p->name,p->num,p->sex,p->Chinese,p->Math,p->English);mWZU267。p = p->next; break;case 4:printf("请输入语文成绩:"); /按语文成绩查找n40BRtD。scanf("%d",&Chinese);p = head;while(p!= NULL)if(Chinese = p->Chinese)printf("%s %d %s %d %d %dn",p->name,p->num,p->sex,p->Chinese,p->Math,p->English);UOxGolq。p = p->next; break; case 5:printf("请输入高等数学成绩:"); /按高等数学成绩查找mKr2sOw。scanf("%d",&Math);p = head;while(p!= NULL)if(Math = p->Math)printf("%s %d %s %d %d %dn",p->name,p->num,p->sex,p->Chinese,p->Math,p->English);oPHj9Dz。p = p->next; break; case 6:printf("请输入英语成绩:"); /按英语成绩查找iHUq0G7。scanf("%d",&English);p = head;while(p!= NULL)if(English = p->English)printf("%s %d %s %d %d %dn",p->name,p->num,p->sex,p->Chinese,p->Math,p->English);D61ZMaN。p = p->next; break; default:printf("指令错误返回二级菜单!n");Menu_2();break;/*-