|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
#include<conio.h>
|
|
|
|
|
#define MAX 2000
|
|
|
|
|
struct Student
|
|
|
|
|
{
|
|
|
|
|
int num; //ѧ<><D1A7>
|
|
|
|
|
char name[8]; //<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
char sex; //<2F>Ա<EFBFBD>
|
|
|
|
|
int mark[4]; //<2F><><EFBFBD>ſγɼ<CEB3><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊƽ<CEAA><C6BD><EFBFBD>ɼ<EFBFBD>
|
|
|
|
|
};
|
|
|
|
|
int get_menu_choice() ;//<2F><><EFBFBD>ܲ˵<DCB2>ѡ<EFBFBD><D1A1>
|
|
|
|
|
void menu() ;//<2F>˵<EFBFBD><CBB5><EFBFBD>Ӧ
|
|
|
|
|
void main_menu(); //<2F><>ʾ<EFBFBD>˵<EFBFBD>
|
|
|
|
|
void Sort_menu();//<2F><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
|
|
|
|
|
int all; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char password[20];//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
struct Student student[MAX];
|
|
|
|
|
void Init(); //<2F><>ʼ<EFBFBD><CABC>,<2C>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1>¼<EFBFBD><C2BC><EFBFBD>ļ<EFBFBD><C4BC>еļ<D0B5>¼<EFBFBD><C2BC>
|
|
|
|
|
FILE *file_operate(const char *mode);//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void Delete(FILE *fp); //ɾ<><C9BE><EFBFBD><EFBFBD>¼
|
|
|
|
|
void Alter(FILE *fp); //<2F>ļ<DEB8>¼<EFBFBD><C2BC>Ϣ
|
|
|
|
|
void Show(); //<2F><>ʾ<EFBFBD><CABE>ӡ<EFBFBD><D3A1><EFBFBD>е<EFBFBD><D0B5><EFBFBD>Ϣ
|
|
|
|
|
void Save(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
void Find(); //<2F><><EFBFBD>Ҽ<EFBFBD>¼<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
|
|
|
|
|
void Input(FILE *fp); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD>¼
|
|
|
|
|
int Inputoneperson(int i); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>¼
|
|
|
|
|
void set_psw(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int key_check(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
|
|
|
|
|
void exchange(int i,int j);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
void PrintTitle(); //<2F><>ӡͷ<D3A1><CDB7>Ϣ
|
|
|
|
|
void clear(); //<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
void Show_student(int i); //<2F><>ʾ<EFBFBD><CABE>ӡһ<D3A1><D2BB><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>Ϣ
|
|
|
|
|
int CheckNumber(int num_temp); //<2F><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>-1
|
|
|
|
|
void Inputfile(int i,FILE *fp); //<2F><><EFBFBD>±<EFBFBD>Ϊi <20>ļ<EFBFBD>¼д<C2BC><D0B4><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
void Readfile(int i,FILE *fp); //<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
int Sort_menu_choice();//ѡ<><D1A1><EFBFBD>ǰ<EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><C5BB>dzɼ<C7B3><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void Sort_save();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
void Sort_num();//ѡ<><D1A1><EFBFBD>ǰ<EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void Sort_mark();//ѡ<><D1A1><EFBFBD>ǰ<EFBFBD><C7B0>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
main() //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf(" |**************************************************************************|\n");
|
|
|
|
|
printf(" | |\n");
|
|
|
|
|
printf(" | |\n");
|
|
|
|
|
printf(" | |\n");
|
|
|
|
|
printf(" | <20><>ӭʹ<D3AD><CAB9>ѧ<EFBFBD><D1A7><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ϵͳ |\n");
|
|
|
|
|
printf(" | |\n");
|
|
|
|
|
printf(" | |\n");
|
|
|
|
|
printf(" | |\n");
|
|
|
|
|
printf(" |**************************************************************************|\n");
|
|
|
|
|
printf("\n");
|
|
|
|
|
if(key_check())
|
|
|
|
|
{
|
|
|
|
|
Init();
|
|
|
|
|
clear();
|
|
|
|
|
menu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int get_menu_choice()//<2F><><EFBFBD>ܲ˵<DCB2>ѡ<EFBFBD><D1A1>
|
|
|
|
|
{
|
|
|
|
|
int menu_ch; //<2F>˵<EFBFBD>ѡ<EFBFBD><D1A1>
|
|
|
|
|
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() //<2F><><EFBFBD>˵<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf(" <20><>ӭʹ<D3AD><CAB9>ѧ<EFBFBD><D1A7><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ϵͳ \n");
|
|
|
|
|
printf(" ***************************************************************\n");
|
|
|
|
|
printf(" || 0.<2E>˳<EFBFBD>ϵͳ | 1.<2E><>ѯ<EFBFBD><D1AF>Ϣ ||\n");
|
|
|
|
|
printf(" || 2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ | 3 <20><>ʾ<EFBFBD><CABE>Ϣ ||\n");
|
|
|
|
|
printf(" || 4.ɾ<><C9BE><EFBFBD><EFBFBD>Ϣ | 5.<2E><EFBFBD><DEB8><EFBFBD>Ϣ ||\n");
|
|
|
|
|
printf(" || 6.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ | 7.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ||\n");
|
|
|
|
|
printf(" || 8.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ||\n");
|
|
|
|
|
printf(" ***************************************************************\n");
|
|
|
|
|
}
|
|
|
|
|
void clear()//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
system("pause");
|
|
|
|
|
system("cls");
|
|
|
|
|
}
|
|
|
|
|
void menu() //<2F>˵<EFBFBD><CBB5><EFBFBD>Ӧ
|
|
|
|
|
{
|
|
|
|
|
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(" || <20><>лʹ<D0BB>ã<EFBFBD> || \n");
|
|
|
|
|
printf(" || ||\n");
|
|
|
|
|
printf(" || ||\n");
|
|
|
|
|
printf(" ||**************************************||\n");
|
|
|
|
|
printf(" ||**************************************||\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void Show()//<2F><>ʾ<EFBFBD><CABE>ӡ<EFBFBD><D3A1><EFBFBD>е<EFBFBD><D0B5><EFBFBD>Ϣ
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
printf("<EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD>¼:\n",all);
|
|
|
|
|
PrintTitle();
|
|
|
|
|
for(i=0;i<all;i++)
|
|
|
|
|
Show_student(i);
|
|
|
|
|
}
|
|
|
|
|
void Show_student(int i) //<2F><>ʾ<EFBFBD><CABE>ӡһ<D3A1><D2BB><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>Ϣ
|
|
|
|
|
{
|
|
|
|
|
printf(" %8d %8s %1c %3d %3d %3d %3d \n",student[i].num,student[i].name,student[i].sex,student[i].mark[0],student[i].mark[1],student[i].mark[2],student[i].mark[3]);
|
|
|
|
|
}
|
|
|
|
|
void PrintTitle()//<2F><>ӡͷ<D3A1><CDB7>Ϣ
|
|
|
|
|
{
|
|
|
|
|
printf("-----------------------------------------------------------------\n");
|
|
|
|
|
printf(" ѧ<><D1A7> <20><><EFBFBD><EFBFBD> <20>Ա<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ѧ Ӣ<><D3A2> ƽ<><C6BD><EFBFBD>ɼ<EFBFBD> \n");
|
|
|
|
|
printf("-----------------------------------------------------------------\n");
|
|
|
|
|
}
|
|
|
|
|
void Init() //<2F><>ʼ<EFBFBD><CABC>,<2C>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1>¼<EFBFBD><C2BC><EFBFBD>ļ<EFBFBD><C4BC>еļ<D0B5>¼<EFBFBD><C2BC>
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
all=0;
|
|
|
|
|
if((fp=fopen("student.txt","rb"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
fp=fopen("student.txt","ab");
|
|
|
|
|
clear();
|
|
|
|
|
menu();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(i=0;feof(fp)==0;i++)
|
|
|
|
|
Readfile(i,fp);
|
|
|
|
|
}
|
|
|
|
|
all=i-1;
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void Find()//<2F><><EFBFBD>Ҽ<EFBFBD>¼<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
int i,num_temp;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=file_operate("rb");
|
|
|
|
|
for(i=0;feof(fp)==0;i++)
|
|
|
|
|
Readfile(i,fp);
|
|
|
|
|
all=i-1;
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("Input the number that someone you want to find:(<28><>10141303)");
|
|
|
|
|
scanf("%d",&num_temp);
|
|
|
|
|
i=CheckNumber(num_temp);
|
|
|
|
|
if(i>=0)
|
|
|
|
|
{
|
|
|
|
|
PrintTitle();
|
|
|
|
|
Show_student(i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("numbody is the number:%d\n",num_temp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void Readfile(int i,FILE *fp)//<2F><><EFBFBD>ļ<EFBFBD><C4BC>ж<EFBFBD><D0B6><EFBFBD>¼
|
|
|
|
|
{
|
|
|
|
|
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)//<2F><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>-1
|
|
|
|
|
{
|
|
|
|
|
int i,result;
|
|
|
|
|
for(i=0;i<all;i++)
|
|
|
|
|
{
|
|
|
|
|
if(student[i].num==num_temp)
|
|
|
|
|
{
|
|
|
|
|
result=1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(result==1)
|
|
|
|
|
return i;
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
int Inputoneperson(int i)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>¼
|
|
|
|
|
{
|
|
|
|
|
int j,sum=0;
|
|
|
|
|
int num_temp;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:");
|
|
|
|
|
scanf("%d",&num_temp);
|
|
|
|
|
if(num_temp>999999999)
|
|
|
|
|
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<6D><65>lessthan 20 numbers<72><73><EFBFBD><EFBFBD>");
|
|
|
|
|
scanf("%s",&student[i].name);
|
|
|
|
|
printf("Sex(M/W):");
|
|
|
|
|
scanf("%s",&student[i].sex);
|
|
|
|
|
printf("\n <20><><EFBFBD><EFBFBD>\t <20><>ѧ\t Ӣ<><D3A2>\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)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD>¼
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
i=all;
|
|
|
|
|
if(Inputoneperson(i))
|
|
|
|
|
{
|
|
|
|
|
all++;
|
|
|
|
|
Inputfile(i,fp);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void Inputfile(int i,FILE *fp) //<2F><><EFBFBD>±<EFBFBD>Ϊi <20>ļ<EFBFBD>¼д<C2BC><D0B4><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
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)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
{
|
|
|
|
|
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)//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
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()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char filename[10],ch;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
printf("Name the new file<6C><65>(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<all;i++)
|
|
|
|
|
Inputfile(i,fp);
|
|
|
|
|
Show();
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
void Delete(FILE *fp)//ɾ<><C9BE><EFBFBD><EFBFBD>¼
|
|
|
|
|
{
|
|
|
|
|
int i,j,k,num_temp,choice2,t=0;
|
|
|
|
|
char str[5];
|
|
|
|
|
printf("make sure you will delete it(Y/N)");
|
|
|
|
|
gets(str);
|
|
|
|
|
if(str[0]!='N'&&str[0]!='n');
|
|
|
|
|
t=1;
|
|
|
|
|
if(t==1)
|
|
|
|
|
{
|
|
|
|
|
printf("Inpute the number someone you needed:(<28><>10141301)");
|
|
|
|
|
scanf("%d",&num_temp);
|
|
|
|
|
i=CheckNumber(num_temp);
|
|
|
|
|
if(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<all;j++)
|
|
|
|
|
{
|
|
|
|
|
strcpy(student[j].name,student[j+1].name);
|
|
|
|
|
student[j].sex=student[j+1].sex;
|
|
|
|
|
student[j].num=student[j+1].num;
|
|
|
|
|
for(k=0;k<4;k++)
|
|
|
|
|
{
|
|
|
|
|
student[j].mark[k]=student[j+1].mark[k];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
all--;
|
|
|
|
|
for(k=0;k<all;k++)
|
|
|
|
|
Inputfile(k,fp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("numbody is the number:%d\n",num_temp);
|
|
|
|
|
}
|
|
|
|
|
void Alter(FILE *fp)//<2F>ļ<DEB8>¼<EFBFBD><C2BC>Ϣ
|
|
|
|
|
{
|
|
|
|
|
int i,j,num_temp,sum=0,t;
|
|
|
|
|
char str[5];
|
|
|
|
|
printf("make sure you will alter it(Y/N)");
|
|
|
|
|
gets(str);
|
|
|
|
|
if(str[0]!='N'&&str[0]!='n')
|
|
|
|
|
t=1;
|
|
|
|
|
if(t==1)
|
|
|
|
|
{
|
|
|
|
|
printf("Inpute the number somesoe you want to alter:(<28><>10141301)");
|
|
|
|
|
scanf("%d",&num_temp);
|
|
|
|
|
i=CheckNumber(num_temp);
|
|
|
|
|
if(i>=0)
|
|
|
|
|
{
|
|
|
|
|
student[i].num=num_temp;
|
|
|
|
|
printf("Input name<6D><65>lessthan 20 numbers<72><73><EFBFBD><EFBFBD>");
|
|
|
|
|
scanf("%s",&student[i].name);
|
|
|
|
|
printf("Sex(M/W):");
|
|
|
|
|
scanf("%s",&student[i].sex);
|
|
|
|
|
printf("\n <20><><EFBFBD><EFBFBD>\t <20><>ѧ\t Ӣ<><D3A2>\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;j<all;j++)
|
|
|
|
|
Inputfile(j,fp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("numbody is the number:%d\n",num_temp);
|
|
|
|
|
}
|
|
|
|
|
int Sort_menu_choice()//ѡ<><D1A1><EFBFBD>ǰ<EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><C5BB>dzɼ<C7B3><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
int choice;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ(1 <20><>ѧ<EFBFBD><D1A7> 2 <20><>ƽ<EFBFBD><C6BD><EFBFBD>ɼ<EFBFBD>)<29><> ");
|
|
|
|
|
scanf("%d",&choice);
|
|
|
|
|
if((choice<0)||(choice>2))
|
|
|
|
|
printf("error!");
|
|
|
|
|
}
|
|
|
|
|
while((choice<0)||(choice>2));
|
|
|
|
|
return(choice);
|
|
|
|
|
}
|
|
|
|
|
void Sort_num()//ѡ<><D1A1><EFBFBD>ǰ<EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
int i,j;
|
|
|
|
|
for(i=0;i<all-1;i++)
|
|
|
|
|
{
|
|
|
|
|
for(j=i+1;j<all;j++)
|
|
|
|
|
{
|
|
|
|
|
if(student[i].num>student[j].num)
|
|
|
|
|
exchange(i,j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void Sort_mark()//ѡ<><D1A1><EFBFBD>ǰ<EFBFBD><C7B0>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
int i,j;
|
|
|
|
|
for(i=0;i<all-1;i++)
|
|
|
|
|
{
|
|
|
|
|
for(j=i+1;j<all;j++)
|
|
|
|
|
{
|
|
|
|
|
if(student[i].mark[3]<student[j].mark[3])
|
|
|
|
|
exchange(i,j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void Sort_menu()//<2F><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
switch(Sort_menu_choice())
|
|
|
|
|
{
|
|
|
|
|
case 1:Sort_num();
|
|
|
|
|
Sort_save();
|
|
|
|
|
clear();
|
|
|
|
|
break;
|
|
|
|
|
case 2:Sort_mark();
|
|
|
|
|
Sort_save();
|
|
|
|
|
clear();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void Sort_save()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
if((fp=fopen("student.txt","wb"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Fail to save the file!\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<all;i++)
|
|
|
|
|
Inputfile(i,fp);
|
|
|
|
|
Show();
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void set_psw()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
char key_set[20],key_check[20],c;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
do
|
|
|
|
|
{ printf("You must set password first!\n");
|
|
|
|
|
printf("Enter password:(lessthan 12 numbers and key'.'for end)\n");
|
|
|
|
|
for(i=0;(c=getch())!=' ';i++)
|
|
|
|
|
{
|
|
|
|
|
putchar('*');
|
|
|
|
|
key_set[i]=c;
|
|
|
|
|
}
|
|
|
|
|
key_set[i]='\0';
|
|
|
|
|
printf("\n------------\n");
|
|
|
|
|
printf("conform password:");
|
|
|
|
|
for(i=0;(c=getch())!=' ';i++)
|
|
|
|
|
{
|
|
|
|
|
putchar('*');
|
|
|
|
|
key_check[i]=c;
|
|
|
|
|
}
|
|
|
|
|
key_check[i]='\0';
|
|
|
|
|
printf("\n------------\n");
|
|
|
|
|
if(strcmp(key_set,key_check)==0)
|
|
|
|
|
{printf("Set password success!");
|
|
|
|
|
strcpy(password,key_set);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("error!\n");
|
|
|
|
|
}
|
|
|
|
|
while(strcmp(key_set,key_check)!=0);
|
|
|
|
|
clear();
|
|
|
|
|
fp=fopen("password.txt","wb");
|
|
|
|
|
fprintf(fp,"%s",password);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int key_check()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
|
|
|
|
|
{
|
|
|
|
|
unsigned int i=1,j=1;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
char pword[20],c;
|
|
|
|
|
if((fp=fopen("password.txt","rb"))==NULL)
|
|
|
|
|
{
|
|
|
|
|
fp=fopen("password.txt","a");
|
|
|
|
|
set_psw();
|
|
|
|
|
}
|
|
|
|
|
fscanf(fp,"%s",password);
|
|
|
|
|
fclose(fp);
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
printf("\nInput password<72><64>key' 'for end(%d/three times)",j);
|
|
|
|
|
for(j=0;(c=getch())!=' ';j++)
|
|
|
|
|
{
|
|
|
|
|
putchar('*');
|
|
|
|
|
pword[j]=c;
|
|
|
|
|
}
|
|
|
|
|
pword[j]='\0';
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
while(strcmp(pword,password)!=0&&i<=3);
|
|
|
|
|
if(i<=3)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("You have tryed for three times,fail to open the file!\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|