second commit

master
彭正财 6 years ago
parent 5bb59a7444
commit 434913bd3e

@ -0,0 +1,124 @@
void select()
{
FILE *fp,*ff;
int i,n;
if((fp=fopen("a.txt","w"))==NULL)
{
printf("file open error");
exit(0);
}
printf("输入多少位学生的信息\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("请输入学号:\n");
scanf("%d",&student[i].id);
fprintf(fp,"%d ",student[i].id);
printf("请输入班级:\n");
scanf("%d",&student[i].class);
fprintf(fp,"%d ",student[i].class);
printf("请输入姓名:\n");
scanf("%s",&student[i].name);
fprintf(fp,"%s ",student[i].name);
printf("请输入开始上机时间(小时):\n");
scanf("%d",&student[i].time_beginhour);
fprintf(fp,"%d ",student[i].time_beginhour);
printf("请输入开始上机时间(分钟):\n");
scanf("%d",&student[i].time_beginminute);
fprintf(fp,"%d ",student[i].time_beginminute);
printf("请输入结束上机时间(小时):\n");
scanf("%d",&student[i].time_endhour);
fprintf(fp,"%d ",student[i].time_endhour);
printf("请输入结束上机时间(分钟):\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);/*存放学生人数*/
fclose(ff);
printf("保存成功");
}
void count()
{
FILE *fp;
int id,i=0,j,money;
printf("请输入你的学号\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("学号;%d\n",student[i].id);
printf("班级;%d\n",student[i].class);
printf("姓名;%s\n",student[i].name);
printf("开始上机时间;%d:%d\n",student[i].time_beginhour,student[i].time_beginminute);
printf("结束上机时间;%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("本次上机的费用为:%d",money);
}
void add()
{
int i;
int n,j;
printf("请输入要增加多少人的信息\n");
scanf("%d",&n);
FILE *fp,*ff;
ff=fopen("b.txt","r");
fscanf(ff,"%d",&i);
fclose(ff);
fp=fopen("a.txt","a");
printf("请输入要增加的学生信息\n");
for(j=1;j<=n;j++)
{
printf("请输入学号:\n");
scanf("%d",&student[i+j].id);
fprintf(fp,"%d ",student[i+j].id);
printf("请输入班级:\n");
scanf("%d",&student[i+j].class);
fprintf(fp,"%d ",student[i+j].class);
printf("请输入姓名:\n");
scanf("%s",&student[i+j].name);
fprintf(fp,"%s ",student[i+j].name);
printf("请输入开始上机时间(小时):\n");
scanf("%d",&student[i+j].time_beginhour);
fprintf(fp,"%d ",student[i+j].time_beginhour);
printf("请输入开始上机时间(分钟):\n");
scanf("%d",&student[i+j].time_beginminute);
fprintf(fp,"%d ",student[i+j].time_beginminute);
printf("请输入结束上机时间(小时):\n");
scanf("%d",&student[i+j].time_endhour);
fprintf(fp,"%d ",student[i+j].time_endhour);
printf("请输入结束上机时间(分钟):\n");
scanf("%d",&student[i+j].time_endminute);
fprintf(fp,"%d\n",student[i+j].time_endminute);
}
fclose(fp);
printf("保存成功");
ff=fopen("b.txt","w");
fprintf(ff,"%d",i+n);
fclose(ff);
}
Loading…
Cancel
Save