diff --git a/完整代码.cpp b/完整代码.cpp new file mode 100644 index 0000000..ed7fac9 --- /dev/null +++ b/完整代码.cpp @@ -0,0 +1,822 @@ +#include +#include +#include +#include +struct record +{ + char nativeplace[20]; + char name[20]; + char phone1[20]; + char phone2[20]; + char e_mail[30]; +}student[500]; +int num=0;//ⲿnumΪļеļ¼ +FILE *fp; +void welcome(); //ӭ +void mainmenu(); //˵ +void newrecord(); //¼ +void modify(); //޸ϵ + void modifyname(); //޸ + void modifyphone1(); //绰1޸ + void modifyphone2(); //绰2޸ +void searchmenu(); //ѯ˵ +void searchbynativeplace(); //ѯ +void searchbyname(); //ѯ +void searchbyphone1(); //绰1ѯ +void searchbyphone2(); //绰2ѯ +void deletemenu(); //ɾ˵ + void deleteall(); //ɾ + void deleteone(); //ɾ +void showall(); //ʾ +void readfromfile(); //ȡļ +void writetofile(); //дļ +void deletebynativeplace(); //ɾ +void deletebyname(); //ɾ +void listbynativeplace(); // +void listbyname(); // +void listmenu(); //˵ +int main() // +{ + welcome(); + readfromfile(); + while (1) + { + mainmenu(); + } +} +void welcome()//ӭ + { + printf("\n\n\n\n\n\n"); + printf("\t\t\t============ͨѶ¼==============\n"); + printf("\n\n\n"); + printf("\t\t\t ӭʹã \n"); + printf("\n\n\n"); + printf("\t\t\t================================\n"); + getch(); + return; +} +void writetofile()//дļ +{ + int i; + if ((fp=fopen("student.bin","wb"))==NULL) + { + printf("\n\t\tļʧ"); + } + for (i=0;i0) /*ļΪ*/ + { + rewind(fp); /*ļλָƶļʼλ*/ + for (num=0;!feof(fp) && fread(&student[num],sizeof(struct record),1,fp);num++); + printf("\n\t\tļɹ"); + printf("\n\t\t˵"); + getch(); + return; + } + printf("\n\t\tļɹ"); + printf("\n\t\tͨѶ¼ļκμ¼"); + printf("\n\t\t˵"); + getch(); + return; +}//ļ +void mainmenu()//˵ +{ + char choic; + system("cls"); + printf("\n\t\t******************* ˵ ********************"); + printf("\n\t\t********** 1-¼ 2-޸ļ¼ *************"); + printf("\n\t\t********** 3-ѯ˵ 4-ɾ¼ *************"); + printf("\n\t\t********** 5-¼ 6-˳ *************"); + printf("\n\t\t********** 7-˳ *************"); + printf("\n\t\t************************************************"); + printf("\n\t\tѡ"); + choic=getch(); + switch (choic) + { + case '1':newrecord();break; + case '2':modify();break; + case '3':searchmenu();break; + case '4':deletemenu();break; + case '5':listmenu();break; + case '6':writetofile();break; + case '7':exit(0); + default:mainmenu(); + } +} +void newrecord()//Ӽ¼ +{ + printf("\n\t\t**************** ϵϢ ****************\n"); + printf("\n\t\t뼮:"); + scanf("%s",&student[num].nativeplace); + printf("\n\t\t:"); + scanf("%s",&student[num].name); + printf("\n\t\t绰1:"); + scanf("%s",&student[num].phone1); + printf("\n\t\t绰2:"); + scanf("%s",&student[num].phone2); + printf("\n\t\te-mail:"); + scanf("%s",&student[num].e_mail); + num++;/*ͳϵ˸*/ + printf("\n\t\tǷ?(Y/N):"); + if (getch()=='y') + newrecord(); + return; +}//ϵ + +void deletemenu()//ɾ˵ +{ + char choic; + if(num==0) + { + printf("\n\t\tԲļκμ¼"); + printf("\n\t\t˵"); + getch(); + return; + } + system("cls"); + printf("\n\t\t******************* ɾ˵ *******************"); + printf("\n\t\t*********** 1-ɾ 2-ɾ ***********"); + printf("\n\t\t*********** 3-˵ ***********"); + printf("\n\t\t************************************************"); + printf("\n\t\tѡ"); + choic=getch(); + switch (choic) + { + case '1':deleteall();break; + case '2':deleteone();break; + case '3':mainmenu();break; + default:mainmenu();break; + } +} +void deleteall()//ɾ +{ + printf("\n\t\tȷɾ?(y/n)"); + if (getch()=='y') + { + fclose(fp); + if ((fp=fopen("student.bin","wb"))==NULL) + { + printf("\n\t\tܴļɾʧ"); + readfromfile(); + } + num=0; + printf("\n\t\t¼ɾ˵"); + getch(); + return; + } + else + return; +} +void deletebyname()//ɾ +{ + int a=0; + int findmark=0; + int j; + int deletemark=0; + int i; + char name[20]; + printf("\n\t\tҪɾ"); + scanf("%s",name); + for (i=a;i=0); + student[j+1]=tmp; + } + } + printf("\n\t\tɹ,Ƿʾ?(y/n)"); + if (getch()=='y') + showall(); + return; +} +void listbyname()// +{ + int i,j; + struct record tmp; + for (i=1;i=0)); + student[j+1]=tmp; + } + } + printf("\n\t\tɹ,Ƿʾ?(y/n)"); + if (getch()=='y') + showall(); + return; +} diff --git a/完整代码.exe b/完整代码.exe new file mode 100644 index 0000000..6ed4a53 Binary files /dev/null and b/完整代码.exe differ diff --git a/盛翔宇.cpp b/盛翔宇.cpp new file mode 100644 index 0000000..04434b2 --- /dev/null +++ b/盛翔宇.cpp @@ -0,0 +1,526 @@ +#include +#include +#include +#include +struct record +{ + char nativeplace[20]; + char name[20]; + char phone1[20]; + char phone2[20]; + char e_mail[30]; +}student[500]; +int num=0;//ⲿnumΪļеļ¼ +FILE *fp; +void welcome(); //ӭ +void mainmenu(); //˵ +void newrecord(); //¼ +void modify(); //޸ϵ + void modifyname(); //޸ + void modifyphone1(); //绰1޸ + void modifyphone2(); //绰2޸ +void searchmenu(); //ѯ˵ +void searchbynativeplace(); //ѯ +void searchbyname(); //ѯ +void searchbyphone1(); //绰1ѯ +void searchbyphone2(); //绰2ѯ +void deletemenu(); //ɾ˵ + void deleteall(); //ɾ + void deleteone(); //ɾ +void showall(); //ʾ +void readfromfile(); //ȡļ +void writetofile(); //дļ +void deletebynativeplace(); //ɾ +void deletebyname(); //ɾ +void listbynativeplace(); // +void listbyname(); // +void listmenu(); //˵ +int main() // +{ + welcome(); + readfromfile(); + while (1) + { + mainmenu(); + } +} +void showall()//ʾ +{ + int i; + system("cls"); + if(num!=0) + { + printf("\n\t\t*************** ΪͨѶ¼Ϣ************"); + for (i=0;i=0); + student[j+1]=tmp; + } + } + printf("\n\t\tɹ,Ƿʾ?(y/n)"); + if (getch()=='y') + showall(); + return; +} +void listbyname()// +{ + int i,j; + struct record tmp; + for (i=1;i=0)); + student[j+1]=tmp; + } + } + printf("\n\t\tɹ,Ƿʾ?(y/n)"); + if (getch()=='y') + showall(); + return; +} +void deletemenu()//ɾ˵ +{ + char choic; + if(num==0) + { + printf("\n\t\tԲļκμ¼"); + printf("\n\t\t˵"); + getch(); + return; + } + system("cls"); + printf("\n\t\t******************* ɾ˵ *******************"); + printf("\n\t\t*********** 1-ɾ 2-ɾ ***********"); + printf("\n\t\t*********** 3-˵ ***********"); + printf("\n\t\t************************************************"); + printf("\n\t\tѡ"); + choic=getch(); + switch (choic) + { + case '1':deleteall();break; + case '2':deleteone();break; + case '3':mainmenu();break; + default:mainmenu();break; + } +} +void deleteall()//ɾ +{ + printf("\n\t\tȷɾ?(y/n)"); + if (getch()=='y') + { + fclose(fp); + if ((fp=fopen("student.bin","wb"))==NULL) + { + printf("\n\t\tܴļɾʧ"); + readfromfile(); + } + num=0; + printf("\n\t\t¼ɾ˵"); + getch(); + return; + } + else + return; +} +void deletebyname()//ɾ +{ + int a=0; + int findmark=0; + int j; + int deletemark=0; + int i; + char name[20]; + printf("\n\t\tҪɾ"); + scanf("%s",name); + for (i=a;i +#include +#include +#include +struct record +{ + char nativeplace[20]; + char name[20]; + char phone1[20]; + char phone2[20]; + char e_mail[30]; +}student[500]; +int num=0;//ⲿnumΪļеļ¼ +FILE *fp; +void welcome(); //ӭ +void mainmenu(); //˵ +void newrecord(); //¼ +void modify(); //޸ϵ + void modifyname(); //޸ + void modifyphone1(); //绰1޸ + void modifyphone2(); //绰2޸ +void searchmenu(); //ѯ˵ +void searchbynativeplace(); //ѯ +void searchbyname(); //ѯ +void searchbyphone1(); //绰1ѯ +void searchbyphone2(); //绰2ѯ +void deletemenu(); //ɾ˵ + void deleteall(); //ɾ + void deleteone(); //ɾ +void showall(); //ʾ +void readfromfile(); //ȡļ +void writetofile(); //дļ +void deletebynativeplace(); //ɾ +void deletebyname(); //ɾ +void listbynativeplace(); // +void listbyname(); // +void listmenu(); //˵ +int main() // +{ + welcome(); + readfromfile(); + while (1) + { + mainmenu(); + } +} +void welcome()//ӭ + { + printf("\n\n\n\n\n\n"); + printf("\t\t\t============ͨѶ¼==============\n"); + printf("\n\n\n"); + printf("\t\t\t ӭʹã \n"); + printf("\n\n\n"); + printf("\t\t\t================================\n"); + getch(); + return; +} +void readfromfile()//ļ +{ + system("cls"); + if((fp=fopen("student.bin","rb"))==NULL) + { + printf("\n\t\tͨѶ¼ļ"); + if ((fp=fopen("student.bin","wb"))==NULL) + { + printf("\n\t\tʧ"); + exit(0); + } + else + { + printf("\n\t\tͨѶ¼ļѽ"); + printf("\n\t\t˵"); + getch(); + return; + } + exit(0); + } + fseek(fp,0,2); /*ļλָƶļĩβ*/ + if (ftell(fp)>0) /*ļΪ*/ + { + rewind(fp); /*ļλָƶļʼλ*/ + for (num=0;!feof(fp) && fread(&student[num],sizeof(struct record),1,fp);num++); + printf("\n\t\tļɹ"); + printf("\n\t\t˵"); + getch(); + return; + } + printf("\n\t\tļɹ"); + printf("\n\t\tͨѶ¼ļκμ¼"); + printf("\n\t\t˵"); + getch(); + return; +}//ļ +void mainmenu()//˵ +{ + char choic; + system("cls"); + printf("\n\t\t******************* ˵ ********************"); + printf("\n\t\t********** 1-¼ 2-޸ļ¼ *************"); + printf("\n\t\t********** 3-ѯ˵ 4-ɾ¼ *************"); + printf("\n\t\t********** 5-¼ 6-˳ *************"); + printf("\n\t\t********** 7-˳ *************"); + printf("\n\t\t************************************************"); + printf("\n\t\tѡ"); + choic=getch(); + switch (choic) + { + case '1':newrecord();break; + case '2':modify();break; + case '3':searchmenu();break; + case '4':deletemenu();break; + case '5':listmenu();break; + case '6':writetofile();break; + case '7':exit(0); + default:mainmenu(); + } +} +void newrecord()//Ӽ¼ +{ + printf("\n\t\t**************** ϵϢ ****************\n"); + printf("\n\t\t뼮:"); + scanf("%s",&student[num].nativeplace); + printf("\n\t\t:"); + scanf("%s",&student[num].name); + printf("\n\t\t绰1:"); + scanf("%s",&student[num].phone1); + printf("\n\t\t绰2:"); + scanf("%s",&student[num].phone2); + printf("\n\t\te-mail:"); + scanf("%s",&student[num].e_mail); + num++;/*ͳϵ˸*/ + printf("\n\t\tǷ?(Y/N):"); + if (getch()=='y') + newrecord(); + return; +}//ϵ +void modify()//޸ϵ +{ + char c; + int mark=0; + int i; + int a=0; + if(num==0) + { + printf("\n\t\tԲļκμ¼"); + printf("\n\t\t˵"); + getch(); + return; + } + system("cls"); + printf("\n\t\t********* ޸ϵ˲˵ *********"); + printf("\n\t\t** 1-޸ 2-绰1޸ **"); + printf("\n\t\t** 3-绰2޸ **"); + printf("\n\t\t********-˵*********"); + c=getch(); + switch(c) + { + case '1':modifyname();break; + case '2':modifyphone1();break; + case '3':modifyphone2();break; + default:mainmenu();break; + } +} +void modifyname()//޸ +{ + char choic; + int i; + int mark=0; + int a=0; + char name[20]; + printf("\n\t\tҪ޸ϵ"); + scanf("%s",name); + for(i=0;i