commit 9859f6474aeb62d5122f30b6d8238ff7cbd372db Author: 1852163443@qq.com <1852163443@qq.com> Date: Fri Jan 11 13:51:19 2019 +0800 first commit diff --git a/C语言课设.dev b/C语言课设.dev new file mode 100644 index 0000000..c647c9f --- /dev/null +++ b/C语言课设.dev @@ -0,0 +1,62 @@ +[Project] +FileName=CÓïÑÔ¿ÎÉè.dev +Name=CÓïÑÔ¿ÎÉè +Type=1 +Ver=2 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=0 +Icon= +ExeOutput= +ObjectOutput= +LogOutput= +LogOutputEnabled=0 +OverrideOutput=0 +OverrideOutputName= +HostApplication= +UseCustomMakefile=0 +CustomMakefile= +CommandLine= +Folders= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=3 +CompilerSettings=0000000100000000000000000 +UnitCount=1 + +[VersionInfo] +Major=1 +Minor=0 +Release=0 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 +SyncProduct=1 + +[Unit1] +FileName=main.c +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/C语言课设.exe b/C语言课设.exe new file mode 100644 index 0000000..69916e7 Binary files /dev/null and b/C语言课设.exe differ diff --git a/C语言课设.layout b/C语言课设.layout new file mode 100644 index 0000000..f6b881f --- /dev/null +++ b/C语言课设.layout @@ -0,0 +1,8 @@ +[Editors] +Order=0 +Focused=0 +[Editor_0] +CursorCol=2 +CursorRow=269 +TopLine=222 +LeftChar=1 diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 0000000..fda5ee3 --- /dev/null +++ b/Makefile.win @@ -0,0 +1,28 @@ +# Project: CÓïÑÔ¿ÎÉè +# 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 = CÓïÑÔ¿ÎÉè.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..0db1e83 --- /dev/null +++ b/main.c @@ -0,0 +1,269 @@ +#include +#include +#include +struct stu /*¶¨Òå½á¹¹ÌåÊý×é*/ +{ + char num[15]; + char banji[10]; + char name[25]; + int hour1; + int hour2; + int min1; + int min2; +}st[99]; +void menu() /*²Ëµ¥*/ +{ + printf("\t**************************\n"); + printf("\t****1---ÊäÈëÊý¾Ý**********\n"); + printf("\t****2---¼ÆËã·ÑÓÃ**********\n"); + printf("\t****3---ɾ³ýÊý¾Ý**********\n"); + printf("\t****4---²éѯÊý¾Ý**********\n"); + printf("\t**************************\n"); + printf("\tÊäÈëÏàÓ¦Êý×ÖÑ¡ÔñÒԻسµ½áÊø\n"); +} +void new_students(int *p); +void calculate(struct stu st[],int *p); +void del(int *p); +void search(int *p); +void main() /*Ö÷º¯Êý*/ +{ + int b=0; + int a,*p; + FILE *fpp; /*¶¨ÒåÎļþÖ¸Õë*/ + p=&b; + if((fpp=fopen("stu_num.txt","r"))==NULL) + { + printf("ÎÞÀúÊ·¼Ç¼"); + system("pause"); + } + else + { + fread(p,4,1,fpp); + fclose(fpp); + } + while(1) + { + system("cls"); + menu(); + scanf("%d",&a); + switch(a) + { + case 1: + new_students(p); break; + case 2: + calculate(st,p); break; + case 3: + del(p); break; + case 4: + search(p); break; + case 5: + { + system("pause"); + exit(0); + } + default : + printf("continue\n"); + } + system("pause"); + } +} +void new_students(int *p) /*ÊäÈ뺯Êý*/ +{ + int i; + FILE *fp; + FILE *fpp; + for(i=*p;i<*p+1;i++) + { + printf("ÇëÊäÈëÐÅÏ¢!\n"); + printf("ѧºÅΪ:"); + scanf("%s",&st[i].num); + fflush(stdin); + printf("°à¼¶Îª:"); + scanf("%s",&st[i].banji); + printf("ÐÕÃûΪ:"); + scanf("%s",&st[i].name); + printf("ÉÏ»úСʱΪ:"); + scanf("%d",&st[i].hour1); + printf("ÉÏ»ú·ÖÖÓΪ:"); + scanf("%d",&st[i].min1); + printf("Ï»úСʱΪ:"); + scanf("%d",&st[i].hour2); + printf("Ï»ú»ú·ÖÖÓΪ:"); + scanf("%d",&st[i].min2); + } + if(*p==0) + { + if((fp=fopen("stu_menu.txt","w"))==NULL) + printf("cannot open file"); + } + else + { + fp=fopen("stu_menu.txt","r+"); + for(i=0;i<*p;i++) + fread(&st[i],sizeof(struct stu),1,fp); /*дÈëÎļþ*/ + } + for(i=0;i<*p+1;i++) + if(fwrite(&st[i],sizeof(struct stu),1,fp)!=1) + fclose(fp); + *p=*p+1; + if((fpp=fopen("stu_num.txt","w"))==NULL) + { + printf("cannot open file"); + return; + } + if(fwrite(p,4,1,fpp)!=1) + printf("file write error"); + fclose(fpp); +} +void calculate(struct stu st[],int *p) +{ + int i,j; + FILE *fp; + fp=fopen("stu_menu.txt","r"); /*´ò¿ªÎļþ*/ + for(i=0;i<*p;i++) + { + fread(&st[i],sizeof(struct stu),1,fp); + system("cls"); + printf("ѧºÅΪ:%s\t °à¼¶Îª:%s\t ÐÕÃûΪ:%s\t",st[i].num,st[i].banji,st[i].name); + printf("\tÉÏ»úʱ¼äΪ:%dʱ%d·Ö",st[i].hour1,st[i].min1); + printf("\tÏ»úʱ¼äΪ:%dʱ%d·Ö",st[i].hour2,st[i].min2); + if(st[i].min1<=st[i].min2) + j=(st[i].hour2-st[i].hour1)*60+(st[i].min2-st[i].min1); + else if(st[i].min1>st[i].min2) + j=(st[i].hour2-st[i].hour1-1)*60+(60-st[i].min1+st[i].min2); + else if(st[i].min1==0&&st[i].min2==0) + j=(st[i].hour2-st[i].hour1)*60; + printf("·ÑÓÃΪ:%dÔª",j); + } +} +void del(int *p) /*ɾ³ýº¯Êý*/ +{ + int i,j; + char a[9]; + FILE *fp; + FILE *fpp; + fp=fopen("stu_menu.txt","r+"); + for(i=0;i<*p;i++) + fread(&st[i],sizeof(struct stu),1,fp); + printf("ÇëÊäÈëҪɾ³ýµÄÃû×Ö"); + scanf("%s",a); + for(i=0;i<*p;i++) + { + if(strcmp(a,st[i].name)==0) + { + for(j=i;j<*p-1;j++) + { + strcpy(st[j].num,st[j+1].num); + strcpy(st[j].banji,st[j+1].banji); + st[j].hour1=st[j+1].hour1; + st[j].min1=st[j+1].min1; + st[j].hour2=st[j+1].hour2; + st[j].min2=st[j+1].min2; + strcpy(st[j].name,st[j+1].name); + } + *p=*p-1; + } + } + for(i=0;i<*p;i++) + fwrite(&st[i],sizeof(struct stu),1,fp); + fclose(fp); + if((fpp=fopen("stu_num.txt","w"))==NULL) + { + printf("cann't open file"); + return; + } + if(fwrite(p,4,1,fp)!=1) + printf("file write error"); + fclose(fpp); + printf("¸ÃÉúÐÅÏ¢ÒѾ­²»´æÔÚ"); +} +void search(int *p) /*²éѯÊý¾Ý*/ +{ + int a,i,c=1,j; + char b[9]; + FILE *fp; + fp=fopen("stu_menu.txt","r"); + for(i=0;i<*p;i++) + fread(&st[i],sizeof(struct stu),1,fp); + fclose(fp); + printf("**ÇëÊäÈëÏàÓ¦Êý×ÖÑ¡Ôñ²éѯµÄÌõ¼þ**\n"); + printf("1:ѧºÅ 2:ÐÕÃû 3:°à¼¶\n"); + scanf("%d",&a); + switch(a) /*Ñ¡Ôñ²éÕÒ·½Ê½*/ + { + case 1: + { + printf("ѧºÅ"); + scanf("%s",b); + for(i=0;i<*p;i++) + if(strcmp(b,st[i].num)==0) + { + printf("ѧºÅΪ:%s °à¼¶Îª:%s ÐÕÃûΪ:%s",st[i].num,st[i].banji,st[i].name); + printf("\tÉÏ»úʱ¼äΪ:%dʱ%d·Ö",st[i].hour1,st[i].min1); + printf("\tÏ»úʱ¼äΪ:%dʱ%d·Ö",st[i].hour2,st[i].min2); + if(st[i].min1<=st[i].min2) + j=(st[i].hour2-st[i].hour1)*60+(st[i].hour2-st[i].hour1); + else if(st[i].min1>st[i].min2) + j=(st[i].hour2-st[i].hour1-1)*60+(60-st[i].min1+st[i].min2); + else if(st[i].min1==0&&st[i].min2==0) + j=st[i].hour2-st[i].hour1; + printf("·ÑÓÃΪ:%dÔª",j); + c=0; + } + if(c==1) + { + printf("ûÓÐÏà¹ØÏûÏ¢"); + } + } break; + case 2: + { + printf("ÐÕÃû"); + scanf("%s",b); + for(i=0;i<*p;i++) + if(strcmp(b,st[i].name)==0) + { + printf("ѧºÅΪ:%s °à¼¶Îª:%s ÐÕÃûΪ:%s",st[i].num,st[i].banji,st[i].name); + printf("\tÉÏ»úʱ¼äΪ:%dʱ%d·Ö",st[i].hour1,st[i].min1); + printf("\tÏ»úʱ¼äΪ:%dʱ%d·Ö",st[i].hour2,st[i].min2); + if(st[i].min1<=st[i].min2) + j=(st[i].hour2-st[i].hour1)*60+(st[i].min2-st[i].min1); + else if(st[i].min1>st[i].min2) + j=(st[i].hour2-st[i].hour1-1)*60+(60-st[i].min1+st[i].min2); + else if(st[i].min1==0&&st[i].min2==0) + j=st[i].hour2-st[i].hour1; + printf("·ÑÓÃΪ:%dÔª",j); + c=0; + } + if(c==1) + { + printf("ûÓÐÏà¹ØÏûÏ¢"); + } + } break; + case 3: + { + printf("°à¼¶"); + scanf("%s",b); + for(i=0;i<*p;i++) + if(strcmp(b,st[i].banji)==0) + { + printf("ѧºÅΪ:%s °à¼¶Îª:%s ÐÕÃûΪ:%s",st[i].num,st[i].banji,st[i].name); + printf("\tÉÏ»úʱ¼äΪ:%dʱ%d·Ö",st[i].hour1,st[i].min1); + printf("\tÏ»úʱ¼äΪ:%dʱ%d·Ö",st[i].hour2,st[i].min2); + if(st[i].min1<=st[i].min2) + j=(st[i].hour2-st[i].hour1)*60+(st[i].min2-st[i].min1); + else if(st[i].min1>st[i].min2) + j=(st[i].hour2-st[i].hour1-1)*60+(60-st[i].min1+st[i].min2); + else if(st[i].min1==0&&st[i].min2==0) + j=(st[i].hour2-st[i].hour1)*60; + printf("·ÑÓÃΪ:%dÔª",j); + c=0; + } + if(c==1) + { + printf("ûÓÐÏà¹ØÏûÏ¢"); + } + } break; + default : + printf("ûÓÐÏà¹ØÐÅÏ¢"); + } +} diff --git a/main.o b/main.o new file mode 100644 index 0000000..9b55119 Binary files /dev/null and b/main.o differ