当前位置: 首页 > news >正文

C语言:学生成绩管理系统(含源代码)

一.功能

二.源代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NUM 100
typedef struct
{char no[30];char name[10];char sex[10];char phone[20];float cyuyan;float computer;float datastruct;
} *student, student1;typedef struct
{student stu[MAX_NUM];int number;
} *studentDB;void read(studentDB temp)
{FILE *infile;infile = fopen("./数据.txt", "r");if (!infile){printf("文件打开失败!");exit(0);}while (!feof(infile)){temp->stu[temp->number] = malloc(sizeof(student1));fscanf(infile, "%s %s %s %s %f %f %f", temp->stu[temp->number]->no, temp->stu[temp->number]->name, temp->stu[temp->number]->sex, temp->stu[temp->number]->phone, &(temp->stu[temp->number]->cyuyan), &(temp->stu[temp->number]->computer), &(temp->stu[temp->number]->datastruct));temp->number++;}fclose(infile);
}void write(studentDB temp)
{FILE *outfile;outfile = fopen("./数据.txt", "w");if (!outfile){printf("文件打开失败!");exit(1);}if (temp && temp->number > 0){int i;for (i = 0; i < temp->number; i++){if (i == temp->number - 1){fprintf(outfile, "%s %s %s %s %.2f %.2f %.2f", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);}else{fprintf(outfile, "%s %s %s %s %.2f %.2f %.2f\n", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);}}}fclose(outfile);printf("保存成功");read(temp);
}void display(studentDB temp)
{int i;printf("|   学号   |姓名|性别|  手机号  |c语言|英语|高等数学|\n");for (i = 0; i < temp->number; i++){printf("%s %s %s %s %.2f %.2f %.2f\n", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);}
}void menu()
{printf("\n\n\t****************************简单学生信息管理系统*****************************\n");printf("\t*                              1.显示学生信息                             *|\n");printf("\t*                              2.增加学生信息                             *|\n");printf("\t*                              3.删除学生信息                             *|\n");printf("\t*                              4.修改学生信息                             *|\n");printf("\t*                              5.查询学生信息                             *|\n");printf("\t*                              6.排序学生成绩                             *|\n");printf("\t*                              7.计算学生平均成绩                         *|\n");printf("\t*                              8.保存学生信息                             *|\n");printf("\t*                              9.统计全部课程及格人数                     *|\n");printf("\t*                              10.输出总成绩最高的学生信息                *|\n");printf("\t*                              0.退出系统                                 *|\n");printf("\t***************************************************************************\n");printf("请选择你的操作并将序号输入:");
}int countDigits(long long n)
{int count = 0;while (n > 0){n /= 10;count++;}return count;
}void insert(studentDB temp)
{char no[30];printf("请输入要添加学生的学号:");scanf("%s", no);int n;long long num;sscanf(no, "%lld", &num);n = countDigits(num);if (n != 11){printf("输入的学号位数有误,请重新输入!");return;}else{student1 stu;FILE *outfile;outfile = fopen("./数据.txt", "a");if (!outfile){printf("文件打开失败!");exit(0);}strcpy(stu.no, no);printf("请输入姓名:");scanf("%s", stu.name);printf("请输入性别:");scanf("%s", stu.sex);printf("请输入手机号:");scanf("%s", stu.phone);printf("请输入c语言成绩(带小数点):");scanf("%f", &stu.cyuyan);printf("请输入英语成绩(带小数点):");scanf("%f", &stu.computer);printf("请输入高等数学成绩(带小数点):");scanf("%f", &stu.datastruct);n = fprintf(outfile, "\n%s %s %s %s %f %f %f", stu.no, stu.name, stu.sex, stu.phone, stu.cyuyan, stu.computer, stu.datastruct);printf("%s %s %s %s %.2f %.2f %.2f", stu.no, stu.name, stu.sex, stu.phone, stu.cyuyan, stu.computer, stu.datastruct);printf("学生信息已成功插入!信息长度:%d\n", n);fclose(outfile);read(temp);return;}
}void delete(studentDB temp)
{printf("请输入要删除的学生信息学号:");char no[15];int i, k;scanf("%s", no);printf("%s", no);for (i = 0; i < temp->number; i++){if (strcmp(temp->stu[i]->no, no) == 0){for (k = i; k < temp->number; k++){temp->stu[k] = temp->stu[k + 1];}free(temp->stu[temp->number]);temp->number--;printf("学生信息已成功删除!\n");return;}}printf("学生学号输入错误!");return;
}void modify(studentDB temp)
{printf("请输入要修改的学生信息学号:");char no[15];int i, flag = 0;long num;scanf("%s", no);sscanf(no, "%ld", &num);for (i = 0; i < temp->number; i++){if (strcmp(no, temp->stu[i]->no) == 0){printf("\n学号:%s  姓名:%s  性别:%s  手机号:%s  c语言:%.2f  英语:%.2f  高等数学:%.2f\n\n\n", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);printf("|1.学号|2.姓名|3.性别|4.手机号|5.c语言成绩|6.英语成绩|7.高等数学成绩|8.不改动并返回菜单|9.依次修改全部数据\n\n\n请输入要改动的数据项:");scanf("%d", &flag);switch (flag){case 1:printf("请输入要修改的学号:");scanf("%s", temp->stu[i]->no);break;case 2:printf("请输入姓名:");scanf("%s", temp->stu[i]->name);break;case 3:printf("请输入性别:");scanf("%s", temp->stu[i]->sex);break;case 4:printf("请输入手机号:");scanf("%s", temp->stu[i]->phone);break;case 5:printf("请输入c语言成绩(带小数点):");scanf("%f", &(temp->stu[i]->cyuyan));break;case 6:printf("请输入英语成绩(带小数点):");scanf("%f", &(temp->stu[i]->computer));break;case 7:printf("请输入高等数学成绩(带小数点):");scanf("%f", &(temp->stu[i]->datastruct));break;case 8:return;case 9:printf("请输入姓名:");scanf("%s", temp->stu[i]->name);printf("请输入性别:");scanf("%s", temp->stu[i]->sex);printf("请输入手机号:");scanf("%s", temp->stu[i]->phone);printf("请输入c语言成绩(带小数点):");scanf("%f", &(temp->stu[i]->cyuyan));printf("请输入英语成绩(带小数点):");scanf("%f", &(temp->stu[i]->computer));printf("请输入高等数学成绩(带小数点):");scanf("%f", &(temp->stu[i]->datastruct));break;default:printf("请重新选择!");break;}return;}}
}void search(studentDB temp)
{printf("请输入要查询的学生信息学号:");char no[30];int i, n;long long num;scanf("%s", no);sscanf(no, "%lld", &num);n = countDigits(num);if (n != 11){printf("输入的学号位数有误,请重新输入!");return;}else{for (i = 0; i < temp->number; i++){if (strcmp(temp->stu[i]->no, no) == 0){printf("\n学号:%s  姓名:%s  性别:%s  手机号:%s  c语言:%.2f  英语:%.2f  高等数学:%.2f\n\n\n", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);return;}}printf("学生学号输入错误!");return;}
}void sort(studentDB temp)
{int i, j, n;float t;for (i = 0; i < temp->number; i++){for (j = i + 1; j < temp->number; j++){if ((temp->stu[i]->cyuyan + temp->stu[i]->computer + temp->stu[i]->datastruct) < (temp->stu[j]->cyuyan + temp->stu[j]->computer + temp->stu[j]->datastruct)){student1 *tempstu = temp->stu[i];temp->stu[i] = temp->stu[j];temp->stu[j] = tempstu;}}}printf("已按成绩排序完成!\n");
}void average(studentDB temp)
{int i;float ctotal = 0, comtotal = 0, dstotal = 0;for (i = 0; i < temp->number; i++){ctotal += temp->stu[i]->cyuyan;comtotal += temp->stu[i]->computer;dstotal += temp->stu[i]->datastruct;}printf("C语言平均成绩:%.2f 英语平均成绩:%.2f 高等数学平均成绩:%.2f\n", ctotal / temp->number, comtotal / temp->number, dstotal / temp->number);
}void passing(studentDB temp)
{int i, cpass = 0, compass = 0, dpass = 0;for (i = 0; i < temp->number; i++){if (temp->stu[i]->cyuyan >= 60){cpass++;}if (temp->stu[i]->computer >= 60){compass++;}if (temp->stu[i]->datastruct >= 60){dpass++;}}printf("C语言及格人数:%d 英语及格人数:%d 高等数学及格人数:%d\n", cpass, compass, dpass);
}void max(studentDB temp)
{int i, index = 0;float maxScore = 0;for (i = 0; i < temp->number; i++){float totalScore = temp->stu[i]->cyuyan + temp->stu[i]->computer + temp->stu[i]->datastruct;if (totalScore > maxScore){maxScore = totalScore;index = i;}}printf("学号:%s  姓名:%s  性别:%s  手机号:%s  c语言:%.2f  英语:%.2f  高等数学:%.2f 总成绩:%.2f\n", temp->stu[index]->no, temp->stu[index]->name, temp->stu[index]->sex, temp->stu[index]->phone, temp->stu[index]->cyuyan, temp->stu[index]->computer, temp->stu[index]->datastruct, maxScore);
}int main()
{int select;studentDB stu = malloc(sizeof(studentDB));stu->number = 0;read(stu);do{menu();scanf("%d", &select);switch (select){case 1:display(stu);break;case 2:insert(stu);break;case 3:delete (stu);break;case 4:modify(stu);break;case 5:search(stu);break;case 6:sort(stu);break;case 7:average(stu);break;case 8:write(stu);break;case 9:passing(stu);break;case 10:max(stu);break;case 0:exit(1);}} while (1);return 0;
}

三.注意事项

(1)事先准备: 数据.txt 文件(可以含有学生信息,可以空白,但是必须有)

(2)学号为11

(3)该代码不含有C99或者C11

相关文章:

C语言:学生成绩管理系统(含源代码)

一.功能 二.源代码 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_NUM 100 typedef struct {char no[30];char name[10];char sex[10];char phone[20];float cyuyan;float computer;float datastruct; } *student, student1;typ…...

MySQL 导出导入的101个坑

最近接到一个业务自行运维的MySQL库迁移至标准化环境的需求&#xff0c;库不大&#xff0c;迁移方式也很简单&#xff0c;由开发用myqldump导出数据、DBA导入&#xff0c;但迁移过程坎坷十足&#xff0c;记录一下遇到的各项报错及后续迁移注意事项。 一、 概要 空间问题源与目…...

OpenCv之简单的人脸识别项目(人脸提取页面)

人脸识别 准备五、人脸提取页面1.导入所需的包2.设置窗口2.1定义窗口外观和大小2.2设置窗口背景2.2.1设置背景图片2.2.2创建label控件 3.定义单人脸提取脚本4.定义多人脸提取脚本5.创建一个退出对话框6.按钮设计6.1单人脸提取按钮6.2多人脸提取按钮6.3返回按钮 7.定义关键函数8…...

linux 内核映像差异介绍:vmlinux、zImage、zbImage、image、uImage等

一、背景 Linux内核是整个Linux操作系统的核心部分&#xff0c;它是一个负责与硬件直接交互的软件层&#xff0c;并且提供多种服务和接口&#xff0c;让用户程序能够方便地使用硬件资源。 当我们编译自定义内核时&#xff0c;可以将其生成为以下内核映像之一&#xff1a;vmli…...

【Linux-INPUT输入的子系统】

Linux-INPUT输入的子系统 ■ input 子系统简介■ input 驱动编写流程■ 事件类型 ■ ■ input 子系统简介 input 子系统就是管理输入的子系统&#xff0c; input 子系统分为 input 驱动层、 input 核心层、 input 事件处理层&#xff0c;最终给用户空间提供可访问的设备节点 …...

密码加密及验证

目录 为什么需要加密&#xff1f; 密码算法分类 对称密码算法 非对称密码算法 摘要算法 DigestUtils MD5在线解密工具原理 实现用户密码加密 代码实现 为什么需要加密&#xff1f; 在MySQL数据库中&#xff0c;我们常常需要对用户密码、身份证号、手机号码等敏感信息进…...

找出字符串中出现最多次数的字符以及出现的次数

str.charAt(i) 是JavaScript中获取字符串中特定位置字符的方法&#xff0c;表示获取当前的字符。 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-wi…...

如何看待央行买卖长期国债?

央行远比大家想象中的要渴求货币宽松。 引子 今年以来&#xff0c;有不少关于“央行买卖长期国债”的讨论&#xff0c;前些时候关注点在“买”&#xff0c;最近关注点在“卖”。 然而&#xff0c;市场上的讨论采用了十分粗糙和松散的“自然语言”&#xff0c;所以&#xff0…...

MATLAB算法实战应用案例精讲-【数模应用】Turf组合模型(附MATLAB、python和R语言代码实现)

目录 几个高频面试题目 如何以最小的成本覆盖到最大的消费群体? 应用场景 TURF举例...

android源码下载编译模拟器运行

安卓aosp源码下载&#xff0c;编译&#xff0c;模拟器运行 virtualbox7 安装ubuntu20.04&#xff0c;ubuntu22.04 编译android aosp 源码可以&#xff0c;但是模拟器跑不了&#xff0c;哪个版本都是要么黑屏&#xff0c;要么整个vbox虚拟机闪退。解决方案使用vmware17 ##拯救…...

Golang:Sirupsen/logrus是一个日志库

Sirupsen/logrus是一个日志库 文档 https://github.com/Sirupsen/logrus 安装 go get github.com/sirupsen/logrus代码示例 package mainimport ("github.com/sirupsen/logrus" )func main() {var log logrus.New()log.Trace("Something very low level.&…...

Android Studio插件开发 - Dora SDK的IDE插件

IDE插件开发简介 Android Studio是一种常用的集成开发环境&#xff08;IDE&#xff09;&#xff0c;用于开发Android应用程序。它提供了许多功能和工具&#xff0c;可以帮助开发人员更轻松地构建和调试Android应用程序。 如果你想开发Android Studio插件&#xff0c;以下是一…...

【mybatis】缓存

一级缓存和二级缓存 一级缓存是SqlSession级别的&#xff0c;通过同一个SqlSession查询的数据会被缓存&#xff0c;下次查询相同的数据&#xff0c;就会从一级缓存中直接获取&#xff0c;不会从数据库重新查询。一级缓存默认是开启 使一级缓存失效的四种情况&#xff1a; 11.1…...

自定义类型:结构体类型

在学习完指针相关的知识后将进入到c语言中又一大重点——自定义类型&#xff0c;在之前学习操作符以及指针时我们对自定义类型中的结构体类型有了初步的了解&#xff0c;学习了结构体类型的创建以及如何创建结构体变量&#xff0c;还有结构体成员操作符的使用&#xff0c;现在我…...

C++对象移动

在某些情况下,对象拷贝后就立即被销毁了,这时利用新标准(C11)提供的对象移动而非拷贝将大幅提升性能. 1.右值引用 为了支持移动操作,c11新增了一种引用 - 右值引用(rvalue reference)。这种引用必须指向右值,使用&&声明。 右值引用只能引用临时变量或常量值. 右值引用…...

“华为杯”第十三届中国研究生 数学建模竞赛-E题:粮食最低收购价政策问题研究(续)

目录 4.3 问题三:粮食价格的特殊规律性模型 4.3.1 分析和建模 4.3.2 求解和结果...

(一)django目录介绍

1、生成django项目&#xff0c;得到的目录如下 manage.py&#xff1a;命令行工具&#xff0c;内置多种方式与项目进行交互。在命令提示符窗口下&#xff0c;将路径切换到项目并输入python manage.py help,可以查看该工具的指令信息。 默认的数据库工具&#xff0c;sqlite 在…...

leetcode5 最长回文子串

给你一个字符串 s&#xff0c;找到 s 中最长的 回文 子串。 示例 1&#xff1a; 输入&#xff1a;s "babad" 输出&#xff1a;"bab" 解释&#xff1a;"aba" 同样是符合题意的答案。示例 2&#xff1a; 输入&#xff1a;s "cbbd" 输…...

《论文阅读》通过顺序不敏感的表示正则化实现稳健的个性化对话生成 ACL 2023

《论文阅读》通过顺序不敏感的表示正则化实现稳健的个性化对话生成 ACL 2023 前言 相关个性化生成论文推荐简介问题定义方法损失函数实验结果 前言 亲身阅读感受分享&#xff0c;细节画图解释&#xff0c;再也不用担心看不懂论文啦~ 无抄袭&#xff0c;无复制&#xff0c;纯手…...

python采集汽车价格数据

python采集汽车价格数据 一、项目简介二、完整代码一、项目简介 本次数据采集的目标是车主之家汽车价格数据,采集的流程包括寻找数据接口、发送请求获取响应、解析数据和持久化存储,先来看一下数据情况,完整代码附后: 二、完整代码 #输入请求页面url #返回html文档 imp…...

终极指南:如何在5分钟内让魔兽争霸3在现代电脑上完美运行

终极指南&#xff1a;如何在5分钟内让魔兽争霸3在现代电脑上完美运行 【免费下载链接】WarcraftHelper Warcraft III Helper , support 1.20e, 1.24e, 1.26a, 1.27a, 1.27b 项目地址: https://gitcode.com/gh_mirrors/wa/WarcraftHelper 还在为经典游戏魔兽争霸3在现代W…...

VSCodium终极指南:零监控的VS Code开源替代方案

VSCodium终极指南&#xff1a;零监控的VS Code开源替代方案 【免费下载链接】vscodium binary releases of VS Code without MS branding/telemetry/licensing 项目地址: https://gitcode.com/gh_mirrors/vs/vscodium VSCodium是一款基于Visual Studio Code源代码构建的…...

30 岁硕士 Linux C 开发背景,未来想去澳洲就业,研究方向该选 AI、SDN 漏洞还是 Linux 内核?

结合截至 2026 年 5 月 19 日的澳洲就业市场公开信息与岗位语境整理 这类题最容易把人带偏的一步&#xff0c;是一上来就把问题理解成&#xff1a; 哪条研究方向听起来最前沿。 但如果你的目标不是单纯做学术&#xff0c;而是&#xff1a; 未来去澳洲更容易就业。 那问题其…...

VSCode Log Viewer插件进阶:除了看syslog,还能这样监控你的Nginx/Docker应用日志

VSCode Log Viewer插件进阶&#xff1a;全栈日志监控实战指南 当你同时维护着系统服务、Web服务器和容器化应用时&#xff0c;日志往往散落在不同角落。每次排查问题都要在多个终端窗口间切换&#xff0c;既低效又容易遗漏关键线索。今天我们就来解锁VSCode Log Viewer插件的高…...

汽车供应链客户定位方法拆解:复杂B2B能力如何被客户看懂

从B2B表达方法看&#xff0c;汽车供应链客户定位可以理解为一个“客户判断结构化”的问题。企业不是简单输出自我介绍&#xff0c;而是要把技术能力、项目经验、质量体系、协同机制与证据材料&#xff0c;转化为客户不同角色都能使用的判断信息。很多汽车供应商在做客户定位时&…...

2026年AI模型接口中转平台生产环境实测:主流服务商性能与成本综合排名全指南

2026年AI模型接口中转平台生产环境实测&#xff1a;主流服务商性能与成本综合排名全指南 进入2026年&#xff0c;国内AI大模型产业已经彻底走完技术验证阶段&#xff0c;全面进入规模化落地周期&#xff0c;全行业日均AI Token调用总量已经突破140万亿。如今的大模型API聚合平台…...

当Abaqus自带模型不够用:3D Hashin失效准则VUMAT开发心路与参数调试经验谈

突破Abaqus复合材料仿真边界&#xff1a;三维Hashin失效准则开发实战全解析 当面对纤维增强复合材料的复杂失效行为时&#xff0c;Abaqus内置的二维Hashin准则常常显得力不从心。作为一名长期深耕复合材料损伤模拟的工程师&#xff0c;我曾花费六个月时间从理论推导到代码实现完…...

重磅喜报!中国星坤入围东莞上规资助计划,政企携手共筑智造标杆

近日&#xff0c;东莞市工业和信息化局正式公布 2026 年支持工业企业上规发展做大做强项目拟资助计划&#xff0c;中国星坤&#xff08;XKB Connection&#xff09;凭借在电子连接器领域的技术实力与稳健发展&#xff0c;成功入选&#xff0c;成为东莞智造升级的标杆企业之一东…...

[特殊字符] 零基础搭建「知识科普讲师」数字人|魔珐星云实战指南

在短视频、知识付费、自媒体赛道&#xff0c;知识科普、职场干货、生活常识、读书分享内容需求越来越大。真人出镜成本高、拍摄慢、文案难量产&#xff0c;而AI 数字人讲师可以做到&#xff1a;文案好写、生成快、24 小时可播、风格稳定、形象专业。 本文基于魔珐星云具身智能…...

告别‘偏科’模型:用CAST双流架构搞定视频动作识别,兼顾时空理解

时空双流协同&#xff1a;CAST架构如何重塑视频动作识别的平衡之道 视频动作识别正面临一个关键瓶颈——现有模型往往在时空理解上"偏科"。就像人类大脑需要左右半球协同工作才能完整理解世界一样&#xff0c;理想的视频理解模型也需要同时具备敏锐的空间感知和精准的…...