You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pzc/输入学生信息、计算、增加学生信息.c

125 lines
3.2 KiB

6 years ago
void select()
{
FILE *fp,*ff;
int i,n;
if((fp=fopen("a.txt","w"))==NULL)
{
printf("file open error");
exit(0);
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:\n");
scanf("%d",&student[i].id);
fprintf(fp,"%d ",student[i].id);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>༶:\n");
scanf("%d",&student[i].class);
fprintf(fp,"%d ",student[i].class);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",&student[i].name);
fprintf(fp,"%s ",student[i].name);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD>Сʱ<EFBFBD><EFBFBD>:\n");
scanf("%d",&student[i].time_beginhour);
fprintf(fp,"%d ",student[i].time_beginhour);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>:\n");
scanf("%d",&student[i].time_beginminute);
fprintf(fp,"%d ",student[i].time_beginminute);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD>Сʱ<EFBFBD><EFBFBD>:\n");
scanf("%d",&student[i].time_endhour);
fprintf(fp,"%d ",student[i].time_endhour);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>:\n");
scanf("%d",&student[i].time_endminute);
fprintf(fp,"%d\n",student[i].time_endminute);
}
if(fclose(fp))
{
printf("Can not close the file\n");
exit(0);
}
ff=fopen("b.txt","w");
fprintf(ff,"%d",i);/*<2A><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
fclose(ff);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>");
}
void count()
{
FILE *fp;
int id,i=0,j,money;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>\n");
scanf("%d",&id);
if((fp=fopen("a.txt","r"))==NULL)
{
printf("file open error");
exit(0);
}
while(!feof(fp))
{
fscanf(fp,"%d%d%s%d%d%d%d",&student[i].id,&student[i].class,&student[i].name,&student[i].time_beginhour,&student[i].time_beginminute,&student[i].time_endhour,&student[i].time_endminute);
i++;
j=i;
}
for(i=0;i<=j;i++)
{
if(student[i].id==id)
{
printf("ѧ<EFBFBD>ţ<EFBFBD>%d\n",student[i].id);
printf("<EFBFBD><EFBFBD><EFBFBD>%d\n",student[i].class);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s\n",student[i].name);
printf("<EFBFBD><EFBFBD>ʼ<EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD>䣻%d:%d\n",student[i].time_beginhour,student[i].time_beginminute);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD>䣻%d:%d\n",student[i].time_endhour,student[i].time_endminute);
money=(student[i].time_endhour-student[i].time_beginhour)*60*m+(student[i].time_endminute-student[i].time_beginminute)*m;
}
}
if(fclose(fp))
{
printf("Can not close the file\n");
exit(0);
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD>Ϊ:%d",money);
}
void add()
{
int i;
int n,j;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>Ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>Ϣ\n");
scanf("%d",&n);
FILE *fp,*ff;
ff=fopen("b.txt","r");
fscanf(ff,"%d",&i);
fclose(ff);
fp=fopen("a.txt","a");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ\n");
for(j=1;j<=n;j++)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:\n");
scanf("%d",&student[i+j].id);
fprintf(fp,"%d ",student[i+j].id);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>༶:\n");
scanf("%d",&student[i+j].class);
fprintf(fp,"%d ",student[i+j].class);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",&student[i+j].name);
fprintf(fp,"%s ",student[i+j].name);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD>Сʱ<EFBFBD><EFBFBD>:\n");
scanf("%d",&student[i+j].time_beginhour);
fprintf(fp,"%d ",student[i+j].time_beginhour);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>:\n");
scanf("%d",&student[i+j].time_beginminute);
fprintf(fp,"%d ",student[i+j].time_beginminute);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD>Сʱ<EFBFBD><EFBFBD>:\n");
scanf("%d",&student[i+j].time_endhour);
fprintf(fp,"%d ",student[i+j].time_endhour);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>:\n");
scanf("%d",&student[i+j].time_endminute);
fprintf(fp,"%d\n",student[i+j].time_endminute);
}
fclose(fp);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>");
ff=fopen("b.txt","w");
fprintf(ff,"%d",i+n);
fclose(ff);
}