C语言模拟学生学籍管理系统

2024-05-15 21:48

本文主要是介绍C语言模拟学生学籍管理系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

学生学籍管理系统的C语言模拟实现是对链表、指针、结构体、文件操作等知识点的综合运用,需要实现的功能主要包含:输入学生信息、显示学生信息、查询学生信息、新增学生信息、删除学生信息、修改学生信息、对学生信息排序、保存当前信息到文件、文件备份、文件加载等。
代码实现如下

#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include<conio.h>
#include <MEMORY.H>typedef struct node
{                   int    num;char   name[20];float  score[3];float  ave;struct  node *next;
}STU;STU *Create();
void output(STU *head);
void find(STU *head);
STU *findByNum(STU *head,int num);
STU *findByName(STU *head,char name);
STU *findByNumEx(STU *head,int num,STU **ppbefore);
STU *del(STU* head);
STU *insert(STU *head);
void update(STU *head);
void sort(STU *head);
void save_info(STU *head);
STU *load_info();
void copy();void main()
{   STU *head;int choice;head=NULL;for(;;){system("cls");printf("           \t\t******学生成绩管理系统*********\n");printf("           \t\t* 1.输入学生信息              *\n");printf("           \t\t* 2.显示全部学生信息          *\n");printf("           \t\t* 3.查询学生信息              *\n");printf("           \t\t* 4.新增学生信息              *\n");printf("           \t\t* 5.删除学生信息              *\n");printf("           \t\t* 6.修改学生信息              *\n");printf("           \t\t* 7.对学生信息排序            *\n");printf("           \t\t* 8.保存当前信息到文件        *\n");printf("           \t\t* 9.备份                      *\n");printf("           \t\t* 10.从文件加载学生信息       *\n");printf("           \t\t* 0.退出系统                  *\n");printf("           \t\t*******************************\n");printf("请选择(0-9) :");scanf("%d",&choice);if(choice==0) break;switch(choice){   case 1: head=Create();break;case 2: output(head);break;case 3: find(head);break;case 4: head=insert(head); break;case 5: head=del(head); break;case 6: update(head);break;case 7: sort(head);break;case 8: save_info(head);break;case 9: copy();break;case 10:head=load_info();break;}printf("按任意键继续....");getch();}printf("感谢您的使用,再见!\n");
}STU *Create()
{STU *head,*pnew,*pend;head=NULL;printf("输入学生信息(按0结束输入):\n学号\t姓名\t数学\t英语\t语文\n");for(;;){pnew=(STU *)malloc(sizeof(STU));scanf("%d",&pnew->num);if(pnew->num==0){   printf("输入完成!---> ");break;}scanf("%s%f%f%f",pnew->name,&pnew->score[0],&pnew->score[1],&pnew->score[2]);pnew->ave=(pnew->score[0]+pnew->score[1]+pnew->score[2])/3;pnew->next=NULL;if(head==NULL){head=pnew;pend=pnew;}else{pend->next=pnew;pend=pend->next;}}return head;
}void output(STU *head)
{STU *p;printf("全部学生信息如下:\n学号\t姓名\t数学\t英语\t语文\t平均分\n");for(p=head;p!=NULL;p=p->next)printf("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",p->num,p->name,p->score[0],p->score[1],p->score[2],p->ave);
}void find(STU *head)
{STU *presult;int num;char name[20];int choice;printf("查找学生信息\n");printf("请选择查找方式:1,按学号;2,按姓名\n");printf("choice=");scanf("%d",&choice);if(choice==1){printf("请输入学号:");scanf("%d",&num);presult=findByNum(head,num);}else{printf("请输入姓名\n");scanf("%s",name);presult=findByName(head,name);}if(presult!=NULL){printf("找到了,该生信息如下:\n学号\t姓名\t数学\t英语\t语文\t平均分\n");   printf("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",presult->num,presult->name,presult->score[0],presult->score[1],presult->score[2],presult->ave);}elseprintf("查无此人!\a\n");
}STU *findByNum(STU *head,int num)
{STU *p,*presult=NULL;for(p=head;p!=NULL;p=p->next)if(p->num==num){presult=p;break;}
return presult;
}STU *findByName(STU *head,char *name)
{STU *p,*presult=NULL;for(p=head;p!=NULL;p=p->next)if(strcmp(p->name,name)==0){presult=p;break;}
return presult;
}//函数说明:
//  在head所指向链表中,查找学号为num的节点
//  找到后,返回两个值:指向当前节点的指针presult,指向当前节点的前一节点的指针pbefore,
//  presult通过函数返回值返回(即return),pbefore通过输出型参数ppBefore返回
STU *findByNumEx(STU *head,int num,STU **ppbefore)
{STU *p,*presult=NULL,*pbefore=NULL;for(p=head;p!=NULL;pbefore=p,p=p->next)if(p->num==num){presult=p;break;}if(p==NULL)pbefore=NULL;*ppbefore=pbefore;return presult;
}STU *del(STU *head)
{STU *presult,*pbefore;int num;printf("要删除的学号:");scanf("%d",&num);presult=findByNumEx(head,num,&pbefore);if(presult!=NULL){printf("找到了,该生信息如下:\n学号\t姓名\t数学\t英语\t语文\t平均分\n");   printf("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",presult->num,presult->name,presult->score[0],presult->score[1],presult->score[2],presult->ave);if(presult==head){head=presult->next;}else{pbefore->next=presult->next;}printf("删除成功---> ");}elseprintf("无与此学生相关的信息\a\a\n");return head;
}STU *insert(STU *head)
{STU *pnew,*pcur,*pbefore,*p;int choice;printf("输入新生信息:\n");for(;;){pnew=(STU *)malloc(sizeof(STU));printf("学号\t姓名\t数学\t英语\t语文\n");scanf("%d%s%f%f%f",&pnew->num,pnew->name,&pnew->score[0],&pnew->score[1],&pnew->score[2]);pnew->ave=(pnew->score[0]+pnew->score[1]+pnew->score[2])/3;pnew->next=NULL;if(head==NULL){head=pnew;  }else{pcur=NULL;for(p=head;p!=NULL;pbefore=p,p=p->next)if(p->num > pnew->num){pcur=p;break;}       if(pcur==NULL){pbefore->next=pnew; }else{if(pcur==head){pnew->next=pcur;head=pnew;}else{pnew->next=pcur;pbefore->next=pnew;}}}printf("请选择:按1继续添加->按0结束添加\n");printf("choice=");scanf("%d",&choice);if(choice==0){   printf("信息添加完毕!\n");break;}}return head;
}void update(STU *head)
{STU *presult;int num;printf("输入要修改学生的学号\n");scanf("%d",&num);presult=findByNum(head,num);if(presult==NULL)printf("查无此人!无法修改!\a\n");else{printf("找到了,该生信息如下:\n学号\t姓名\t数学\t英语\t语文\t平均分\n");   printf("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",presult->num,presult->name,presult->score[0],presult->score[1],presult->score[2],presult->ave);printf("输入修改信息\n");printf("学号\t姓名\t数学\t英语\t语文\n"); scanf("%d%s%f%f%f",&presult->num,&presult->name,&presult->score[0],&presult->score[1],&presult->score[2]);presult->ave=(presult->score[0]+presult->score[1]+presult->score[2])/3;printf("修改完毕---> ");}
}void sort(STU *head)
{STU *pi,*pj,*pindex,*p;STU temp;int len=sizeof(STU)-sizeof(STU *);int i,j,n=0;for(p=head;p!=NULL;p=p->next)n++;for(pi=head,i=0;i<n-1;i++,pi=pi->next){pindex=pi;for(pj=pi->next,j=i+1;j<n;j++,pj=pj->next)if(pindex->num> pj->num)pindex=pj;memcpy(&temp,pi,len); memcpy(pi,pindex,len); memcpy(pindex,&temp,len); }printf("排序完毕---> ");
}void save_info(STU *head)
{char filename[40];FILE *fp;STU *p;printf("现在进入保存当前信息到文件的处理\n");printf("请输入文件名:");scanf("%s",filename);if((fp=fopen(filename,"w"))==NULL){printf("无法打开文件\n");return;}fprintf(fp,"全部学生信息如下:\n学号\t姓名\t数学\t英语\t语文\t平均分\n");for(p=head;p!=NULL;p=p->next)fprintf(fp,"%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",p->num,p->name,p->score[0],p->score[1],p->score[2],p->ave);fprintf(fp,"%d",0);fclose(fp);printf("保存完成!--->");
}
STU *load_info()
{STU *head=NULL,*pnew,*pend;char filename[40];FILE *fp;int i;printf("现在进行从文件加载的处理,输入文件名:");scanf("%s",filename);if((fp=fopen(filename,"r"))==NULL){printf("加载失败!");exit(0);}for(i=0;i<7;i++)fscanf(fp,"%s",filename);for(;;){pnew=(STU *)malloc(sizeof(STU));fscanf(fp,"%d",&pnew->num);if(pnew->num==0)break;fscanf(fp,"%s%f%f%f%f",&pnew->name,&pnew->score[0],&pnew->score[1],&pnew->score[2],&pnew->ave);pnew->next=NULL;if(head==NULL){head=pnew;pend=pnew;}else{pend->next=pnew;pend=pnew;}}fclose(fp);printf("加载成功!\n");return head;
}void copy()
{FILE *in,*out;char infile[40];char outfile[40];printf("现在进入学生信息文件的备份\n");printf("源文件名:");scanf("%s",infile);printf("备份文件名:");scanf("%s",outfile);if((in=fopen(infile,"r"))==NULL){printf("文件无法打开\n");exit(0);}if((out=fopen(outfile,"w"))==NULL){printf("文件无法打开\n");exit(0);}while(!feof(in))fputc(fgetc(in),out);fclose(in);fclose(out);
}

程序运行效果图:
这里写图片描述

这篇关于C语言模拟学生学籍管理系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/993011

相关文章

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

usaco 1.2 Transformations(模拟)

我的做法就是一个一个情况枚举出来 注意计算公式: ( 变换后的矩阵记为C) 顺时针旋转90°:C[i] [j]=A[n-j-1] [i] (旋转180°和270° 可以多转几个九十度来推) 对称:C[i] [n-j-1]=A[i] [j] 代码有点长 。。。 /*ID: who jayLANG: C++TASK: transform*/#include<

科研绘图系列:R语言扩展物种堆积图(Extended Stacked Barplot)

介绍 R语言的扩展物种堆积图是一种数据可视化工具,它不仅展示了物种的堆积结果,还整合了不同样本分组之间的差异性分析结果。这种图形表示方法能够直观地比较不同物种在各个分组中的显著性差异,为研究者提供了一种有效的数据解读方式。 加载R包 knitr::opts_chunk$set(warning = F, message = F)library(tidyverse)library(phyl

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

Vue3项目开发——新闻发布管理系统(六)

文章目录 八、首页设计开发1、页面设计2、登录访问拦截实现3、用户基本信息显示①封装用户基本信息获取接口②用户基本信息存储③用户基本信息调用④用户基本信息动态渲染 4、退出功能实现①注册点击事件②添加退出功能③数据清理 5、代码下载 八、首页设计开发 登录成功后,系统就进入了首页。接下来,也就进行首页的开发了。 1、页面设计 系统页面主要分为三部分,左侧为系统的菜单栏,右侧

工厂ERP管理系统实现源码(JAVA)

工厂进销存管理系统是一个集采购管理、仓库管理、生产管理和销售管理于一体的综合解决方案。该系统旨在帮助企业优化流程、提高效率、降低成本,并实时掌握各环节的运营状况。 在采购管理方面,系统能够处理采购订单、供应商管理和采购入库等流程,确保采购过程的透明和高效。仓库管理方面,实现库存的精准管理,包括入库、出库、盘点等操作,确保库存数据的准确性和实时性。 生产管理模块则涵盖了生产计划制定、物料需求计划、

hdu4431麻将模拟

给13张牌。问增加哪些牌可以胡牌。 胡牌有以下几种情况: 1、一个对子 + 4组 3个相同的牌或者顺子。 2、7个不同的对子。 3、13幺 贪心的思想: 对于某张牌>=3个,先减去3个相同,再组合顺子。 import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.IOExcepti

【每日一题】LeetCode 2181.合并零之间的节点(链表、模拟)

【每日一题】LeetCode 2181.合并零之间的节点(链表、模拟) 题目描述 给定一个链表,链表中的每个节点代表一个整数。链表中的整数由 0 分隔开,表示不同的区间。链表的开始和结束节点的值都为 0。任务是将每两个相邻的 0 之间的所有节点合并成一个节点,新节点的值为原区间内所有节点值的和。合并后,需要移除所有的 0,并返回修改后的链表头节点。 思路分析 初始化:创建一个虚拟头节点

C语言 | Leetcode C语言题解之第393题UTF-8编码验证

题目: 题解: static const int MASK1 = 1 << 7;static const int MASK2 = (1 << 7) + (1 << 6);bool isValid(int num) {return (num & MASK2) == MASK1;}int getBytes(int num) {if ((num & MASK1) == 0) {return

MiniGPT-3D, 首个高效的3D点云大语言模型,仅需一张RTX3090显卡,训练一天时间,已开源

项目主页:https://tangyuan96.github.io/minigpt_3d_project_page/ 代码:https://github.com/TangYuan96/MiniGPT-3D 论文:https://arxiv.org/pdf/2405.01413 MiniGPT-3D在多个任务上取得了SoTA,被ACM MM2024接收,只拥有47.8M的可训练参数,在一张RTX