学生信息管理系统源代码.doc
学生信息管理系统源代码#include "conio.h"#include <stdio.h>#include<stdlib.h>#define MAX 30/*日期结构体类型*/typedef structint year; int month; int day;DATE;/*学生结构体类型*/typedef structint num; char name10; char sex10; DATE birthday; int score ;STU; int read_file(STU students) FILE*fp; int i=0; if(fp=fopen("lab.txt","rt")=NULL) printf("nn*库文件不存在!请重建"); return 0; while(feof(fp)!=1) fread(&studentsi,sizeof(STU),1,fp); if(studentsi.num=0) break; else i+; fclose(fp); return i;void save_file(STU students,int sum) FILE *fp; int i; if(fp=fopen("lab.txt","wb")=NULL) printf("读文件错误!n"); return; for(i=0;i<sum;i+) if(fwrite(&studentsi,sizeof(STU),1,fp)!=1) printf("写文件错误!n"); fclose(fp); /*输入模块*/ int input(STU students) int i=0,sum; system("cls"); printf("nn 录入学生个数 nn"); scanf("%d",&sum); printf("nn 录入学生信息 n",MAX); printf("nn -n") ; for(i=0;i<sum;i+) printf("n第%d个人",i+1) ; printf("nn 学号 "); scanf("%d",&studentsi.num) ; printf("nn 姓名 ") ; scanf("%s",&studentsi.name); printf("nn 性别 "); scanf("%s",&studentsi.sex); printf("nn 出生日期 ") ; printf("nn 年"); scanf("%d",&studentsi.birthday.year); printf("nn 月"); scanf("%d",&studentsi.birthday.month); printf("nn 日"); scanf("%d",&studentsi.birthday.day); printf("nn 成绩 "); scanf("%d",&studentsi.score ); printf("n-%d个学生信息输入完毕-n",i); printf("-按任意键返回主菜单-") ; return i; /*输出模块*/ void output(STU students,int sum) system("cls"); int i=0; for(i=0;i<sum;i+) printf("n -学生信息- n"); printf("学号 姓名 性别 出生日期 成绩 n"); printf("- n"); printf("%4d %10s %8s %15d-%2d-%2d %3dn", studentsi.num, studentsi.name, studentsi.sex, studentsi.birthday.year, studentsi.birthday.month, studentsi.birthday.day, studentsi.score ); printf("按任意键返回主菜单n"); getch(); /*添加模块*/ int append(STU students,int sum) system("cls"); int i,j; printf("请输入要添加的学生数量:n"); scanf("%d",&j); for(i=sum;i<sum+j;i+) printf("-按格式输入提示内容:n"); printf("请输入学号:n"); scanf("%d",&studentsi.num); printf("请输入姓名:n"); scanf("%s", &studentsi.name ); printf("请输入性别 :n"); scanf("%s",&studentsi.sex); printf("请输入出生日期:n"); scanf("%d-%d-%d",&studentsi.birthday.year, &studentsi.birthday.month, &studentsi.birthday.day); printf("请输入成绩:n") ; scanf ("%d",studentsi.score ); printf("%d本信息输入完毕",i); printf("学号 姓名 性别 出生日期 成绩 n"); printf("- n"); printf("%4d %10s %8s %15d-%2d-%2d %3dn", studentsi.num, studentsi.name, studentsi.sex, studentsi.birthday.year, studentsi.birthday.month, studentsi.birthday.day, studentsi.score ); printf("按任意键返回主菜单n"); sum=sum+j; return(sum); /*修改模块*/ void modify(STU students,int sum) int i=0,choice,modify_num,flag; do system("cls") ; printf("n输入要修改的学生学号n") ; scanf("%d",&modify_num); for(i=0;i<sum;i+) if(studentsi.num=modify_num) printf("n -学生信息- n"); printf("学号 姓名 性别 出生日期 成绩 n"); printf("- n"); printf("%4d %6s %4s %10d-%2d-%2d %6dn", studentsi.num, studentsi.name, studentsi.sex, studentsi.birthday.year, studentsi.birthday.month, studentsi.birthday.day, studentsi.score ); printf(" n 您要修改那一项 n "); printf(" n 1 学号 n "); printf(" n 2 姓名 n "); printf(" n 3 性别 n "); printf(" n 4 出生日期 n "); printf(" n 5 成绩 n "); printf(" n 请选择(1-4): n "); scanf ("%d",&choice); switch(choice) case 1:printf("n 输入修改后的学号: "); scanf("%d",&studentsi.num); break; case 2:printf("n 输入修改后的姓名 : "); scanf("%s",&studentsi.name); break; case 3:printf("n 输入修改后的性别 : "); scanf("%s",&studentsi.sex); break; case 4:printf("n 输入修改后的出生日期"); scanf("%d-%d-%d",&studentsi.birthday.year, &studentsi.birthday.month, &studentsi.birthday.day); break; case 5:printf("n 输入修改后的成绩: "); scanf("%d",&studentsi.score); break; printf("n -该学生信息- n"); printf("学号 姓名 性别 出生日期 成绩 n"); printf("- n"); printf("%4d %6s %4s %10d-%2d-%2d %6dn", studentsi.num, studentsi.name, studentsi.sex, studentsi.birthday.year, studentsi.birthday.month, studentsi.birthday.day, studentsi.score ); break; if(i=sum) printf("n 该学号不存在 " ); / bioskey(0); printf("nn 继续修改吗?(Y/N) "); choice=getch(); if(choice='Y'|choice='y') flag=1; printf("n 继续 !n"); else flag=0; while(flag=1); printf("n-按任意键返回主菜单-n"); /bioskey(0); /*删除模块*/ void del(STU students,int sum) int i; int j; int del_num; system("cls") ; printf("n输入要删除的学生学号n") ; scanf("%d",&del_num); for(i=0;i<sum;i+) if(studentsi.num=del_num) break; for(j=i;j<sum;j+) studentsj =studentsj+1; /*查询模块*/ void inquire(STU students,int sum) int i=0,choice,inquire_num,flag; do system("cls") ; printf("n输入要查询的学生学号n") ; scanf("%d",&inquire_num); for(i=0;i<sum;i+) if(studentsi.num=inquire_num) printf("n -该学生信息- n"); printf("学号 姓名 性别 出生日期 成绩 n"); printf("- n"); printf("%4d %6s %4s %10d-%2d-%2d %6dn", studentsi.num, studentsi.name, studentsi.sex, studentsi.birthday.year, studentsi.birthday.month, studentsi.birthday.day, studentsi.score ); break; if(i=sum) printf("n 该学号不存在 " ); /bioskey(0); printf("nn 继续查询吗?(Y/N) "); choice=getch(); if(choice='Y'|choice='y') flag=1; printf("n 继续 !n"); else flag=0; while(flag=1); printf("n-按任意键返回主菜单-n"); /bioskey(0); /*排序模块*/ void sort(STU students,int sum) STU t; int i,j,k; system("cls") ; printf("n-库行排名-n"); printf("n-n"); printf("n 排名 学号 姓名 性别 出生日期n ") ; for(i=0;i<sum;i+) k=i; for(j=i+1;j<sum;j+) if (studentsi.score>studentsj.score) k=j; if (k!=i) t=studentsi; studentsi=studentsk; studentsk=t; output(students, sum); /bioskey(0); void main() STU studentsMAX; int choice,sum; sum=read_file(students); if(sum=0) printf("*并录入基本库存信息!*n"); getch(); sum=input(students); do system("cls"); printf("nnn *学生管理系统*nn") ; printf(" 1 添加学生信息nn") ; printf(" 2 修改学生信息nn") ; printf(" 3 删除学生信息nn") ; printf(" 4 打印学生信息nn") ; printf(" 5 查询学生信息nn") ; printf(" 6 排序学生信息nn") ; printf(" 0 退出系统nnn") ; printf(" 请选择(0-6):") ; scanf("%d",&choice) ; switch (choice) case 1:sum=append(students,sum); break; case 2:modify(students,sum); break; case 3:del(students,sum); break; case 4:output(students,sum); break; case 5:inquire(students,sum);break; case 6:sort(students,sum); break; case 0: break; while(choice!=0); save_file(students,sum);第8页(共8页)