c语言课程设计 (问题很长,能帮我回答1~10的其中一个分题都万分感谢了!

2024-12-02 23:32:39
推荐回答(1个)
回答(1):

我的地震物质管理系统

比改下可以用哈
#include
#include
#define N 500
struct volunteer{char name[10];
char sex;
int age;
int phoneqianwuwei;
long phonehouliuwei;
int year;
int month;
int day;}vol[N];
struct material{char type[10];
int worth;
char supportor[20];
char dest[20];}mat[N];
void new()
{
FILE *fp;
int i,j;
char x;
printf("name(eg:tansonglin) sex(m/w) age(16-60)\n");
printf("phoneqianwuwei(eg:13096) phonehouliuwei(eg: 357573) year month day (eg:2008 5 12)\n");
for(i=0;i<500;i++)
{
scanf("%s %c %d %d %ld %d %d %d",vol[i].name,&vol[i].sex,&vol[i].age,&vol[i].phoneqianwuwei,&vol[i].phonehouliuwei,&vol[i].year,&vol[i].month,&vol[i].day);
getchar();
printf("continue press y,end press n\n");
scanf("%c",&x);
if(x=='n')break;
else
printf("next person:\n");
}
if((fp=fopen("vol_list","w"))==NULL)
{printf("cannot open this file\n");
return;}
for(j=0;j<=i;j++)
if(fwrite(&vol[j],sizeof(struct volunteer),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}

void seeker()
{
int i;
char name[10];
FILE *fp;
if((fp=fopen("vol_list","r"))==NULL)
{printf("cannot open this file");
return;}
printf("Which person do you want to seek?Please input his or her name:\n");
scanf("%s",name);
for(i=0;i {
fread(&vol[i],sizeof(struct volunteer),1,fp);
if(strcmp(name,vol[i].name)==0)
{printf("%s %c %d %d %ld %d %d %d\n",vol[i].name,vol[i].sex,vol[i].age,vol[i].phoneqianwuwei,vol[i].phonehouliuwei,vol[i].year,vol[i].month,vol[i].day);
}
}
fclose(fp);
}

void add()
{
int i;
FILE *fp;
fp=fopen("vol_list","a");
printf("please input his or her number:\n");
scanf("%d",&i);
printf("Please input his or her information:\n");
printf("name(eg:tansonglin) sex(m/w) age(16-60)\n");
printf("phoneqianwuwei(eg:13096) phonehouliuwei(eg: 375753) startday(eg:2008 5 12)\n");
scanf("%s %c %d %ld %d %d %d",
vol[i].name,&vol[i].sex,&vol[i].age,&vol[i].phoneqianwuwei,&vol[i].phonehouliuwei,&vol[i].year,&vol[i].month,&vol[i].day);
fwrite(&vol[i],sizeof(struct volunteer),1,fp);
fclose(fp);
}

void all()
{
FILE *fp;
int i;
fp=fopen("vol_list","r");
printf("*******************************************************\n");
for(i=0;i {fread(&vol[i],sizeof(struct volunteer),1,fp);
if(feof(fp)) break;
printf("%s %c %d %d %ld %d %d %d\n",vol[i].name,vol[i].sex,vol[i].age,vol[i].phoneqianwuwei,vol[i].phonehouliuwei,vol[i].year,vol[i].month,vol[i].day);
}
printf("*******************************************************\n");
fclose(fp);
}

void del()
{
FILE *fp;
int i,a,b;
char name[10];
fp=fopen("vol_list","r");
for(i=0;i<500;i++)
{
fread(&vol[i],sizeof(struct volunteer),1,fp);
if(feof(fp))break;
}
a=i-1;
printf("Please input the information you want to delete.\n");
scanf("%s",name);
for(i=0;i<=a;i++)
{
if(strcmp(name,vol[i].name)==0)
{
b=i;
break;
}
}

fclose(fp);
fp=fopen("vol_list","w");
for(i=0;ifwrite(&vol[i],sizeof(struct volunteer),1,fp);
for(i=b;ifwrite(&vol[i+1],sizeof(struct volunteer),1,fp);
fclose(fp);
}

void newm()
{
FILE *fp;
int i,j;
char x;
printf("type(eg:temp),worth($100),supportor(eg:tansonglin),dest(eg:wenchuan)\n");
for(i=0;i {
scanf("%s %d %s %s",mat[i].type,&mat[i].worth,mat[i].supportor,mat[i].dest);
getchar();
printf("continue press y,end press n\n");
scanf("%c",&x);
if(x=='n')break;
else
printf("next material:\n");
}
if((fp=fopen("mat_list","w"))==NULL)
{printf("cannot open this file\n");
return;}
for(j=0;j<=i;j++)
if(fwrite(&mat[j],sizeof(struct material),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void seekerm()
{
int i;
char type[10];
FILE *fp;
if((fp=fopen("mat_list","r"))==NULL)
{printf("cannot open this file");
return;}
printf("Which material do you want to seek?Please input it's type:\n");
scanf("%s",type);
for(i=0;i<500;i++)
{
fread(&mat[i],sizeof(struct material),1,fp);
if(strcmp(type,mat[i].type)==0)
{printf("%s %d %s %s\n",mat[i].type,&mat[i].worth,mat[i].supportor,mat[i].dest);
break;
}
}
fclose(fp);
}

void f()
{
int i;
printf("OK!\n");
printf("Please press any key to go on.\n");
printf("*******************************************************\n");
scanf("%d",&i);
}

main()
{
char a,b,d;
do{
clrscr();
printf(" Welcome to my software! ");
printf("\n");printf("\n");
printf("*************************************************************** \n");
printf(" 1.New vollunteer register. \n");
printf(" 2.Volunteer's message seeker. \n");
printf(" 3.Add new volunteer. \n");
printf(" 4.All volunteers'information. \n");
printf(" 5.Delete volunteer. \n");
printf(" 6.New material register. \n");
printf(" 7.Material message seeker. \n");
printf(" 0.Exit. \n");
printf("*************************************************************** \n");
printf("What do you want to do? please press 0~7 \n");
scanf("%c",&b);
switch(b)
{case'1':new();f();break;
case'2':seeker();f();break;
case'3':add();f();break;
case'4':all();f();break;
case'5':del();f();break;
case'6':newm();f();break;
case'7':seekerm();f();break;
case'0':break;}
}while(b!='0');
}