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语言逗号运算符和逗号表达式的使用小结

《C语言逗号运算符和逗号表达式的使用小结》本文详细介绍了C语言中的逗号运算符和逗号表达式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习... 在C语言中逗号“,”也是一种运算符,称为逗号运算符。 其功能是把两个表达式连接其一般形式为:表达

Go语言实现桥接模式

《Go语言实现桥接模式》桥接模式是一种结构型设计模式,它将抽象部分与实现部分分离,使它们可以独立地变化,本文就来介绍一下了Go语言实现桥接模式,感兴趣的可以了解一下... 目录简介核心概念为什么使用桥接模式?应用场景案例分析步骤一:定义实现接口步骤二:创建具体实现类步骤三:定义抽象类步骤四:创建扩展抽象类步

GO语言实现串口简单通讯

《GO语言实现串口简单通讯》本文分享了使用Go语言进行串口通讯的实践过程,详细介绍了串口配置、数据发送与接收的代码实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目录背景串口通讯代码代码块分解解析完整代码运行结果背景最近再学习 go 语言,在某宝用5块钱买了个

GO语言zap日志库理解和使用方法示例

《GO语言zap日志库理解和使用方法示例》Zap是一个高性能、结构化日志库,专为Go语言设计,它由Uber开源,并且在Go社区中非常受欢迎,:本文主要介绍GO语言zap日志库理解和使用方法的相关资... 目录1. zap日志库介绍2.安装zap库3.配置日志记录器3.1 Logger3.2 Sugared

Go语言中如何进行数据库查询操作

《Go语言中如何进行数据库查询操作》在Go语言中,与数据库交互通常通过使用数据库驱动来实现,Go语言支持多种数据库,如MySQL、PostgreSQL、SQLite等,每种数据库都有其对应的官方或第三... 查询函数QueryRow和Query详细对比特性QueryRowQuery返回值数量1个:*sql

GO语言中gox交叉编译的实现

《GO语言中gox交叉编译的实现》本文主要介绍了GO语言中gox交叉编译的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录一、安装二、使用三、遇到的问题1、开启CGO2、修改环境变量最近在工作中使用GO语言进行编码开发,因

从基础到高级详解Go语言中错误处理的实践指南

《从基础到高级详解Go语言中错误处理的实践指南》Go语言采用了一种独特而明确的错误处理哲学,与其他主流编程语言形成鲜明对比,本文将为大家详细介绍Go语言中错误处理详细方法,希望对大家有所帮助... 目录1 Go 错误处理哲学与核心机制1.1 错误接口设计1.2 错误与异常的区别2 错误创建与检查2.1 基础

Spring Boot分层架构详解之从Controller到Service再到Mapper的完整流程(用户管理系统为例)

《SpringBoot分层架构详解之从Controller到Service再到Mapper的完整流程(用户管理系统为例)》本文将以一个实际案例(用户管理系统)为例,详细解析SpringBoot中Co... 目录引言:为什么学习Spring Boot分层架构?第一部分:Spring Boot的整体架构1.1

Go语言中json操作的实现

《Go语言中json操作的实现》本文主要介绍了Go语言中的json操作的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录 一、jsOChina编程N 与 Go 类型对应关系️ 二、基本操作:编码与解码 三、结构体标签(Struc

python语言中的常用容器(集合)示例详解

《python语言中的常用容器(集合)示例详解》Python集合是一种无序且不重复的数据容器,它可以存储任意类型的对象,包括数字、字符串、元组等,下面:本文主要介绍python语言中常用容器(集合... 目录1.核心内置容器1. 列表2. 元组3. 集合4. 冻结集合5. 字典2.collections模块