#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
#define STU struct student
STU
{long num;
char name[20];
int sex;
long classes;
long birth;
};
/***************************input****************************/
void input(int k,STU *st)
{int n,i;
FILE *fp;
long b;
STU student_1;
printf("Please input your number[ ]\b\b\b\b\b\b\b");
scanf("%ld",&b);
for(i=0;i<k;i++)
if(st[i].num==b)
{printf("\nThe school number is repeat!\n");
free(st);menu();}
else
{printf("\nPlease input your name[ ]\b\b\b\b\b\b\b\b\b");
scanf("%s",student_1.name);
printf("\nPlease input you sex male(1) or female(2)[ ]\b\b\b\b\b\b\b");
scanf("%d",&student_1.sex);
printf("\nPlease input you Class[ ]\b\b\b\b\b\b\b");
scanf("%ld",&student_1.classes);
printf("\nPlease input you date of birth[ ]\b\b\b\b\b\b\b");
scanf("%ld",&student_1.birth);
fp=fopen("student1.txt","ab");
if(!fp)
{printf("Document error! ");
exit(0);}
else
{fprintf(fp,"%ld%s%d%ld%ld",b,student_1.name,student_1.sex,student_1.classes,student_1.birth);
printf("%ld%s%d%ld%ld",b,student_1.name,student_1.sex,student_1.classes,student_1.birth);
n=k+1;
rewind(fp);
fprintf(fp,"%d",n);
fclose(fp);
free(st);
menu();}
}}
/******************************inquiries********************************/
void inquiries(int k,STU *st)
{int i,j=0,n,p,w;
long a;
do
{printf("\n\t\t**************INQUIRIE MENU**************\n\n");
printf("\t\t\t1.Inquiries school number\n");
printf("\t\t\t2.Inquiries classes\n");
printf("\t\t\t3.Inquiries date of birth\n");
printf("\t\t\t4.Back to menu\n");
printf("\n\n\t\t******************************************\n");
printf("Choice your number(1-4)[ ]\b\b\b\b\b\b\b");
scanf("%d",&n);
if(n<1&&n>4)
{w=1;getchar();}
else
w=0;
}while(w==1);
switch(n)
{case 1:j=0;printf("Please input your inquiries school number[ ]\b\b\b\b\b\b\b");
scanf("%ld",&a);
for(i=0;i<k;i++)
{if(st[i].num==a)
{j=1;p++;
printf("%ld%s%d%ld%ld",st[i].num,st[i].name,st[i].sex,st[i].classes,st[i].birth);}
}
if(!j)
{printf("There is no this school number!");}
else
{printf("Success.There are %d student.",p);}
inquiries(k,st);break;
case 2:j=0;printf("Please input you class number[ ]\b\b\b\b\b\b\b");
scanf("%ld",&a);
for(i=0;i<k;i++)
{if(st[i].classes==a)
{i=1;p++;
printf("%d%s%d%d%ld",st[i].num,st[i].name,st[i].sex,st[i].classes,st[i].birth);}
}
if(!j)
{printf("There is no this Class!");}
else
{printf("Success.There are %d student.",p);}
inquiries(k,st);break;
case 3:j=0;
printf("Please input you date of birth[ ]\b\b\b\b\b\b\b");
scanf("%ld",&a);
for(i=0;i<k;i++)
{if(st[i].birth==a)
{i=1;p++;
printf("%d%s%d%d%ld",st[i].num,st[i].name,st[i].sex,st[i].classes,st[i].birth);}
}
if(!j)
{printf("There is no this date of birth!");}
else
{printf("Success.There are %d student.",p);}
inquiries(k,st);break;
case 4:free(st);menu();break;
}
}
/***************************change************************/
void change(int k,STU *st)
{int a,i,n,w,j=0,p,q=0;
FILE *fp;
fp=fopen("student1","wb");
if(!fp)
{printf("Document error! ");
exit(0);}
printf("Plese input you change number[ ]\b\b\b\b\b\b\b");
scanf("%ld",&a);
for(i=0;i<k;i++)
if(st[i].num==a)
{j=1;p=i;
do
{printf("\n\t\t***************CHANGES MENU***************");
printf("\n\t\t\t1.Change Number");
printf("\n\t\t\t2.Change Name");
printf("\n\t\t\t3.Change Sex");
printf("\n\t\t\t4.Change classes");
printf("\n\t\t\t5.Change Date of birth");
printf("\n\t\t\t6.Back");
printf("\n\t\t***********************************************\n");
printf("\nChoice your number(1-6)[ ]\b\b\b\b\b\b\b");
scanf("%d",&n);
if(n<1&&n>6)
{w=1;getchar();}
else w=0;
}while(w==1);
switch(n)
{case 1:printf("\nPlease input your new number[ ]\b\b\b\b\b\b\b");
scanf("%ld",&st[i].num);q=1;change(k,st);break;
case 2:printf("\nPlease input your new name[ ]\b\b\b\b\b\b\b\b\b");
scanf("%s",st[i].name);q=1;change(k,st);break;
case 3:printf("\nPlease input your right sexmale(M) or female(f))[ ]\b\b\b\b\b\b\b");
scanf("%d",&st[i].sex);q=1;change(k,st);break;
case 4:printf("\nPlease input your new classes[ ]\b\b\b\b\b\b\b");
scanf("%ld",&st[i].classes);q=1;change(k,st);break;
case 5:printf("\nPlease input your right date of birth[ ]\b\b\b\b\b\b\b");
scanf("%ld",st[i].birth);q=1;change(k,st);break;
case 6:rewind(fp);
}
fprintf(fp,"%d",k);
for(i=0;i<k;i++)
fprintf(fp,"%ld%s%d%ld%ld",st[i].num,st[i].name,st[i].sex,st[i].classes,st[i].birth);
if(p)
printf("The changed information are:%ld%s%d%ld%ld",st[q].num,st[q].name,st[q].sex,st[q].classes,st[q].birth);
free(st);fclose(fp);menu();
}
if(!j)
{printf("There is no this student");free(st);menu();}
}
/******************************delete****************************/
delete(int k,STU *st)
{int i,j,b;
long a;
FILE *fp;
printf("Please input your delete school number[ ]\b\b\b\b\b\b\b");
scanf("%ld",&a);
for(i=0;i<k;i++)
if(st[i].num==a)
{printf("The deleted information are:%ld%s%d%ld%ld",st[i].num,st[i].name,st[i].sex,st[i].classes,st[i].birth);
for(;i<k-1;i++)
{st[i].num=st[i+1].num;
strcpy(st[i].name,st[i+1].name);
st[i].sex=st[i+1].sex;
st[i].classes=st[i+1].classes;
st[i].birth=st[i+1].birth;
}
j=k-1;
fp=fopen("student1","wb");
if(!fp)
{printf("Document error! ");
exit(0);}
rewind(fp);
fprintf(fp,"%d",j);
for(i=0;i<j;i++)
fprintf(fp,"%ld%s%d%ld%ld",st[i].num,st[i].name,st[i].sex,st[i].classes,st[i].birth);
free(st);fclose(fp);menu();
break;
}
else
{printf("There is no this schol number!");
free(st);fclose(fp);menu();
}
}
/**********************************statistic****************************/
void statistic(int k,STU *st)
{int n,w,i,b,p=0;
long a;
int name[10];
do
{printf("\n\t\t***************STATISTIC MENU***************\n\n");
printf("\t\t\t1.Name statistic\n");
printf("\t\t\t2.classes statistic\n");
printf("\t\t\t3.Sex statistic\n");
printf("\t\t\t4.Date of birth statistic\n");
printf("\t\t\t5.Back");
printf("\n\n\t\t********************************************\n");
printf("Choice your number(1-5)[ ]\b\b\b\b\b\b\b");
scanf("%d",&n);
if(n<1&&n>5)
{w=1;getchar();}
else
w=0;
}while(w==1);
switch(n)
{case 1:printf("\nPlease input you statistic name[ ]\b\b\b\b\b\b\b\b\b");
scanf("%s",name);
for(i=0;i<k;i++)
{if(!strcmp(st[i].name,name))
{p++;
printf("%ld%s%d%ld%ld",st[i].num,st[i].name,st[i].sex,st[i].classes,st[i].birth);
}
}
if(p)
printf("There are %d students.",p);
statistic(k,st);
case 2:printf("\nPlease input you classes[ ]\b\b\b\b\b\b\b");
scanf("%ld",&a);
for(i=0;i<k;i++)
{if(st[i].classes==a)
{p++;
printf("%ld%s%d%ld%ld",st[i].num,st[i].name,st[i].sex,st[i].classes,st[i].birth);
}
}
if(p)
printf("There are %d students.",p);
statistic(k,st);
case 3:printf("\nPlease input you statistic sex M or