你看这个行不?
# include"stdio.h"
# include"string.h"
# include"stdlib.h"
# define N 100
char sel1;
char sel2;
int fm=0;
int pm=0;
struct flight
{int flightnum;
int starttime;
int arrivedtime;
char start[10];
char arrived[10];
int portermax;
int money;
int flytime;
char date[10];
}s[N];
struct porter
{char name[10];
char unit[10];
int licencenum;
int ticketdate;
int flightnum;
int sizenum;
}a[N];
void input()
{int i=0;
int num;
int k;
scanf("%d",&num);
while(num==1)
{printf("Please input the new flightnumber:");
scanf("%d",&s[i].flightnum);
printf("Please input the starttime:");
scanf("%d",&s[i].starttime);
printf("Please input the arrivedtime:");
scanf("%d",&s[i].arrivedtime);
printf("Please input the start:");
scanf("%s",s[i].start);
printf("Please input the arrived:");
scanf("%s",s[i].arrived);
printf("Please input the portermax:");
scanf("%d",&s[i].portermax);
printf("Please input the money:");
scanf("%d",&s[i].money);
printf("Please input the flytime:");
scanf("%d",&s[i].flytime);
printf("please input the date");
scanf("%s",s[i].date);
i++;
printf("need to creade another new flight? yes=1 no=other.");
scanf("%d",&num);
};
fm=i;
printf("Return to main menu?(Yes=1)");
scanf("%d",&k);
if (k==1)
main();
}
void findflight()
{ int i;
int j;
int k;
char st[10];
char ar[10];
int sn;
printf("Please input the start:");
scanf("%s",st);
printf("Please input the arrived:");
scanf("%s",ar);
printf(" fltnum start arrived starttime arrtime max money flt date\n");
sn=0;
for(i=0;i<=fm;i++)
{if ((strcmp(st,s[i].start)==0)&&(strcmp(ar,s[i].arrived)==0))
{printf("%7d%10s%10s%10d%10d%5d%6d%4d%5s\n",s[i].flightnum,s[i].start,s[i].arrived,
s[i].starttime,s[i].arrivedtime,s[i].portermax,s[i].money,s[i].flytime,s[i].date);
sn=1;s[i].portermax--;}}
if (sn==0)
{printf("the flight you need is not found!please check it!\n");
printf("Return to main menu?(Yes=1)");
scanf("%d",&k);
if (k==1)
main();}
printf("Please input the name:");
scanf("%s",a[pm].name);
printf("Please input the unit:");
scanf("%s",a[pm].unit);
printf("Please input the licencenum:");
scanf("%d",&a[pm].licencenum);
printf("Please input the ticketdate:");
scanf("%d",&a[pm].ticketdate);
printf("Please input the flightnum:");
scanf("%d",&a[pm].flightnum);
printf("Please input the sizenum:");
scanf("%d",&a[pm].sizenum);
pm=pm+1;
printf("Return to main menu?(Yes=1)");
scanf("%d",&k);
if (k==1)
main();
}
void passticket()
{int i;
int ptfn;
int ptsn;
int dm;
int yn;
int k;
printf("please input the flight num:");
scanf("%d",&ptfn);
printf("please input the size num:");
scanf("%d",&ptsn);
for (i=0;i<=fm;i++)
{if ((s[i].flightnum==ptfn)&&(a[i].sizenum==ptsn))
{dm=i;
s[i].portermax++;
printf("please back the money!\n");}}
printf("would you like to pass the porter?");
printf("yes=1,no=2");
scanf("%d",&yn);
if (yn==1)
{int j;
for (j=dm;j<=pm;j++)
{a[j]=a[j+1];
}
pm=pm-1;
printf("\nthe porter has been delete!\n");}
printf("Return to main menu?(Yes=1)");
scanf("%d",&k);
if (k==1)
main();
}
void findflightzl()
{int fln;
int i;
int j;
printf("please input the flightnum you want to find:");
scanf("%d",&fln);
printf(" fltnum start arrived starttime arrtime max money flt date\n");
for (i=0;i<=pm;i++)
{if (s[i].flightnum==fln)
printf("%7d%10s%10s%10d%10d%5d%6d%4d%5s\n",s[i].flightnum,s[i].start,s[i].arrived,
s[i].starttime,s[i].arrivedtime,s[i].portermax,s[i].money,s[i].flytime,s[i].date);
}
printf("Return to main menu?(Yes=1)");
scanf("%d",&j);
if (j==1)
main();
}
void findbydate()
{char da[10];
int i;
int j;
printf("please input the date you want to find:");
scanf("%s",&da);
printf(" fltnum start arrived starttime arrtime max money flt date\n");
for (i=0;i<=pm;i++)
{if (strcmp(s[i].date,da)==0)
printf("%7d%10s%10s%10d%10d%5d%6d%4d%5s\n",s[i].flightnum,s[i].start,s[i].arrived,
s[i].starttime,s[i].arrivedtime,s[i].portermax,s[i].money,s[i].flytime,s[i].date);
}
printf("Return to main menu?(Yes=1)");
scanf("%d",&j);
if (j==1)
main();
}
void mainmenu();
void newflight()
{ int i=fm;
int k;
printf("Please input the new flightnumber:");
scanf("%d",&s[i].flightnum);
printf("Please input the starttime:");
scanf("%d",&s[i].starttime);
printf("Please input the arrivedtime:");
scanf("%d",&s[i].arrivedtime);
printf("Please input the start:");
scanf("%s",s[i].start);
printf("Please input the arrived:");
scanf("%s",s[i].arrived);
printf("Please input the portermax:");
scanf("%d",&s[i].portermax);
printf("Please input the money:");
scanf("%d",&s[i].money);
printf("Please input the flytime:");
scanf("%d",&s[i].flytime);
printf("please input the date:");
scanf("%s",s[i].date);
fm=fm+1;
printf("Return to main menu?(Yes=1)");
scanf("%d",&k);
if (k==1)
main();
}
void passflight()
{int pfn;
int tm;
int yn;
int i;
int k;
printf("please input the flightnum you need:");
scanf("%d",&pfn);
for (i=0;i<=fm;i++)
{if (s[i].flightnum==pfn)
tm=i;}
printf("would you like to pass the flight?");
printf("yes=1,no=2");
scanf("%d",&yn);
if (yn==1)
{int j;
for (j=tm;j<=fm;j++)
{s[j]=s[j+1];}
fm=fm-1;
printf("the flight has been delete!\n");}
printf("Return to main menu?(Yes=1)");
scanf("%d",&k);
if (k==1)
main();
}
void findflightname()
{
int i;
int j;
char name[10];
printf("please input the name you want to find:");
scanf("%s",name);
printf(" name unit licnum ticdat flinum siznum\n");
for (i=0;i<=pm;i++)
{if (strcmp(a[i].name,name)==0)
printf("%10s%10s%10d%10d%10d%10d\n",a[i].name,a[i].unit,a[i].licencenum,a[i].ticketdate,
a[i].flightnum,a[i].sizenum);}
printf("Return to main menu?(Yes=1)");
scanf("%d",&j);
if (j==1)
main();
}
void find_start_arrived()
{
int i;
int j;
char st[10];
char ar[10];
printf("Please input the start:");
scanf("%s",st);
printf("Please input the arrived:");
scanf("%s",ar);
printf(" fltnum start arrived starttime arrtime max money flt date\n");
for(i=0;i<=fm;i++)
{if ((strcmp(st,s[i].start)==0)&&(strcmp(ar,s[i].arrived)==0))
printf("%7d%10s%10s%10d%10d%5d%6d%4d%5s\n",s[i].flightnum,s[i].start,s[i].arrived,
s[i].starttime,s[i].arrivedtime,s[i].portermax,s[i].money,s[i].flytime,s[i].date);}
printf("Return to main menu?(Yes=1)");
scanf("%d",&j);
if (j==1)
main();
}
void flightmanage();
void findbydate();
void findfly()
{
char find;
system("cls");
printf("\n");
printf("\n");
printf(" **********************************************************************\n");
printf(" * *\n");
printf(" * Flight find *\n");
printf(" * *\n");
printf(" **********************************************************************\n");
printf("\n");
printf("\n");
printf("\n");
printf(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" + +\n");
printf(" + Please choose: (input the serial number) +\n");
printf(" + +\n");
printf(" + +\n");
printf(" + 1. Find by flightnum. +\n");
printf(" + +\n");
printf(" + 2. Find by portername. +\n");
printf(" + +\n");
printf(" + 3. Find by datenum. +\n");
printf(" + +\n");
printf(" + 4. Find by start-arrived. +\n");
printf(" + +\n");
printf(" + 5. Return to the mainmenu. +\n");
printf(" + +\n");
printf(" + +\n");
printf(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("please select:");
scanf("%c",&find);
switch(find)
{
case '1' : findflightzl();break;
case '2' : findflightname();break;
case '3' : findbydate();break;
case '4' : find_start_arrived();break;
case '5' : main();break;
default : break;
}
}
void flightmanage();
void dayflightmanage()
{
int i;
int j;
char day[10];
printf("Please input date:");
scanf("%s",day);
printf(" fltnum start arrived starttime arrtime max money flt date\n");
for(i=0;i<=fm;i++)
{if (strcmp(day,s[i].date)==0)
printf("%7d%10s%10s%10d%10d%5d%6d%4d%5s\n",s[i].flightnum,s[i].start,s[i].arrived,s[i].starttime,s[i].arrivedtime,s[i].portermax,s[i].money,s[i].flytime,s[i].date);
}
printf("Return to main menu?(Yes=1) Return to flightmanage menu?(No=0)");
scanf("%d",&j);
if (j==1)
main();
else
flightmanage();
}
void recentmanage()
{
char stdate[10];
int cha=0;
int i;
int j;
int check=0;
printf("please input startdate:");
scanf("%s",stdate);
printf("\n");
printf(" fltnum start arrived starttime arrtime max money flt date\n");
for(i=0;i<=fm;i++)
if (strcmp(stdate,s[i].date)==0)
{printf("%7d%10s%10s%10d%10d%5d%6d%4d%5s\n",s[i].flightnum,s[i].start,s[i].arrived,
s[i].starttime,s[i].arrivedtime,s[i].portermax,s[i].money,s[i].flytime,s[i].date);
cha=i+1;
check=1;
for(i=cha;i<fm;i++)
{printf("%7d%10s%10s%10d%10d%5d%6d%4d%5s\n",s[i].flightnum,s[i].start,s[i].arrived,
s[i].starttime,s[i].arrivedtime,s[i].portermax,s[i].money,s[i].flytime,s[i].date); }
}
if (check==0)
{printf("can't find any flight!\n");}
printf("Return to main menu?(Yes=1)");
scanf("%d",&j);
if (j==1)
main();
}
void mainmenu()
{
system("cls");
printf("\n");
printf("\n");
printf(" **********************************************************************\n");
printf(" * *\n");
printf(" * Welcome to use the system *\n");
printf(" * *\n");
printf(" **********************************************************************\n");
printf("\n");
printf("\n");
printf("\n");
printf(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" + +\n");
printf(" + Please choose: (input the serial number) +\n");
printf(" + +\n");
printf(" + +\n");
printf(" + 1. Book ticket(s). +\n");
printf(" + +\n");
printf(" + 2. Return a ticket. +\n");
printf(" + +\n");
printf(" + 3. Scheduled flight manage. +\n");
printf(" + +\n");
printf(" + 4. Get information. +\n");
printf(" + +\n");
printf(" + 5. Save and exit. +\n");
printf(" + +\n");
printf(" + +\n");
printf(" + +\n");
printf(" + +\n");
printf(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("\n");
printf("\n");
printf("\n");
printf("please select:");
scanf("%c",&sel1);
}
void mainmenu();
void dayflightmanage();
void findflightzl();
void passflight();
void flightmanage()
{
system("cls");
printf("\n");
printf("\n");
printf(" **********************************************************************\n");
printf(" * *\n");
printf(" * Flight manage menu *\n");
printf(" * *\n");
printf(" **********************************************************************\n");
printf("\n");
printf("\n");
printf("\n");
printf(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" + +\n");
printf(" + Please choose: (input the serial number) +\n");
printf(" + +\n");
printf(" + +\n");
printf(" + 1. Get base information of Scheduled flight. +\n");
printf(" + +\n");
printf(" + 2. Day fly condition manage. +\n");
printf(" + +\n");
printf(" + 3. Recent fly condition manage. +\n");
printf(" + +\n");
printf(" + 4. insert new flight. +\n");
printf(" + +\n");
printf(" + 5. Delete flight. +\n");
printf(" + +\n");
printf(" + 6. Return main menu. +\n");
printf(" + +\n");
printf(" + +\n");
printf(" + +\n");
printf(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("\n");
printf("\n");
printf("\n");
printf("please select:");
scanf("%c",&sel2);
switch (sel2)
{
case '1' : findflightzl();break;
case '2' : dayflightmanage();break;
case '3' : recentmanage();break;
case '4' : newflight();break;
case '5' : passflight();break;
case '6' : mainmenu();break;
default : break;
}
}
void filesave()
{int j;
FILE *fp;
if((fp=fopen("flight","wb"))==NULL)
{printf("can't open file!\n");
return;
}
for(j=0;j<fm;j++)
if(fwrite(&s[j],sizeof(struct flight),1,fp)!=1)
printf("file write error!\n");
fclose(fp);
exit(1);
}
main()
{
mainmenu();
switch (sel1)
{
case '1' : findflight();break;
case '2' : passticket();break;
case '3' : flightmanage();break;
case '4' : findfly();break;
case '5' : filesave();break;
default : break;
}
}