收藏 分销(赏)

c语言学生成绩管理系统(链表版).docx

上传人:xrp****65 文档编号:5911793 上传时间:2024-11-23 格式:DOCX 页数:34 大小:25.69KB
下载 相关 举报
c语言学生成绩管理系统(链表版).docx_第1页
第1页 / 共34页
c语言学生成绩管理系统(链表版).docx_第2页
第2页 / 共34页
c语言学生成绩管理系统(链表版).docx_第3页
第3页 / 共34页
c语言学生成绩管理系统(链表版).docx_第4页
第4页 / 共34页
c语言学生成绩管理系统(链表版).docx_第5页
第5页 / 共34页
点击查看更多>>
资源描述

1、#include #include #include #include #include #include #define YES 1#define NO 0typedef structint num;float math_score;float engl_score;float chin_score;float phy_score;float chem_score;double aver_score;double sum_score;char sex;StudentDate;/学生基本信息typedef struct studentchar name20;/学生姓名StudentDate o

2、ne;/学生其他信息int rank;/成绩排名struct student *next;Student, *List;Student *startCheck(void);/开始检查Student *createListHead(void);/创建链表的头void menu(void);/主菜单void sortList(Student *pHead);/排序链表void readListWithFile(Student *pHead, char *file_name);/从文件中读取数据,并保存在链表中void sorttList(Student *pHead);/排序链表int userC

3、hioce(Student *pHead);/用户选择int sortMenu(void);/打印选择菜单void passwordCheck(void);/密码检测void correctWord(void);/修改密码void addStudentInfo(Student *pHead);/向链表的末尾添加数据int scanMenu(void);/浏览菜单void findStudentInfo(Student *pHead);/查找学生信息void delStudentInfo(Student *pHead);/删除某一个学生信息void alterStudentInfo(Studen

4、t *pHead);/修改学生信息void saveList(Student *pHead);/将链表保存在文件里void printList(Student *pHead);/打印链表void statisStudentInfo(Student *pHead);/查看学生信息int statisMenu(void);/查看菜单void gotoxy(int x, int y);/改变光标位置函数void inputData(Student *pHead, Student *node);/输入信息,并检测是否合法int main(void)Student *pHead;HANDLE hOut

5、= GetStdHandle(STD_OUTPUT_HANDLE);/得到窗口句柄SMALL_RECT rc = 0, 0, 94 - 1, 30 - 1 ; /Y位置,X位置,宽,高SetConsoleWindowInfo(hOut, true, &rc);/ 重置窗口位置和大小system(color 5B);/设置控制台颜色pHead = startCheck();/读取信息while (1)if (9 = userChioce(pHead) /按9时退出系统break;return 0;void menu(void)system(CLS);/清屏printf(nnnttttn);pri

6、ntf(tttt 学生成绩统计系统 n);printf(ttttn);printf(tttt 1 增加学生记录 n);printf(ttttn);printf(tttt 2 删除学生记录 n);printf(ttttn);printf(tttt 3 修改学生记录 n);printf(ttttn);printf(tttt 4 查找学生信息 n);printf(ttttn);printf(tttt 5 统计学生成绩 n);printf(ttttn);printf(tttt 6 查看学生成绩 n);printf(ttttn);printf(tttt 7 修改登陆密码 n);printf(ttttn)

7、;printf(tttt 8 关于 n);printf(ttttn);printf(tttt 9 退出系统 n);printf(ttttn);void gotoxy(int x, int y)/x为列坐标,y为行坐标COORD pos = x, y ;HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(hOut, pos);Student *startCheck(void)Student *pHead;FILE *fp1;char password20 = 123456;int i;if (fp1 = f

8、open(password.dat, rb) = NULL)/若密码文件不存在,新建密码文件fp1 = fopen(password.dat, wb);fwrite(password, 20, 1, fp1);fclose(fp1);printf(密码初始化完成!(默认密码为:123456));passwordCheck();elsepasswordCheck();/读条system(CLS);system(title 学生成绩统计系统-载入中);/将标题栏命名为“学生成绩统计系统”printf(nnttt欢迎进入本系统!正在载入.);printf(nnnntttn);printf(ttt n

9、);printf(tttn);gotoxy(26, 7);for ( i = 0; i next = NULL;return pHead;void readListWithFile(Student *pHead, char *file_name)FILE *fp;Student *p1, *p2;int count, rank = 0;StudentDate dat;char stu_name20;fp = fopen(file_name, r);if (fp = NULL)fp = fopen(file_name, w);fclose(fp);return;fseek(fp, 0L, 2);

10、count = ftell(fp);p1 = pHead;fp = fopen(file_name, r);while (!feof(fp)p2 = (List)malloc(sizeof(Student);fscanf(fp, %d%s %c%f%f%f%f%fn, &p2-one.num, p2-name, &p2-one.sex, &p2-one.chin_score,&p2-one.math_score, &p2-one.engl_score, &p2-one.chem_score, &p2-one.phy_score);p2-one.sum_score = (double)(p2-o

11、ne.chin_score + p2-one.chin_score + p2-one.engl_score +p2-one.chem_score + p2-one.phy_score);p2-one.aver_score = p2-one.sum_score / 5;p2-next = NULL;p1-next = p2;p1 = p2;if (ftell(fp) = count)break;/将链表排序,并初始化排名for (p1 = pHead-next; p1 != NULL; p1 = p1-next)for (p2 = p1-next; p2 != NULL; p2 = p2-nex

12、t)if (p2-one.aver_score p1-one.aver_score)dat = p2-one;strcpy(stu_name, p2-name);p2-one = p1-one;strcpy(p2-name, p1-name);p1-one = dat;strcpy(p1-name, stu_name);p1-rank = +rank;fclose(fp);void sortList(Student *pHead)Student *p1, *p2;StudentDate dat;char stu_name20;int bum, count = 0, rank;system(ti

13、tle 学生成绩统计系统-查看);/将标题栏命名为“学生成绩统计系统”bum = sortMenu();if (bum = 1)/按平均分高低排序for (p1 = pHead-next; p1 != NULL; p1 = p1-next)for (p2 = p1-next; p2 != NULL; p2 = p2-next)if (p2-one.aver_score p1-one.aver_score)dat = p2-one;rank = p2-rank;strcpy(stu_name, p2-name);p2-one = p1-one;p2-rank = p1-rank;strcpy(p

14、2-name, p1-name);p1-one = dat;p1-rank = rank;strcpy(p1-name, stu_name);elseif (bum = 2)/按学号高低排序for (p1 = pHead-next; p1 != NULL; p1 = p1-next)for (p2 = p1-next; p2 != NULL; p2 = p2-next)if (p2-one.num one.num)dat = p2-one;rank = p2-rank;strcpy(stu_name, p2-name);p2-one = p1-one;p2-rank = p1-rank;str

15、cpy(p2-name, p1-name);p1-one = dat;p1-rank = rank;strcpy(p1-name, stu_name);elseif (bum = 3)return;elsesortList(pHead);printList(pHead);void printList(Student *pHead)int count = 0;pHead = pHead-next;system(CLS);printf(tttt计科6班成绩!);printf(nn );printf(n 学号 姓 名 性别语 文数 学英 语化 学物 理平均分总 分名次n);while (pHead)

16、 printf( n);printf( %-5d %-6s %c %5.1f %5.1f %5.1f %5.1f %5.1f %5.1f %5.1f %-3dn, pHead-one.num,pHead-name, pHead-one.sex, pHead-one.chin_score, pHead-one.math_score,pHead-one.engl_score, pHead-one.chem_score, pHead-one.phy_score, pHead-one.aver_score, pHead-one.sum_score, pHead-rank);pHead = pHead-

17、next;count+;printf( n);printf(ttt该班一共%d个人!, count);getch();int userChioce(Student *pHead)int bum;system(title 学生成绩统计系统-主菜单);/将标题栏命名为“学生成绩统计系统”menu();printf(请按键选择: );bum = (int)(getch() - 0);switch (bum)case 1:addStudentInfo(pHead);break;case 2:delStudentInfo(pHead);break;case 3:alterStudentInfo(pHea

18、d);break;case 4:findStudentInfo(pHead);break;case 5:statisStudentInfo(pHead);break;case 9:break;case 6:sortList(pHead);break;case 7:correctWord();break;case 8:MessageBox(NULL, TEXT(特性:进入系统需输入密码,可以修改密码;展示学生信息时,以表格的方式呈现;输入学生信息时,不能输入已存在的学号;以链表、文件为基础;作者:HappyBeers), TEXT(关于), MB_OK);break; default:break

19、;return bum;int sortMenu(void)int bum;system(CLS);printf(nnn);printf(ttn);printf(tt 以什么方式查询 ? n);printf(ttn);printf(tt 1 按成绩的高低 n);printf(ttn);printf(tt 2 按学号的升次 n);printf(ttn);printf(tt 3 返回主菜单 n);printf(ttn);printf(请按键选择:);bum = (int)(getch() - 0);system(CLS);return bum;void passwordCheck(void)cha

20、r password20, inputword20;int i = 0, j = 0;char c = 0;FILE *fp = fopen(password.dat, rb);system(title 学生成绩统计系统-密码输入);/将标题栏命名为“学生成绩统计系统”fread(password, 20, 1, fp);for (i = 0; i 5; i+)j = 0;printf(nnntt你还有%d次机会输入正确密码: , 3-i);printf(nnnntttn);printf(ttt n);printf(tttn);gotoxy(26, 8);while (c = getch()

21、!= 13 & j 0)putchar(b);putchar( );putchar(b);j-;elseif (isprint(c)/isprint为检测C是否为可打印的函数 putchar(*);inputwordj = c;j+;inputwordj = 0;if (strcmp(inputword, password) = 0)return;elsesystem(CLS);printf(ttt密码输入错误);if (5 = i)system(CLS);printf(nnntt你已浪费所有机会!程序即将退出!);Sleep(2000);exit(0);fclose(fp);system(C

22、LS);return;void correctWord(void)char password20;FILE *fp;int i = 0;char c;system(title 学生成绩统计系统-修改密码);/将标题栏命名为“学生成绩统计系统”system(CLS);printf(nnnnttt请输入新的密码:);while (c = getch() != 13 & i 0)putchar(b);putchar( );putchar(b);i-;elseif (isprint(c)/isprint为检测C是否为可打印的函数 putchar(*);passwordi = c;i+;password

23、i = 0;printf(nttt是否将密码修改为? Y or N:, password);c = getch();if (c = Y | c = y)fp = fopen(password.dat, wb);fwrite(password, 20, 1, fp);fclose(fp);printf(nttt修改成功!n);elsereturn;getch();void addStudentInfo(Student *pHead)FILE *fp;Student *p1, *p2, *p3 = pHead;StudentDate dat;int judge = YES, rank = 0;ch

24、ar bum, stu_name20;system(title 学生成绩统计系统-添加);/将标题栏命名为“学生成绩统计系统”fp = fopen(stud.dat, a);while (pHead-next)pHead = pHead-next;while (judge)p1 = (List)malloc(sizeof(Student);inputData(p3, p1);p1-next = NULL;pHead-next = p1;pHead = p1;fprintf(fp, %d %s %c %.1f %.1f %.1f %.1f %.1fn, p1-one.num, p1-name,

25、p1-one.sex, p1-one.chin_score,p1-one.math_score, p1-one.engl_score, p1-one.chem_score, p1-one.phy_score);printf(是否继续添加?(Y/N);bum = getch();if (bum = n | bum = N)break;/并交换排名for (p1 = p3-next; p1 != NULL; p1 = p1-next)for (p2 = p1-next; p2 != NULL; p2 = p2-next)if (p2-one.aver_score p1-one.aver_score

26、)dat = p2-one;strcpy(stu_name, p2-name);p2-one = p1-one;strcpy(p2-name, p1-name);p1-one = dat;strcpy(p1-name, stu_name);p1-rank = +rank;fclose(fp);int scanMenu(void)int bum;system(CLS);printf(nnn);printf(ttn);printf(tt 以什么方式查询 ? n);printf(ttn);printf(tt 1 按学生的学号 n);printf(ttn);printf(tt 2 按学生的姓名 n);

27、printf(ttn);printf(tt 3 返回主菜单 n);printf(ttn);printf(请按键选择:);bum = (int)(getch() - 0);system(CLS);return bum;void findStudentInfo(Student *pHead)int bum, count = 0;int num;char student_name20;pHead = pHead-next;system(title 学生成绩统计系统-查找);/将标题栏命名为“学生成绩统计系统”bum = scanMenu();if (bum = 1)printf(请输入学生的学号:)

28、;scanf(%d, &num);while (pHead)if (pHead-one.num = num)if (count = 0)printf(nttt已经查到!n);printf(nnnn );printf(n 学号 姓 名 性别语 文数 学英 语化 学物 理平均分总 分名次n);count = 1;printf( n);printf( %-5d %-6s %c %5.1f %5.1f %5.1f %5.1f %5.1f %5.1f %5.1f %-3dn, pHead-one.num,pHead-name, pHead-one.sex, pHead-one.chin_score, p

29、Head-one.math_score,pHead-one.engl_score, pHead-one.chem_score, pHead-one.phy_score, pHead-one.aver_score, pHead-one.sum_score, pHead-rank);break;pHead = pHead-next;if (pHead = NULL)printf(nttt没有该学生记录!n);elseprintf( n);elseif (bum = 2)printf(请输入学生姓名:);scanf(%s, student_name);while (pHead)if (strcmp(

30、student_name, pHead-name) = 0)if (count = 0)printf(nttt已经查到!n);printf(nnnn );printf(n 学号 姓 名 性别语 文数 学英 语化 学物 理平均分总 分名次n);count = 1;printf( n);printf( %-5d %-6s %c %5.1f %5.1f %5.1f %5.1f %5.1f %5.1f %5.1f %-3dn, pHead-one.num,pHead-name, pHead-one.sex, pHead-one.chin_score, pHead-one.math_score,pHea

31、d-one.engl_score, pHead-one.chem_score, pHead-one.phy_score, pHead-one.aver_score, pHead-one.sum_score, pHead-rank);pHead = pHead-next;if (count = 0)printf(nttt没有该学生记录!);elseprintf( n);elseif (bum = 3)return;elsefindStudentInfo(pHead);getch();void delStudentInfo(Student *pHead)Student *p1, *p2 = pHead;int bum;int num, count = 0;char student_name20, c;system(title 学生成绩统计系统-删除);/将标题栏命名为“学生成绩统计系统”bum = scanMenu();if (bum = 1)p1 = pHead-next;printf(nttt请输入要删除学生的学号:);scanf(%d, &num);while (p1)if (p1-one.num = num)count = 1;printf(n

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
搜索标签

当前位置:首页 > 通信科技 > 开发语言

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服