《课程设计-(c语言)学生成绩管理系统(共13页).doc》由会员分享,可在线阅读,更多相关《课程设计-(c语言)学生成绩管理系统(共13页).doc(13页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上湖北师范学院 信息工程班 朱文峰完整程序# include # include # include typedef struct student char num10; /学号char name10; /姓名int chinese; int math; int english; int computer;int total; /总分float ave; /平均分STU;/单链表实现typedef struct node struct student data; /数据域struct node * next; /指针域 NODE, * PNODE; /主菜单void m
2、enu1() printf(n * 欢迎进入学生成绩管理系统 *nn);printf( 湖北师范学院 信工班nn);void menu2()printf( *nn);printf( 1 增加数据 2 删除数据 n);printf( 3 查找信息 4 修改信息 n);printf( 5 顺序显示 6 统计数据nn);printf( *n);/保存学生信息void save(PNODE list)FILE *fp;NODE *p;fp = fopen(student, wb);/只写方式打开二进制文件if(fp = NULL) printf(n文件操作错误n);return ;p = list -
3、 next;while(p)if(fwrite(p,sizeof(NODE),1,fp) = 1) p = p - next;elsebreak;fclose(fp); /增加学生信息void add(PNODE list)NODE *p, *r, *s; char flag = 0, num10, name10;int a,b,c,d;/各门成绩char ch;r = list;while(r - next != NULL)r = r - next;/将指针移到链表末尾while(1)while(1) printf(n 请依次输入学号,姓名,语文,数学,英语,计算机的成绩,用空格隔开:n);
4、printf( );scanf(%s%s%d%d%d%d,num,name,&a,&b,&c,&d); flag = 0;s = list - next;while(s)/检查该学号是否已经存在if(strcmp(s - data.num, num) = 0)flag = 1;break;s = s - next;if(1 = flag) printf( 您输入的学号已存在,请重新输入:);continue;break;p = (PNODE)malloc(sizeof(NODE); if(!p)printf(内存错误n); return ; strcpy(p - data.num, num);
5、strcpy(p - data.name, name); p - data.chinese = a;p - data.math = b;p - data.english = c;p - puter = d;p - data.total = a + b + c + d;p - data.ave = (a + b + c + d) / 4.0;p - next = NULL; r - next = p; /将新结点挂在尾结点后面r = p;save(list);printf( 保存成功! 是否继续操作?: );getchar();scanf(%c, &ch);if(ch = y | ch = Y)
6、continue;elsereturn;/打印某个学生的信息void pri(NODE *r)printf( 学号 姓名 语文 数学 英语 计算机 平均分 总分n);printf( %-7s%5s%4d%5d%5d%6d%9.2f%5dn,r-data.num, r-data.name, r-data.chinese, r-data.math,r-data.english, r-puter, r-data.ave, r-data.total);/遍历链表void traverse(PNODE list)PNODE p;p = list - next;printf( 学号 姓名 语文 数学 英语
7、 计算机 平均分 总分n);while(p != NULL)printf( %-7s%5s%4d%5d%5d%6d%9.2f%5dn,p-data.num, p-data.name, p-data.chinese, p-data.math,p-data.english, p-puter, p-data.ave, p-data.total);p = p - next;return ;/按学号排序学生信息并显示void dis(PNODE list)char ch;PNODE p, r;STU stu;if(!list - next)printf( 没有可用数据!n);return ;for(p
8、= list - next; p - next != NULL; p = p - next)for(r = p - next; r != NULL; r = r - next)if(strcmp(p-data.num, r-data.num) 0)stu = p - data;p - data = r - data;r - data = stu;printf( -n);traverse(list);printf( -n);printf( 是否返回继续操作?: );getchar();scanf(%c, &ch);if(ch = y | ch = Y)return;elseexit(0);/查找
9、学生信息void find(PNODE list)char num10, ch;NODE *r;int f = 0;while(1)r = list - next;printf( 请输入学号或姓名: );scanf(%s, num);while(r)if(strcmp(r - data.num, num) = 0) f = 1;pri(r);break;else if(strcmp(r - data.name, num) = 0) f = 1;pri(r);r = r - next;if(!f)printf( 没有找到对应信息!n);printf( 是否继续操作?: );getchar();s
10、canf(%c, &ch);if(ch = y | ch = Y)continue;elsereturn;/删除学生数据void del(PNODE list)while(1)PNODE r, p;char num10, ch;printf( 请输入学号或姓名: );scanf(%s, num);r = list - next;p = list;while(r)if(strcmp(r - data.num, num) = 0 | strcmp(r - data.name, num) = 0)while(p - next != r)p = p - next;p - next = r - next
11、;r = r - next;printf( 删除成功!是否继续执行删除?: );save(list);getchar();scanf(%c, &ch);if(ch = y | ch = Y)continue;elsereturn;/修改学生信息void modi(PNODE list)while(1)PNODE r;int a, b, c, d;char num10, ch;printf( 请输入学号或姓名: );scanf(%s, num);r = list - next;while(r)if(strcmp(r - data.num, num) = 0 | strcmp(r - data.n
12、ame, num) = 0)pri(r);printf( 请依次输入各门成绩:);scanf(%d%d%d%d, &a, &b, &c, &d);r - data.chinese = a;r - data.math = b;r - data.english = c;r - puter = d;r = r - next;printf( 修改成功!是否继续修改?: );save(list);getchar();scanf(%c, &ch);if(ch = y | ch = Y)continue;elsereturn;/平均分排序,不及格学生课程显示/各门成绩最高分,最低分,平均分void sta(
13、PNODE list)PNODE p, r;STU stu;char ch;int f = 0, count = 0;int ave_ch = 0, ave_ma = 0, ave_en = 0, ave_co = 0;int max_ch, max_ma, max_en, max_co;int min_ch, min_ma, min_en, min_co;char name_max_ch10, name_max_ma10, name_max_en10, name_max_co10;char name_min_ch10, name_min_ma10, name_min_en10, name_m
14、in_co10;if(!list - next)printf( 没有可用数据!n);return ;for(p = list - next; p - next != NULL; p = p - next)for(r = p - next; r != NULL; r = r - next)if(p-data.ave data.ave)stu = p - data;p - data = r - data;r - data = stu;printf(n 按平均分排名为: n);printf( -n);traverse(list);printf( -nn);/不及格统计p = list - next;
15、while(p)if(p-data.chinese data.name, p-data.chinese);if(p-data.math data.name, p-data.math);if(p-data.english data.name, p-data.english);if(p-puter data.name, p-puter);p = p - next;count +;if(!f)printf( 全部及格n);printf(n);/各门成绩平均分p = list - next;while(p)ave_ch = ave_ch + p-data.chinese / count;ave_ma
16、= ave_ma + p-data.math / count;ave_en = ave_en + p-data.english / count;ave_co = ave_co + p-puter / count;p = p - next;printf( 各科平均分为:n);printf( -n);printf( 语文 数学 英语 计算机n);printf( %d %d %d %dn, ave_ch, ave_ma, ave_en, ave_co);/各门成绩最高分,最低分p = list - next;max_ch = min_ch = p-data.chinese;max_ma = min_
17、ma = p-data.math;max_en = min_en = p-data.english;max_co = min_co = p-puter;strcpy(name_max_ch, p-data.name);strcpy(name_max_ma, p-data.name);strcpy(name_max_en, p-data.name);strcpy(name_max_co, p-data.name);strcpy(name_min_ch, p-data.name);strcpy(name_min_ma, p-data.name);strcpy(name_min_en, p-data
18、.name);strcpy(name_min_co, p-data.name);while(p)if(p-data.chinese max_ch)max_ch = p-data.chinese;strcpy(name_max_ch, p-data.name);if(p-data.chinese data.chinese;strcpy(name_min_ch, p-data.name);if(p-data.math max_ma)max_ma = p-data.math;strcpy(name_max_ma, p-data.name);if(p-data.math data.math;strcp
19、y(name_min_ma, p-data.name);if(p-data.english max_en)max_en = p-data.english;strcpy(name_max_en, p-data.name);if(p-data.english data.english;strcpy(name_min_en, p-data.name);if(p-puter max_co)max_co = p-puter;strcpy(name_max_co, p-data.name);if(p-data.chinese puter;strcpy(name_min_co, p-data.name);p
20、 = p - next;printf(n 各门成绩最高分,最低分:n);printf( -n);printf( 最高分 最低分n);printf( 语文: );printf(%s %d %s %dn,name_max_ch, max_ch, name_min_ch, min_ch);printf( 数学: );printf(%s %d %s %dn,name_max_ma, max_ma, name_min_ma, min_ma);printf( 英语: );printf(%s %d %s %dn,name_max_en, max_en, name_min_en, min_en);printf
21、( 计算机: );printf(%s %d %s %dn,name_max_co, max_co, name_min_co, min_co);printf( -n);printf(nn 是否继续操作?: );getchar();scanf(%c, &ch);if(ch = y | ch = Y)return;elseexit(0);/主函数void main()PNODE list; /定义链表FILE *fp; int s; /选择变量int count = 0;/结点个数 NODE *p, *r; list = (PNODE)malloc(sizeof(NODE); if(!list) p
22、rintf(内存出错!n); exit(0); list - next = NULL;r = list; fp = fopen(student,ab+); /可读可写,文件不存在则创建文件 if(fp = NULL)printf(n文件出错n);exit(0);while(!feof(fp)/如果没有到文件尾p = (PNODE)malloc(sizeof(NODE);if(!p)printf(内存出错!n); exit(0); if(fread(p,sizeof(NODE),1,fp) = 1)p - next = NULL;r - next = p;r = p; count +;fclos
23、e(fp); menu1();printf(n 文件打开成功,已有%d个记录n, count);while(1)menu2();printf(n 请选择对应操作:); scanf(%d, &s);switch(s)case 1:add(list); break; /增加case 2:del(list); break; /删除case 3:find(list);break; /查询 case 4:modi(list); break; /修改case 5:dis(list); break; /显示case 6:sta(list); break;/统计default: printf(n您的输入有误,请重新输入:n); break; 专心-专注-专业