本代码供读者学习使用,请不要随意转载。

一、设计题目:学生成绩管理系统

二、目的与要求
每位学生记录包含有学号、姓名、性别、出生日期、三门功课的成绩(高等数学、大学英语、C语言)、总分和平均分
系统菜单:
(1)录入学生记录
(2)添加学生记录
(3)删除学生记录
(4)修改学生记录(要求输入密码)
(5)查找学生记录(按学号、按姓名)
(6)按总分对记录进行降序排列
(7)将当前结果显示或打印,重新保存进数据文件中
(8)输出所有学生信息
(9)计算班级平均分
(10)修改管理员密码(未保存至文件,程序关闭后失效)
(11)C语言挂科人数
(0)结束程序

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
#define LEN sizeof(struct student)struct student
{struct student *next;long num;char name[8];char sex[4];int year;int month;int day;float c;float math;float eng;float sum;
};int n;
struct student * creat()          //建立基础的学生信息库
{struct student * head,*p1,*p2;n=0;p1=p2=(struct student *)malloc(LEN);printf("输入学生的学号为0时,停止录入.\n");printf("请输入学生学号:");scanf("%ld",&p1->num);if(p1->num!=0){printf("请输入学生姓名:");scanf("%s",p1->name);printf("请输入学生性别:");scanf("%s",p1->sex); printf("请输入学生生日:\n");printf("年:");scanf("%d",&p1->year);printf("月:");scanf("%d",&p1->month);printf("日:");scanf("%d",&p1->day);printf("c语言:");scanf("%f",&p1->c);printf("高数:");scanf("%f",&p1->math);printf("英语:");scanf("%f",&p1->eng);p1->sum=p1->c+p1->eng+p1->math;printf("\n");}while(p1->num!=0){n=n+1;if(n==1){head=p1;}else{p2->next=p1;}p2=p1;p1=(struct student *)malloc(LEN);printf("请输入学生学号:");scanf("%ld",&p1->num);if(p1->num!=0){printf("请输入学生姓名:");scanf("%s",p1->name);printf("请输入学生性别:");scanf("%s",p1->sex);printf("请输入学生生日:\n");printf("年:");scanf("%d",&p1->year);printf("月:");scanf("%d",&p1->month);printf("日:");scanf("%d",&p1->day);printf("c语言:");scanf("%f",&p1->c);printf("高数:");scanf("%f",&p1->math);printf("英语:");scanf("%f",&p1->eng);p1->sum=p1->c+p1->eng+p1->math;printf("\n");}}p2->next=NULL;return head;
}struct student * del(struct student *head,long num) //删除学生信息
{struct student  *p1,*p2;if(head==NULL){printf("\nlist null!\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;elsep2->next=p1->next;printf("你删除的学生信息为:\n");printf("学号:%ld\n",p1->num);printf("姓名:%s\n",p1->name);printf("性别:%s\n",p1->sex);printf("生日:\n");printf("年:%d\n",p1->year);printf("月:%d\n",p1->month);printf("日:%d\n",p1->day);printf("c语言:%5.2f\n",p1->c);printf("高数:%5.2f\n",p1->math);printf("英语:%5.2f\n",p1->eng);p1->sum=p1->c+p1->math+p1->eng;printf("总分:%5.2f\n",p1->sum);printf("\n");n=n-1;}elseprintf("输入有误!\n");return head;
}struct student * insert (struct student *head,struct student *stud) //添加学生信息
{struct student * p0,*p1,*p2;p1=head;p0=stud;if(head==NULL){head=p0;p0->next=NULL;}elsewhile((p0->num>p1->num)&&(p1->next!=NULL)){p2=p1;p1=p1->next;}if(p0->num<=p1->num){if(head==p1)head=p0;elsep2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;}n=n+1;return head;
}void sort(struct student  *head) //排序
{struct student *p, *q, *max;long temp1;char temp2[4],temp9[4];int temp3,temp4,temp5;float temp,temp6,temp7,temp8;p = head;while (p != NULL){max = p;q = p->next;while (q != NULL){if (max->sum < q->sum)max = q;q = q->next;}// 交换值if (max != p){temp = max->sum;max->sum = p->sum;p->sum = temp;temp1=max->num;max->num=p->num;p->num=temp1;strcpy(temp2,max->name);strcpy(max->name,p->name);strcpy(p->name,temp2);temp3=max->year;max->year=p->year;p->year=temp3;temp4=max->month;max->month=p->month;p->month=temp4;temp5=max->day;max->day=p->day;p->day=temp5;temp6=max->c;max->c=p->c;p->c=temp6;temp7=max->math;max->math=p->math;p->math=temp7; temp8=max->eng;max->eng=p->eng;p->eng=temp8;strcpy(temp9,max->sex);strcpy(max->sex,p->sex);strcpy(p->sex,temp9);}p = p->next;}
printf("排序以后的学生信息为:\n");
struct student *p1;p1 = head;
int count=1;
while(p1!=NULL)
{printf("第%d名:\n",count);printf("学号:%ld   ",p1->num);printf("姓名:%s   ",p1->name);printf("生日:");printf("%d.",p1->year);printf("%d.",p1->month);printf("%d   ",p1->day);printf("c语言:%5.3f   ",p1->c);printf("高数:%5.3f   ",p1->math);printf("英语:%5.3f   ",p1->eng);printf("总分:%4.2f   ",p1->sum);printf("\n");count++;p1=p1->next;
}
}float ave(struct student * head)//求平均数
{int i;float ave,sum=0;struct student *p;p=head;for(i=0;p!=NULL;i++){sum=sum+p->sum;p=p->next;}ave=sum/i;return ave;
}void change(struct student *head,long num)//修改学生数据
{struct student *p;p=head;for(;p!=NULL;){if(p->num==num){printf("请输入学生姓名:");scanf("%s",p->name);printf("请输入学生性别:");scanf("%s",p->sex);printf("请输入学生生日:\n");printf("年:");scanf("%d",&p->year);printf("月:");scanf("%d",&p->month);printf("日:");scanf("%d",&p->day);printf("c语言:");scanf("%f",&p->c);printf("高数:");scanf("%f",&p->math);printf("英语:");scanf("%f",&p->eng);p->sum=p->c+p->eng+p->math;printf("\n");break;}else{p=p->next;} }
}void filein(struct student *head)//保存到文件中
{FILE *fp;struct student *p;if((fp=fopen("D:\\20161181\\23\\student.dat","wb"))==NULL)//打开文件 {printf("can't open.\n");exit(0);}p=head; while(p!=NULL)                //将链表的内容存储到文本文件中 {fwrite(p,LEN,1,fp);printf("\n");p=p->next;}fclose(fp);printf("成功保存至D:\\20161181\\23\\student.dat\n");
}
struct student *fileout(struct student *head)
{FILE *fp;struct student *p,*s;if((fp=fopen("D:\\20161181\\23\\student.dat","rb"))==NULL)return NULL;else if(fgetc(fp)==EOF)return NULL;rewind(fp);head=(struct student *)malloc(LEN);fread(head,LEN,1,fp);p=head;while(!feof(fp)){s=(struct student *)malloc(LEN);if(fread(s,LEN,1,fp)==0)break;p->next=s;p=s;p->next=NULL;}return head;fclose(fp);}struct student * locate(struct student *head,long num1)//按学号查找
{struct student *p1,*p2;p1=head;if(head==NULL)    //空链表时返回{printf("/n链表为空!/n");return(head);}else{while(num1!=p1->num && p1->next!=NULL){p2=p1;p1=p1->next;}if(p1->num==num1)//比较输入学号是否与链表中学生学号匹配 {printf("查找的学生信息为:\n");printf("学号:%ld\n",p1->num);printf("姓名:%s\n",p1->name);printf("性别:%s\n",p1->sex);                                                       printf("生日:\n");                          printf("年:%d\n",p1->year);                        printf("月:%d\n",p1->month);                     printf("日:%d\n",p1->day);                      printf("c语言:%5.3f\n",p1->c);                           printf("高数:%5.3f\n",p1->math);                         printf("英语:%5.3f\n",p1->eng);p1->sum=p1->c+p1->eng+p1->math;printf("总分:%5.2f\n",p1->sum);                     printf("\n");                         return head;}else{printf("无该学生数据\n");return head;}
}}struct student * locate1(struct student *head)//按姓名查找
{char name[10];printf("请输入要查询学生的姓名:");scanf("%s",name); struct student *p1,*p2;p1=head;if(head==NULL)    //空链表时返回{printf("/n链表为空!/n");return(head);}else{while(strcmp(name,p1->name)!=0 && p1->next!=NULL){p2=p1;p1=p1->next;}if(strcmp(name,p1->name)==0)//比较输入姓名与链表中学生姓名是否匹配 {printf("查找的学生信息为:\n");printf("学号:%ld\n",p1->num);printf("姓名:%s\n",p1->name);printf("性别:%s\n",p1->sex);                                                      printf("生日:\n");                          printf("年:%d\n",p1->year);                        printf("月:%d\n",p1->month);                     printf("日:%d\n",p1->day);                      printf("c语言:%5.3f\n",p1->c);                           printf("高数:%5.3f\n",p1->math);                         printf("英语:%5.3f\n",p1->eng);p1->sum=p1->c+p1->eng+p1->math;printf("总分:%5.2f\n",p1->sum);                     printf("\n");                         return head;}else{printf("无该学生数据\n");return head;}
}}//输出学生信息 void print(struct student *head){struct student *p;p=head;printf("现在链表里的数据为:\n");while(p!=NULL){printf("学号:%ld   ",p->num);printf("姓名:%s   ",p->name);printf("性别:%s   ",p->sex);printf("生日:%d.",p->year);printf("%d.",p->month);printf("%d   ",p->day);printf("c语言:%5.2f   ",p->c);printf("高数:%5.2f   ",p->math);printf("英语:%5.2f   ",p->eng);printf("总分:%5.2f   ",p->sum);printf("\n");p=p->next;}printf("\n");
}
void sum(struct student *head)
{int n=0;struct student *p,*p1;p=head;while(p!=NULL){if(p->c<60){n++;    }p=p->next; }if(n==0){ printf("(o^.^o)本次C语言无人挂科.\n");}
if(n>0){ printf("本次C语言挂科人数有%d人\n\n",n);printf("挂科人员的学号,姓名如下\n\n");}p1=head;while(p1!=NULL&&p1->c<60){printf("学号:%ld  ",p1->num);printf("姓名:%s\n",p1->name);p1=p1->next;}printf("\n");
}
int main()
{int choose,n;long number,e;char name[6];struct student *head,*p;char password[10]={"123456"};char password1[10],password2[10],password3[10],password4[10],num[12];printf("请输入进入学生成绩管理系统的管理员代号和密码:\n系统默认登录密码为:123456.\n管理员代号:");scanf("%s",num);printf("密码:"); scanf("%s",password1);printf("\n");for(;;){if(strcmp(password1,password)!=0){printf("输入错误,请重新输入:\n管理员代号:");scanf("%s",num);printf("\n密码:"); scanf("%s",password1);printf("\n");}else{printf("%s管理员成功登陆\n",num); break;}   }printf("★★★★欢迎使用学生成绩管理系统★★★★\n\n");printf("---------------------------------------\n");printf("\t0.退出程序\n\t1.录入学生记录\n\t2.添加学生记录\n");printf("\t3.删除学生记录\n\t4.修改学生记录\n");printf("\t5.查找学生记录\n\t6.按总分对学生记录进行降序排序\n");printf("\t7.将数据保存至文件\n\t8.输出所有学生信息\n\t9.计算班级平均分\n");printf("\t10.修改管理员密码\n\t11.统计C语言挂科人数\n");system("pause");system("cls");head=fileout(head);choose=-1;while(choose!=0){printf("★★★★欢迎使用学生成绩管理系统★★★★\n");printf("---------------------------------------\n");printf("\t0.退出程序\n\t1.录入学生记录\n\t2.添加学生记录\n");printf("\t3.删除学生记录\n\t4.修改学生记录\n");printf("\t5.查找学生记录\n\t6.按总分对学生记录进行降序排序\n");printf("\t7.将数据保存至文件\n\t8.输出所有学生信息\n\t9.计算班级平均分\n");printf("\t10.修改管理员密码\n\t11.统计C语言挂科人数\n");printf("请输入一个数字:\n");scanf("%d",&choose);system("cls");switch(choose){case 0:printf("\n\n");printf("★★★★期待您的下次使用★★★★");printf("\n\n");break;case 1:head=creat();system("pause");system("cls");break;case 2:p=(struct student *)malloc(LEN);printf("请输入要添加学生学号\n"); printf("学号:\n");scanf("%ld",&p->num);if(p->num!=0){printf("请输入学生姓名:");scanf("%s",p->name);printf("请输入学生性别:");scanf("%s",p->sex);printf("请输入学生生日:\n");printf("年:");scanf("%d",&p->year);printf("月:");scanf("%d",&p->month);printf("日:");scanf("%d",&p->day);printf("c语言:");scanf("%f",&p->c);printf("高数:");scanf("%f",&p->math);printf("英语:");scanf("%f",&p->eng); p->sum=p->c+p->eng+p->math;head=insert(head,p);}system("pause");system("cls");break;case 3:printf("输入您要删除的学号:\n");scanf("%ld",&e);if(e!=0)head=del(head,e);system("pause");system("cls");break;case 4:int num;printf("请输入密码:\n");scanf("%s",password4);while(strcmp(password,password4)!=0){printf("输入错误,请重输:\n");scanf("%s",password4);} printf("输入密码正确!\n");printf("请输入要修改学生学号:");scanf("%ld",&num);change(head,num); system("pause");system("cls");break;case 5:int ch;printf("输入您要查找的学生的内容:\n1.按学号查找\n2.按姓名查找\n");scanf("%d",&ch);if(ch==1){printf("请输入要查询学生学号:");scanf("%ld",&number);head=locate(head,number);printf("\n");}if(ch==2){head=locate1(head);printf("\n");}system("pause");system("cls");break;case 6:sort(head);system("pause");system("cls");break;case 7:filein(head); system("pause");system("cls");break;                    case 8:print(head);system("pause");system("cls");break;case 9:float aver;aver=ave(head);printf("该班平均分为:%4.2f\n",aver);system("pause");system("cls");break;case 10:printf("旧密码:");scanf("%s",password1);printf("新密码:");scanf("%s",password2);printf("请您确认新密码:"); scanf("%s",password3);for(;;){if(strcmp(password,password1)!=0){printf("输入的旧密码有误\n");printf("旧密码:");scanf("%s",password1);printf("新密码:");scanf("%s",password2);printf("请确认新密码:"); scanf("%s",password3);}if(strcmp(password2,password3)!=0){printf("输入的新密码与确认的新密码不一致\n");printf("旧密码:");scanf("%s",password1);printf("新密码:");scanf("%s",password2);printf("请确认新密码:"); scanf("%s",password3);}if(strcmp(password1,password)==0&&strcmp(password2,password3)==0){printf("成功修改密码.\n");break; }}strcpy(password,password2);system("pause");system("cls");break;case 11:sum(head);system("pause");system("cls");break;}}return 0;}

1.先输入系统规定密码123456进入学生成绩管理系统。进入后能看到以下界面。

2.按照下图信息进行学生信息的录入。

3.按3删除学号为3的学生信息。

再按8看看链表中的数据是不是被删除了。

4.按2添加学生为3的学生信息。

按8看看添加的效果,程序是按照学号排序的方式插入的。

5.按数字5查找学生记录。(两种方式。1.按照学号查询 2.按照姓名查询)
1.按照学号查询

2.按照姓名查询

6.按数字6根据总分对学生成绩进行排序。

7.按数字9计算班级平均分
8.按数字10进行密码修改(由于未存入文件,再次打开仍然要输入原始密码,此项密码修改只针对第4项功能的修改学生记录时的密码输入)

9.按数字4进行学生记录的修改(需要输入上次修改密码)

可以看到原始密码123456已经失效。
9.按数字11统计C语言挂科人数。
有挂科人员时,会输出挂科人员的学号和姓名。

10.按数字7将学生信息保存至文件(文件路径为D:\20161181\23\stu.dat)。
第二次打开程序时,原有数据会丢失,由于没有做读取文件的功能。

读者可以自行完善文件的读取功能


11.按数字0退出程序。

经测试,上述代码未出现问题。

关注公众号,获取更多资源。在后台回复学生成绩管理系统,即可获取源码。

每天进步一点点,开心也多一点点

用C语言链表编写学生成绩管理系统相关推荐

  1. C语言链表实现学生成绩管理系统

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<iostream> i ...

  2. c语言用链表实现成绩管理系统,C语言基于单链表得学生成绩管理系统

    前言 传说中讲课通俗而不庸俗,说话风流而不下流的小编又来了哦,今天的主要内容是:C语言基于单链表得学生成绩管理系统.首先给年夜家总结下为什么你们学习C语言会觉得难,尤其是对单链表这块,主要原因得是因为 ...

  3. c语言实现学生二科成绩的单链表,c++链表实现学生成绩管理系统(简易版)

    #include using namespace std; typedef struct student{ int id;//学号 string sex; string name; int cpp;/ ...

  4. C语言编写学生成绩管理系统

    文章链接:https://codemouse.online/archives/2020-06-04-16-07-48 需求 用C语言编写学生成绩管理系统,要求该系统可 对学生操作:添加和删除操作. 可 ...

  5. 用链表c语言程序设计,C语言程序设计-基于链表的学生成绩管理系统

    <C语言程序设计-基于链表的学生成绩管理系统>由会员分享,可在线阅读,更多相关<C语言程序设计-基于链表的学生成绩管理系统(18页珍藏版)>请在人人文库网上搜索. 1.华北科技 ...

  6. c语言编写简单的成绩管理系统,用c语言编写学生成绩管理系统

    <用c语言编写学生成绩管理系统>由会员分享,可在线阅读,更多相关<用c语言编写学生成绩管理系统(9页珍藏版)>请在人人文库网上搜索. 1.include#include#inc ...

  7. c语言用链表实现成绩管理系统,C语言写的学生成绩管理系统(链表)

    <C语言写的学生成绩管理系统(链表)>由会员分享,可在线阅读,更多相关<C语言写的学生成绩管理系统(链表)(6页珍藏版)>请在人人文库网上搜索. 1.include#inclu ...

  8. C语言基础篇02:单链表实现学生成绩管理系统

    单链表实现学生成绩管理系统 前言 需求分析 详细设计 增加成绩信息 删除成绩信息 修改成绩信息 查询学生信息和浏览学生信息 总结 前言 上篇已经讲过单链表的基本实现,这篇将以一个简单的管理系统入手. ...

  9. C语言链表学生成绩制作成链表,C语言程序设计课程设计基于链表的学生成绩管理系统.doc...

    C语言程序设计课程设计基于链表的学生成绩管理系统 华北科技学院计算机系综合性实验报告 PAGE 第 PAGE 10 页 华北科技学院计算机系综合性实验 实 验 报 告 课程名称 C语言程序设计 实验学 ...

最新文章

  1. java学习笔记_Java学习笔记——第1篇
  2. iOS 新特性分列式 之 iOS 8.x - 主要内容:应用扩展、手动对焦、Size Class
  3. python类方法中使用:修饰符@staticmethod和@classmethod的作用与区别,还有装饰器@property的使用
  4. vc60如何输入c语言,vc60中如何编译运行及调试c语言程序.pdf
  5. RabbitMQ基础概念详细介绍
  6. 5分钟从零构建第一个 Apache Flink 应用
  7. BugkuCTF-MISC题random color
  8. 【Spring】Spring boot 可以通过集成jolokia来使用HTTP形式访问mbean
  9. c4d序列号_(图文+视频)野分享:手把手教你免费获取Megascans所有资产并应用于C4D...
  10. 输油管的布置数学建模matlab,输油管布置问题的优化模型
  11. 每日小技巧:教您ps提示内存不足怎么办?
  12. 单词数(HDU 2072)
  13. python 颜色与字体
  14. echarts仪表盘option_ECharts 仪表盘样式修改
  15. 换掉 Java 8 Java 1718 新特性真香
  16. 帝国霸业服务器无限加载,帝国霸业银河生存控制台的服务器命令是什么_控制台服务器命令一览_3DM单机...
  17. 安裝oracle坑之---安装界面乱码,全都是框框
  18. 一些纳税常识[公司]
  19. ubuntu22安装多端同步的笔记软件——joplin
  20. 计算机的3d打印机,DIY机械计算器,用3D打印技术体验更棒

热门文章

  1. 如何知道自己的电脑的牌子以及型号等信息
  2. 【网络小知识】之TCP IP 五元组(five-tuple/5-tuple)
  3. 「Note」Math not for OI
  4. 计算机断电后黑屏怎么办,如何解决win7系统电脑开机后断电黑屏的故障
  5. 往事如烟 - 夫妻股篇
  6. 2020全网最全前端安全综述(深度好文!)
  7. 蒙特卡洛模拟预测公司未来的毛利润
  8. 游泳的鱼 AC于2018.7.21
  9. 下一代数据库发展的趋势
  10. 黄教头第五周作业 暴力破解在sqli漏洞中的应用