第1个回答 2013-12-30
#include"stdio.h"
#include"string.h"
#include"windows.h"
#define N 3
struct USER
{ char stu_number[6];
char stu_month[12];
float stu_WR;
float stu_PR;
float stu_GR;
float total;
} stu[N];
/*void write(struct USER s[],char*filemonth);
void read(struct USER s[],char*filemonth);
struct USER selectone(int i,char*filemonth);
void copyfile(char*filemonth1,char*filemonth2);*/
void input()
{
int i;
printf("please input %d user'information:\n",N);
printf("Number Month WR PG RG\n");
for(i=0;i<N;i++)
{
scanf("%s%s%f %f %f",stu[i].stu_number,stu[i].stu_month,&stu[i].stu_WR,&stu[i].stu_PR,
&stu[i].stu_GR);
stu[i].total=stu[i].stu_WR+stu[i].stu_PR+stu[i].stu_GR;
printf("total=%2.f\n",stu[i].total);
}
}
maxmin()
{ int i;
float max,min;
max=min=0;
for(i=0;i<N;i++)
{ if(max<stu[i].total) max=stu[i].total;
if(min>stu[i].total) min=stu[i].total;
}
printf("费用最高的用户为:%d\n,费用最低的用户为:%d\n",max,min);
}
main()
{ int sel;
printf("***************************\n");
printf("1.请输入当月水、电、气费用并统计费用总和\n");
printf("2.求出费用最高和最低的用户编号\n");
printf("4.查询所有费用\n");
printf("5.查询最高和最低房屋编号\n");
printf("6.退出\n");
printf("请选择: \n");
printf("***************************\n");
scanf("%d",&sel);
switch(sel)
{ case 1:printf("输入");input();break;
case 2:printf("求最");maxmin();break;
case 4:printf("查询");break;
case 5:printf("查询最高和最低");break;
case 6:exit(0);break;
default:printf("选择错误,退出!");exit(0);break;
}
}
/*write(stu,file1);
printf("\nChoose a user:1-%d\n",N);
scanf("%d",&k);
unit=selectone(k,file1);
printf("%s\%s\t%f\t%f\t%f\t%d\n",user.stu_number,user.stu_month,user.WR,user.PR,
user.GR,user.total);
copyfile(file1,file2);
read(file1,file2);
for(i=0;i<N;i++)
printf("%s\t%s\t%c\t%d\t%.2f\t%.2f\t%.2f\t%.2f\n",stu2[i].stu_number,stu2[i].stu_month,stu2[i].WR,stu2[i].PR,
stu2[i].GR,].stu2[i]total);
}
void write(struct USER s[],char*filemonth)
{ FILE *fp;
if((fp=fopen(filemonth,"wb"))==NULL)
{ printf("\nCan't open this file!\n");
exit(0);
}
fwrite(s,sizeof(struct USER),N,fp);
if(ferror(fp))
{ printf("File Erroe!\n");
exit(0);
}
fclose(fp);
printf("\n%s write finished!\n",filemonth);
}
void write(struct USER s[],char*filemonth)
{ FILE*fp;
if((fp=fopen(filemonth,"rb"))==NULL)
{ printf("\nCan't open this file!\n");
exit(0);
}
fread(s,sizeof(struct USER),N,fp);
if(ferror(fp))
{ printf("File Erroe!\n");
exit(0);
}
fclose(fp);
printf("\n%s write finished!\n",filemonth);
}
struct USER selectone(int i,char*filemonth)
{ FILE*fp;
struct USER sone;
if((fp=fopen(filemonth,"rb"))==NULL)
{ printf("\nCan't open this file!\n");
exit(0);
}
fseek(fp,(i-1)*sizeof(struct USER),0);
fread(&sone,sizeof(struct USER),1,fp);
if(ferror(fp))
{ printf("File Erroe!\n");
exit(0);
}
fclose(fp);
return sone;
}
void copyfile(char*filemonth1,char*filemonth2)
{ FILE*fp,*fp2;
char ch;
if((fp1=fopen(filemonth,"rb"))==NULL)
{ printf("\nCan't open this file!\n");
exit(0);
}
if((fp2=fopen(filemonth,"wb"))==NULL)
{ printf("\nCan't open this file!\n");
exit(0);
}
while((ch=fgetc(fp1))!=EOF)
fputc(ch,fp2);
fclose(fp1);
fclose(fp2);
printf("\n%s to %s copy finished!\n",filemonth1,filemonth2);
}*/