1、学生成绩管理系统报告课程设计报告课程名称: 数据结构课程设计 设计题目: 学生成绩管理系统 学 院: 信息科学与工程学院 专 业: 计算机科学与技术 姓 名: 指导教师: 二零一三年十二月二十七日一、 设计内容及要求设计内容:利用线性链表实现学生成绩管理系统具体要求:(1)可以对所有学生的信息输入,并保存在文件中。可以输出显示学生信息。 (2)可以插入、删除、查找、追加学生信息。二、 算法设计 程序的总体框架 二、 算法实现#include#include#includestruct students char Num10; /*字符型学生学号*/ char Name20; /*学生姓名*/
2、char Sex3; /*学生性别*/ double English; /*双精度型英语成绩*/ double riyu; /*日语成绩*/ double Sjjg; /*数据结构成绩*/ double tiyu; /*体育成绩*/ double shuxue; /*离散数学成绩*/ struct students *next; /*用与构建连表指向下一结点*/;void menu();/*主菜单*/void Xiugaimenu();/*修改菜单*/struct students *Input();/*新建学生信息*/void fprint(struct students *head);/*
3、将信息导入文件*/void fprint_(struct students *head);/*将信息导入文件并覆盖*/void Xianshi(struct students *head);/*浏览全部学生信息*/struct students *create(struct students *head);/*从文件读取数据构建链表*/void FindofNum(struct students *head);/*按学号查询学生信息*/void FindofNname(struct students *head);/*按姓名查询学生信息*/struct students *Insert(str
4、uct students *head);/*根据姓名插入学生信息*/struct students *Delete(struct students *head);/*按学号删除学生成绩信息*/struct students * Xiugai();/*修改学生信息*/*主菜单*/void menu() printf(nn); printf(*n); printf( 学生成绩管理系统 n); printf(-n); printf( 1-添加新同学 2-显示学生信息 n); printf( 3-按学号查找 4-按姓名查找 n); printf( 5-插入新同学 6-修改学生信息 n); printf
5、( 7-删除学生信息 0-退出系统 n); printf(-n); printf(_n);/*修改菜单*/void Xiugaimenu() printf(nn); printf( 1-修改学生姓名 2-修改学生学号 n); printf( 3-修改学生性别 4-修改英语成绩 n); printf( 5-修改日语成绩 6-修改数据结构 n); printf( 7-修改体育成绩 8-修改数学成绩 n); printf( 0-返回上级菜单 n); printf(nn);/*新建学生信息*/struct students *Input() struct students *p1,*p2,*head;
6、 /*建立结点及头结点*/ char Name; int x; printf(n请按对应项输入学生信息以#结束:n); printf(姓名 学号 性别 英语 日语 数据结构 体育成绩 离散数学成绩n); p1=(struct students *)malloc(sizeof(struct students); head=p2=p1; do /*输入学生信息*/ scanf(%s,&p1-Name); if(strcmp(p1-Name,#)=0) break; else scanf(%s%s%lf%lf%lf%lf%lf,p1-Num,p1-Sex,&p1-English,&p1-riyu,&
7、p1-Sjjg,&p1-tiyu,&p1-shuxue); p1=(struct students *)malloc(sizeof(struct students); p2-next=p1; p2=p1; while(1); p1-next=NULL; printf(学生信息输入结束!n); printf(是否保存学生信息?(1.是/2.否):); scanf(%d,&x); if(x=1) fprint(head); /*调用函数保存至文件*/ else printf(n文件没有被保存!n); return head; /*返回头指针*/*将信息导入文件*/void fprint(struc
8、t students *head) struct students *p1; FILE *fp; if(fp=fopen(h:students_list.txt,a)=NULL) printf(File open error!n); exit(0); for(p1=head;p1-next!=NULL;p1=p1-next) /*遍历*/ fprintf(fp,%st%st%st%.1lft%.1lft%.1lft%.1lft%.1lfn,p1-Name,p1-Num,p1-Sex,p1-English,p1-riyu,p1-Sjjg,p1-tiyu,p1-shuxue);/*将学生信息写入文
9、件*/ fclose(fp); /*关闭文件*/ printf(n学生信息已成功保存到文件 students_list.txt 中!n);/*将信息导入文件并覆盖*/void fprint_(struct students *head) struct students *p1; FILE *fp; if(fp=fopen(h:students_list.txt,w)=NULL) printf(File open error!n); exit(0); for(p1=head;p1!=NULL;p1=p1-next) /*遍历*/ fprintf(fp,%st%st%st%.1lft%.1lft%
10、.1lft%.1lft%.1lfn,p1-Name,p1-Num,p1-Sex,p1-English,p1-riyu,p1-Sjjg,p1-tiyu,p1-shuxue);/*将学生信息写入文件*/ fclose(fp); /*关闭文件*/;/*浏览全部学生信息*/void Xianshi(struct students *head) char Num10; /*字符型学生学号*/ char Name20; /*学生姓名*/ char Sex3; /*学生性别*/ double English; /*双精度型英语成绩*/ double riyu; /*日语成绩*/ double Sjjg; /
11、*数据结构成绩*/ double tiyu; /*体育成绩*/ double shuxue; /*离散数学成绩*/ FILE *fp; if(fp=fopen(h:students_list.txt,r)=NULL) printf(File open error!n); exit(0); printf(-n); printf(姓名 学号 性别 英语 日语 数据结构 体育成绩 离散数学n); while(!feof(fp)/*当源文件未结束时进行循环*/ fscanf(fp,%s%s%s%lf%lf%lf%lf%lf,Name,Num,Sex,&English,&riyu,&Sjjg,&tiyu
12、,&shuxue); printf(%st%st%st%.1lft%.1lft%.1lft%.1lft%.1lfn,Name,Num,Sex,English,riyu,Sjjg,tiyu,shuxue); ; fclose(fp);/*从文件中读取数据构建链表*/struct students *create(struct students *head) FILE *fp; struct students *p,*p1,*p2; if(fp=fopen(h:students_list.txt,a+)=NULL) printf(File open error!n); exit(0); while
13、(!feof(fp) /当源文件未结束时进行循环 p=(struct students *)malloc(sizeof(struct students); fscanf(fp,%s%s%s%lf%lf%lf%lf%lf,p-Name,p-Num,p-Sex,&p-English,&p-riyu,&p-Sjjg,&p-tiyu,&p-shuxue); if(head=NULL) head=p; p1=p; else p1-next=p; p2=p1; p1=p; p2-next=NULL; free(p); fclose(fp); return head;/*按姓名查询学生信息*/void Fi
14、ndofName(struct students *head) int i=0; char b20; struct students *p; head=create(head); p=head; printf(n请输入要查询的学生姓名:); scanf(%s,b); while(p!=NULL) if(strcmp(p-Name,b)=0) printf(姓名 学号 性别 英语 日语 数据结构 体育成绩 离散数学n); printf(%st%st%st%.1lft%.1lft%.1lft%.1lft%.1lfn,p-Name,p-Num,p-Sex,p-English,p-riyu,p-Sjj
15、g,p-tiyu,p-shuxue); i+; p=p-next; if(i=0) printf(n对不起!没有找到名为%s的学生信息!n,b);/*按学号查询学生信息*/void FindofNum(struct students *head) int i=0; char b20; struct students *p; head=create(head); p=head; printf(n请输入要查询的学生学号:); scanf(%s,b); while(p!=NULL) if(strcmp(p-Num,b)=0) printf(姓名 学号 性别 英语 日语 数据结构 体育成绩 离散数学n
16、); printf(%st%st%st%.1lft%.1lft%.1lft%.1lft%.1lfn,p-Name,p-Num,p-Sex,p-English,p-riyu,p-Sjjg,p-tiyu,p-shuxue); i+; p=p-next; if(i=0) printf(n对不起!没有找到学号为%s学生信息!n,b);/*插入学生信息*/struct students *Insert(struct students *head) struct students *p0,*p1,*p2; char b20; Xianshi(head); head=create(head); p0=(st
17、ruct students *)malloc(sizeof(struct students); p0-next=NULL; printf(插入指定姓名前面: ); scanf(%s,b); printf(姓名 学号 性别 英语 日语 数据结构 体育成绩 离散数学n); scanf(%s%s%s%lf%lf%lf%lf%lf,p0-Name,p0-Num,p0-Sex,&p0-English,&p0-riyu,&p0-Sjjg,&p0-tiyu,&p0-shuxue);/将学生信息写入文件 getchar(); if(head=NULL) head=p0; else p1=head; while
18、(strcmp(p1-Name,b)!=0)&(p1-next!=NULL) p2=p1; p1=p1-next; if(strcmp(p1-Name,b)=0) p2-next=p0; p0-next=p1; else p1-next=p0; fprint_(head); printf(n姓名为 %s 学生信息已被插入指定姓名前,并保存至文件!n,p0-Name); return head;/*按学号删除学生成绩信息*/struct students *Delete(struct students *head) struct students *p1,*p2; char m15; print
19、f(n所有学生信息如下:n); Xianshi(head); printf(n请输入想要删除的学生学号:); scanf(%s,m); head=create(head); if(head=NULL) printf(无学生信息!n); return head; if(strcmp(head-Num,m)!=0) p1=head; p2=head-next; while(p2!=NULL) if(strcmp(p2-Num,m)=0) p1-next=p2-next; free(p2); else p1=p2; p2=p1-next; fprint_(head); printf(n学号为 %s
20、学生信息已被删除,并保存至文件!n,m); return head;/*修改学生信息(按编号修改)*/struct students *Xiugai() int t; char num10; char Num10; /*字符型学生学号*/ char Name20; /*字符型学生姓名*/ char Sex3; /*字符型学生性别*/ double English; /*双精度实型英语成绩*/ double riyu; /*双精度实型日语成绩*/ double Sjjg; /*双精度实数据结构*/ double tiyu; /*双精度实型体育成绩*/ double shuxue; /*离散数学*
21、/ struct students *head=NULL; struct students *p; printf(n所有学生信息如下:n); Xianshi(head); head=create(head); printf(n输入需要修改的学生的学号:); scanf(%s,num); p=head; while(head!=NULL) if(strcmp(p-Num,num)=0) system(cls); Xiugaimenu(); printf(编号为%s的学生信息如下:n,num); printf(姓名 学号 性别 英语 日语 数据结构 体育成绩 离散数学n); printf(%st%
22、st%st%.1lft%.1lft%.1lft%.1lft%.1lfn,p-Name,p-Num,p-Sex,p-English,p-riyu,p-Sjjg,p-tiyu,p-shuxue); while(1) printf(请选择需要修改的信息:); scanf(%d,&t); switch(t) case 1: printf(请输入新姓名:); scanf(%s,Name); strcpy(p-Name,Name); break; case 2: printf(请输入新学号:); scanf(%s,&Num); strcpy(p-Num,Num); break; case 3: print
23、f(请输入新性别:); scanf(%s,Sex); strcpy(p-Sex,Sex); break; case 4: printf(请输入新英语成绩:); scanf(%lf,&English); p-English=English; break; case 5: printf(请输入新日语成绩:); scanf(%lf,&riyu); p-riyu=riyu; break; case 6: printf(请输入新数据结构成绩:); scanf(%lf,&Sjjg); p-Sjjg=Sjjg; break; case 7: printf(请输入新体育成绩:); scanf(%lf,&tiy
24、u); p-tiyu=tiyu; break; case 8: printf(请输入新数学成绩:); scanf(%lf,&shuxue); p-shuxue=shuxue; break; case 0: system(cls); menu(); goto lab; break; default: printf(对不起,输入有误!); break; else p=p-next; lab: fprint_(head); printf(修改完成,并储存至文件!n); return head;/*主函数*/void main() int choice,ch; char m15; struct stu
25、dents *head=NULL; menu(); while(1) printf(请输入选项:); scanf(%d,&choice); switch(choice) case 1: Input();break; case 2: system(cls); menu(); Xianshi(head);break; case 3: system(cls); menu(); FindofNum(head); break; case 4: system(cls); menu(); FindofName(head); break; case 5: system(cls); menu(); Insert(head); break; case 6: system(cls); menu(); Xiugai(); break; case 7: system(cls); menu(); head=Delete(head); break; case 0: system(cls); printf(tt欢迎下次再来!);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1