commit f376be01879b61d59ba0b1967f93ac5d85331839 Author: 鐙櫧 <18408000306@stu.hut.edu.cn> Date: Thu Jan 10 10:15:08 2019 +0800 first commit diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 0000000..ba08c2f --- /dev/null +++ b/Makefile.win @@ -0,0 +1,28 @@ +# Project: 学生成绩管理系统 +# Makefile created by Dev-C++ 5.11 + +CPP = g++.exe +CC = gcc.exe +WINDRES = windres.exe +OBJ = main.o +LINKOBJ = main.o +LIBS = -L"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32" -static-libgcc -m32 +INCS = -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" +CXXINCS = -I"C:/Program Files/Dev-Cpp/MinGW64/include" -I"C:/Program Files/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" +BIN = 学生成绩管理系统.exe +CXXFLAGS = $(CXXINCS) -m32 +CFLAGS = $(INCS) -m32 +RM = rm.exe -f + +.PHONY: all all-before all-after clean clean-custom + +all: all-before $(BIN) all-after + +clean: clean-custom + ${RM} $(OBJ) $(BIN) + +$(BIN): $(OBJ) + $(CC) $(LINKOBJ) -o $(BIN) $(LIBS) + +main.o: main.c + $(CC) -c main.c -o main.o $(CFLAGS) diff --git a/main.c b/main.c new file mode 100644 index 0000000..31c70ab --- /dev/null +++ b/main.c @@ -0,0 +1,549 @@ +#include +#include +#include +#include +#define MAX 2000 +struct Student +{ + int num; //学号 + char name[8]; //姓名 + char sex; //性别 + int mark[4]; //三门课成绩,最后为平均成绩 +}; +int get_menu_choice() ;//接受菜单选择 +void menu() ;//菜单响应 +void main_menu(); //显示菜单 +void Sort_menu();//排序菜单 +int all; //总人数 +char password[20];//密码 +struct Student student[MAX]; +void Init(); //初始化,文件不存在,则建立,同时记录下文件中的记录数 +FILE *file_operate(const char *mode);//文件操作 +void Delete(FILE *fp); //删除记录 +void Alter(FILE *fp); //修改记录信息 +void Show(); //显示打印所有的信息 +void Save(); //备份信息到文件 +void Find(); //查找记录的函数 +void Input(FILE *fp); //向管理系统中增加记录 +int Inputoneperson(int i); //向数组增加一条记录 +void set_psw(); //设置密码 +int key_check(); //密码验证 +void exchange(int i,int j);//交换两个人的所有信息 +void PrintTitle(); //打印头信息 +void clear(); //清屏 +void Show_student(int i); //显示打印一个人的信息 +int CheckNumber(int num_temp); //检查学号是否存在,存在返回序号,不存在返回-1 +void Inputfile(int i,FILE *fp); //把下标为i 的记录写入文件 +void Readfile(int i,FILE *fp); //读一条记录从文件 +int Sort_menu_choice();//选择是按学号还是成绩排序 +void Sort_save();//排序后数据写入文件 +void Sort_num();//选择是按学号排序 +void Sort_mark();//选择是按成绩排序 +main() //主函数 +{ + printf("\n"); + printf(" |**************************************************************************|\n"); + printf(" | |\n"); + printf(" | |\n"); + printf(" | |\n"); + printf(" | 欢迎使用学生成绩管理系统 |\n"); + printf(" | |\n"); + printf(" | |\n"); + printf(" | |\n"); + printf(" |**************************************************************************|\n"); + printf("\n"); +if(key_check()) +{ + Init(); + clear(); + menu(); +} +} +int get_menu_choice()//接受菜单选择 +{ +int menu_ch; //菜单选项 +do +{ + printf("Select the choice:"); + scanf("%d",&menu_ch); +if((menu_ch<0)||(menu_ch>9)) +printf("error!"); +} +while((menu_ch<0)||(menu_ch>9)); + return(menu_ch); +} +void main_menu() //主菜单 +{ + + printf("\n"); + printf(" 欢迎使用学生成绩管理系统 \n"); + printf(" ***************************************************************\n"); + printf(" || 0.退出系统 | 1.查询信息 ||\n"); + printf(" || 2.添加信息 | 3 显示信息 ||\n"); + printf(" || 4.删除信息 | 5.修改信息 ||\n"); + printf(" || 6.备份信息 | 7.设置密码 ||\n"); + printf(" || 8.数据排序 ||\n"); + printf(" ***************************************************************\n"); +} +void clear()//清屏 +{ +system("pause"); +system("cls"); +} +void menu() //菜单响应 +{ +while(1) +{ + main_menu(); +switch(get_menu_choice()) +{ + case 1:Find();clear(); + break; + case 2:Input(file_operate("ab"));clear(); + break; + case 3:Show();clear(); + break; + case 4:Delete(file_operate("wb"));clear(); + break; + case 5:Alter(file_operate("wb"));clear(); + break; + case 6:Save();clear(); + break; + case 7:set_psw();clear(); + break; + case 8:Sort_menu(); + break; + case 0:system("cls"); + printf("\n"); + printf("\n"); + printf("\n"); + printf(" ||**************************************||\n"); + printf(" ||**************************************||\n"); + printf(" || ||\n"); + printf(" || ||\n"); + printf(" || 感谢使用! || \n"); + printf(" || ||\n"); + printf(" || ||\n"); + printf(" ||**************************************||\n"); + printf(" ||**************************************||\n"); + exit(0); +} +} +} +void Show()//显示打印所有的信息 +{ +int i; +printf("有%d个记录:\n",all); +PrintTitle(); +for(i=0;i=0) +{ +PrintTitle(); +Show_student(i); +} +else +{ +printf("numbody is the number:%d\n",num_temp); +} +} +void Readfile(int i,FILE *fp)//从文件中读记录 +{ +int j; +fscanf(fp,"%8d",&student[i].num); +fscanf(fp,"%8s ",&student[i].name); +fscanf(fp,"%1c",&student[i].sex); +for(j=0;j<4;j++) +fscanf(fp,"%3d",&student[i].mark[j]); +} +int CheckNumber(int num_temp)//检查学号是否存在,存在返回序号,不存在返回-1 +{ +int i,result; +for(i=0;i999999999) +printf("error!"); +} +while(num_temp>99999999); +if(CheckNumber(num_temp)>0) +{ +printf("Number repeatly!\n"); +return 0; +} +else +{ +student[i].num=num_temp; +printf("Input name(lessthan 20 numbers):"); +scanf("%s",&student[i].name); +printf("Sex(M/W):"); +scanf("%s",&student[i].sex); +printf("\n 语文\t 数学\t 英语\n"); +for(j=0;j<3;j++) +{ +scanf("%d",&student[i].mark[j]); +sum=sum+student[i].mark[j]; +} +student[i].mark[3]=sum/3; +PrintTitle(); +Show_student(i); +return 1; +} +} +void Input(FILE *fp)//向管理系统中增加记录 +{ +int i; +i=all; +if(Inputoneperson(i)) +{ +all++; +Inputfile(i,fp); +} +fclose(fp); +} +void Inputfile(int i,FILE *fp) //把下标为i 的记录写入文件 +{ +int j; +fprintf(fp,"%8d",student[i].num); +fprintf(fp,"%8s ",student[i].name); +fprintf(fp,"%1c ",student[i].sex); +for(j=0;j<4;j++) +fprintf(fp,"%3d ",student[i].mark[j]); +} + + +void exchange(int i,int j)//交换两个人的所有信息 +{ +int k; +int num_temp,mark_temp; +char name_temp[20],sex_temp; +num_temp=student[i].num; +student[i].num=student[j].num; +student[j].num=num_temp; +for(k=0;k<4;k++) +{ +mark_temp=student[i].mark[k]; +student[i].mark[k]=student[j].mark[k]; +student[j].mark[k]=mark_temp; +} +strcpy(name_temp,student[i].name); +strcpy(student[i].name,student[j].name); +strcpy(student[j].name,name_temp); +sex_temp=student[i].sex; +student[i].sex=student[j].sex; +student[j].sex=sex_temp; +} +FILE *file_operate(const char *mode)//文件操作 +{ +char choice; +FILE *fp; +do +{ +fflush(stdin); +if((fp=fopen("student.txt",mode))==NULL) +{ +puts("Fail to open the file!"); +puts("Try again!(Y/N)?"); +scanf("%c",&choice); +} +} +while(choice=='y'||choice=='Y'); +if(choice=='n'||choice=='N') +exit(1); +return(fp); +} +void Save()//备份信息到文件 +{ +int i; +char filename[10],ch; +FILE *fp; +printf("Name the new file:(less than ten bits)"); +scanf("%s",filename); +if((fp=fopen(filename,"wb"))==NULL) +{ +printf("Fail to build the file!\n"); +exit(0); +} +ch=getchar(); +for(i=0;i=0) +{ +PrintTitle(); +Show_student(i); +printf("Sure to delete the person?(1,Y/2,N)"); +scanf("%d",&choice2); +if(choice2==1) +{ +for(j=i;j=0) +{ +student[i].num=num_temp; +printf("Input name(lessthan 20 numbers):"); +scanf("%s",&student[i].name); +printf("Sex(M/W):"); +scanf("%s",&student[i].sex); +printf("\n 语文\t 数学\t 英语\n"); +for(j=0;j<3;j++) +{ +scanf("%d",&student[i].mark[j]); +sum=sum+student[i].mark[j]; +} +student[i].mark[3]=sum/3; +PrintTitle(); +Show_student(i); +for(j=0;j2)) +printf("error!"); +} +while((choice<0)||(choice>2)); +return(choice); +} +void Sort_num()//选择是按学号排序 +{ +int i,j; +for(i=0;istudent[j].num) +exchange(i,j); +} +} +} +void Sort_mark()//选择是按成绩排序 +{ +int i,j; +for(i=0;i