Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Class Student Management system with C language

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

这篇文章将为大家详细讲解有关C语言如何实现班级学生管理系统,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

下面是根据班级,这个人数较少的单位设计的学籍管理系统,录入时,要求班内序号由1开始 按顺序录入,其中主要用到了 结构体数组,文件处理,循环语句,选择语句等方面的知识

在设计中遇到一个问题就是:不知道怎样修改已经保存在文件中的某一个指定学生的信息,后来在询问学长之后才了解到 ,可以: 先把文件中的数据全部读入结构体数组中,再修改指定序号的数组元素,然后再用"wt"的方式写进原文件,这样就可以删除文件里的原内容,再写进新内容

下面是源代码,在Dev-C++ 条件下进行编译

#include#include#include#includeint count1=0;int count2=0;int count3=0;void class_print();void men1_student();void men2_student(); void men3_student();void men4_student(); void input_student();void input_grade(); void input_reward();void input_finance();void report_finance(); void seek_student();void seek_grade();void seek_reward();void change_student();void change_grade();void change_reward();int now1_student();int now2_student();int now3_student();struct date{ int year; int month; int day;};struct student{ char number[2]; char name[10]; char sex[4]; char tel[15]; char id[20]; char study[10];};struct grade{ char number[2]; char name[10]; char math[4]; char English[4]; char Cprogram[4]; char sumtest[4];};struct reward{ char number[2]; char name[10]; struct date time; char rewarding[80];};struct finance{ char thing[20]; char type[8]; struct date time2; int i;};struct student m_stu[50];struct grade g_stu[50];struct reward r_stu[50];struct finance f_class;struct grade t_change;main(){ int choice=-1; //一级菜单 while(choice!=0) { printf("\n"); printf("\t\t\t\t\t\t**"); class_print(); printf("**\n"); printf("\t\t\t\t\t\t****************************\n"); printf("\t\t\t\t\t\t** 班级学生学籍管理系统 **\n"); printf("\t\t\t\t\t\t** 1.户籍管理系统 **\n"); printf("\t\t\t\t\t\t** 2.成绩管理系统 **\n"); printf("\t\t\t\t\t\t** 3.奖惩管理系统 **\n"); printf("\t\t\t\t\t\t** 4.财务管理系统 **\n"); printf("\t\t\t\t\t\t** 0.退 出 **\n"); printf("\t\t\t\t\t\t请选择"); scanf("%d",&choice); switch(choice) { case 1: men1_student(); break; case 2: men2_student(); break; case 3: men3_student(); break; case 4: men4_student(); break; case 0: printf("返回上一级"); break; default : break; } }} void men1_student() //二级菜单(学生户籍管理){int choice=-1;while(choice!=0) { printf("\n"); printf("\t\t\t\t\t\t****************************\n"); printf("\t\t\t\t\t\t**"); class_print(); printf("**\n"); printf("\t\t\t\t\t\t** 班级学生户籍信息管理 **\n"); printf("\t\t\t\t\t\t** 户籍信息已录入人数:");now1_student();printf(" **\n"); printf("\t\t\t\t\t\t** 1.户籍录入系统 **\n"); printf("\t\t\t\t\t\t** 2.户籍修改系统 **\n"); printf("\t\t\t\t\t\t** 3.户籍查询系统 **\n"); printf("\t\t\t\t\t\t** 0.返 回 **\n"); printf("\t\t\t\t\t\t请选择"); scanf("%d",&choice); switch(choice) { case 1: input_student(); break; case 2: change_student(); break; case 3: seek_student(); break; case 0: printf("返回上一级"); break; default : break; } getch(); }} void input_student() // 户籍录入函数 录入信息保存至D盘根目录下information1.txt文件下 { int j; printf("学生户籍信息录入"); printf("\n班内序号: "); scanf("%s",&m_stu[count1].number); printf("\n姓名: "); gets(m_stu[count1].name); gets(m_stu[count1].name); printf("\n性别: "); scanf("%s",&m_stu[count1].sex); printf("\n电话号码: "); scanf("%s",&m_stu[count1].tel); printf("\n身份证号: "); scanf("%s",&m_stu[count1].id); printf("\n学号: "); scanf("%s",&m_stu[count1].study); printf("是否保存该学生信息?1-保存 2-放弃"); scanf("%d",&j); if(j==1) { FILE *info; //保存至本地文件 info=fopen("d:\\information1.txt","at+"); fwrite(&m_stu[count1],sizeof(struct student),1,info); fclose(info); printf("信息已保存至D:\\information1.tex 文件下,按任意键继续"); count1++; } else printf("放弃保存,按任意键继续"); }void seek_student() //查询户籍信息函数 { FILE *info; info=fopen("d:\\information1.txt","rt"); int i; printf("请输入该学生班内序号"); scanf("%d",&i); if(i50) printf("抱歉,该学生信息不存在"); else { rewind(info); fseek(info,sizeof(struct student)*(i-1),0); fread(&m_stu[i-1],sizeof(struct student),1,info); printf("\n\n序号 姓名 性别 电话号码\t 身份证号\t\t学号\t"); printf("\n\n%d %s %s %s %s %s",i,m_stu[i-1].name,m_stu[i-1].sex,m_stu[i-1].tel,m_stu[i-1].id,m_stu[i-1].study); } } void change_student() //修改户籍信息 { int i=0,j,k,f;char h[100000]; FILE *info; info=fopen("d:\\information1.txt","rt"); printf("\n\t请输入要修改户籍信息的学生班内序号"); scanf("%d",&j); if(j50) printf("抱歉,该学生信息不存在"); else { rewind(info); while(fgets(h,sizeof(struct student),info)!=NULL) { fseek(info,sizeof(struct student)*i,0); fread(&m_stu[i],sizeof(struct student),1,info); i++; } } fclose(info); printf("\n该学生目前户籍信息为\n:"); printf("\n\n序号 姓名 性别 电话号码\t 身份证号\t\t学号\t"); printf("\n\n%d %s %s %s %s %s",j,m_stu[j-1].name,m_stu[j-1].sex,m_stu[j-1].tel,m_stu[j-1].id,m_stu[j-1].study); printf("确定修改此学生信息?1- 修改 2- 返回"); scanf("%d",&k); if(k==1) { printf("\n姓名: "); gets(m_stu[j-1].name); gets(m_stu[j-1].name); printf("\n性别: "); scanf("%s",&m_stu[j-1].sex); printf("\n电话号码: "); scanf("%s",&m_stu[j-1].tel); printf("\n身份证号: "); scanf("%s",&m_stu[j-1].id); printf("\n学号: "); scanf("%s",&m_stu[j-1].study); } else return; info=fopen("d:\\information1.txt","wt"); for(f=0;f

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report