# include < lt string.h > gt//The header file contains string function processing.
# include & ltconio.h & gt
# include < stdlib.h >//Header file containing dynamic storage and release functions.
Struct feijing Piao// defines an array of structures.
{
char air no[4]; //Define the flight number
char StartPos[6]; //Define the origin
char EndPos[6]; //Define the destination
char start time[ 14]; //yymmddwwhhmmss
char Mount[4]; //Define the number of air tickets.
Charge price [5]; //Define the fare
Unsigned character a; //Define unsigned variable a
};
struct FeiJiDingPiao s,ss[50];
Long file size (file * stream)
{
Long curl, length;
Curpos = ftell (stream);
fseek(stream,0L,SEEK _ END);
Length = ftell (stream);
fseek(stream,curpos,SEEK _ SET);
Return length;
}
Void disp()// Browse information
{ char I;
printf(" \ n-"); for(I = 0; I<4; i++) printf("%c ",s . air no[I]);
printf("-"); for(I = 0; I<6; i++) printf("%c ",s . start pos[I]);
printf("-"); for(I = 0; I<6; i++) printf("%c ",s . end pos[I]);
printf("-"); for(I = 0; I< 14; i++) printf("%c ",s . start time[I]);
printf("-"); for(I = 0; I<4; i++) printf("%c ",s . Mount[I]);
printf("-"); for(I = 0; I<5; i++) printf("%c ",s . Price[I]);
//printf(" \ n ");
}
void Pstrcpy( char i)//
{ char j;
for(j = 0; j & lt4; j++) s.AirNo[j]=ss[i]。 AirNo[j];
for(j = 0; j & lt6; j++) s.StartPos[j]=ss[i]。 start pos[j];
for(j = 0; j & lt6; j++) s.EndPos[j]=ss[i]。 start pos[j];
for(j = 0; j & lt 14; j++) s.StartTime[j]=ss[i]。 start pos[j];
for(j = 0; j & lt4; j++) s.Mount[j]=ss[i]。 start pos[j];
for(j = 0; j & lt5; j++) s.Price[j]=ss[i]。 start pos[j];
s . a = 0;
}
Int write_ssToFile (char count)// Add a record.
{
File * stream;
char I;
If ((stream = fopen("record.txt ","w+")= = NULL)/* Open the file test. $$$ */
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
for(I = 0; I < count; i++)
fwrite(& amp; ss[i],40, 1,stream); /* Write structure to file */
Fclose (flow); /* Close the file */
Printf ("\ nWrite record succeeded!" );
getch();
Returns 0;
}
Char Func3 1 (character n)
{ char I;
Printf ("\ nSuspend record! \ n ");
printf(" \ Nair no[4]"); for(I = 0; I<4; i++) ss[n]。 AirNo[I]= getche();
printf(" \ nstart pos[6]"); for(I = 0; I<6; i++) ss[n]。 StartPos[I]= getche();
printf(" \ nend pos[6]"); for(I = 0; I<6; i++) ss[n]。 end pos[I]= getche();
printf(" \ n start time[ 14]"); for(I = 0; I< 14; i++)ss[n]。 start time[I]= getche();
printf(" \ n mount[4]"); for(I = 0; I<4; i++) ss[n]。 mount[I]= getche();
printf(" \ n price[5]"); for(I = 0; I<5; i++) ss[n]。 price[I]= getche();
ss[n]。 a = 0;
Do {printf ("\ nConfirm Y/N?" );
I = getche();
}while ((me! = ' Y ')& amp; (me! = ' y ')& amp; (me! = ' N ')& amp; (me! = ' n '));
If((i=='Y')|(i=='y')) returns1;
Otherwise, return 0;
}
Intinsert _ i (charno _ to _ delete)//Insert information.
{
File * stream;
//struct my struct s;
char i,j,k = 0;
Long curl, length;
if ((stream = fopen("Record.txt "," r "))
== NULL)
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
Length=filesize (stream);
Length/= 41;
Printf(" \n nThere are %d records \ n ",length);
If (length & gt= no _ delete)
{ for(j=0,I = 0; J< length; j++) {
curpos = 4 1 * j; //*0 * 1 *2
if(j==no_to_delete){
if(func 3 1(I)= = 1){ k = 1; pstrcpy(I); disp(); i++; }
}
fseek(stream,curpos,SEEK _ SET);
Fred (& ampss[i], 40, 1, stream);
//i++;
pstrcpy(I); disp(); i++;
}
if(k = = 1)write _ ssto file(Length+ 1);
}
Fclose (flow);
Returns 0;
}
Intdelete _ i (charno _ to _ delete)//Delete the record.
{
File * stream;
//struct my struct s;
char i,j;
Long curl, length;
if ((stream = fopen("Record.txt "," r "))
== NULL)
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
Length=filesize (stream);
Length/= 41;
Printf(" \n nThere are %d records \ n ",length);
If (length & gt= no _ delete)
{ for(j=0,I = 0; J< length; j++) {
curpos = 4 1 * j; //*0 * 1 *2
If (j! = No _ Delete)
{fseek(stream,curpos,SEEK _ SET);
Fred (& ampss[i], 40, 1, stream);
//i++;
pstrcpy(I); disp(); i++;
}
}
Write_ssToFile (length-1);
}
Fclose (flow);
Returns 0;
}
Int disp_all(void)// Browse all information.
{
File * stream;
//struct my struct s;
char j;
Long curl, length;
if ((stream = fopen("Record.txt "," r "))
== NULL)
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
Length=filesize (stream);
Length/= 41;
Printf(" \n nThere are %d records \ n ",length);
for(j = 0; J< length; j++) {
curpos = 4 1 * j; //*0 * 1 *2
fseek(stream,curpos,SEEK _ SET);
Fred (& amps, 40, 1, stream);
disp();
}
Fclose (flow);
Returns 0;
}
Int Read_all(void)// Read all information.
{
File * stream;
//struct my struct s;
char j;
Long curl, length;
if ((stream = fopen("Record.txt "," r "))
== NULL)
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
Length=filesize (stream);
Length/= 41;
Printf(" \n nThere are %d records \ n ",length);
for(j = 0; J< length; j++) {
curpos = 4 1 * j; //*0 * 1 *2
fseek(stream,curpos,SEEK _ SET);
Fred (& ampss[j], 4 1, 1, stream);
//disp();
}
Fclose (flow);
Return length;
}
Int write_all (unsigned char n)// Write information.
{
File * stream;
char I;
if ((stream = fopen("record2.txt "," w")) == NULL)
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
for(I = 0; I & ltn;; i++)
{//fseek(stream,curposT,SEEK _ SET);
ss[i]。 a = 0;
fwrite(& amp; ss[i],40, 1,stream); /* Write structure to file */
}
Fclose (flow); /* Close the file */
Printf ("\ nWrite all records successfully!" );
getch();
Returns 0;
}
Long display _i (long number)
{ //No=0/ 1/2/3 ...
File * stream;
//struct my struct s;
//char I;
Long curl, length;
If ((stream = fopen ("record。 Txt ","r ")// Test the open file.
== NULL)
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
Length=filesize (stream);
Length/= 41;
If (length & gt= no) {
Printf ("\ nNo .. %d is in the record ",no);
Curpos = 4 1 * No; //*0 * 1 *2
fseek(stream,curpos,SEEK _ SET); //Find the file
Fred (& amps, 40, 1, stream); //Read in file
disp(); }
Elseprintf ("\ nno. %d is not in the record ",no);
Fclose (flow); //Close the file
Return to curpos
}
Intwrite _ rewrite (longcurpost)//Rewrite information.
{
File * stream;
//char I;
If ((stream = fopen ("record。 Txt ","r+")= = null)/* Test the open file */
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
fseek(stream,curposT,SEEK _ SET);
fwrite(& amp; s,40, 1,stream); /* Write * * object to file */
Fclose (flow); /* Close the file */
Printf ("\ nAppend record succeeded!" );
getch();
Returns 0;
}
int write_app(void)
{
File * stream;
//char I;
If ((stream = fopen ("record。 Txt ","a+")= = null)/* Test the open file */
{
Fprintf(stderr, "cannot open the output file. \ n ");
Returns1;
}
fseek(stream,0L,SEEK _ END);
fwrite(& amp; s,40, 1,stream); /* Write * * object to file */
Fclose (flow); /* Close the file */
Printf ("\ nAppend record succeeded!" );
getch();
Returns 0;
}
char Func 1 1(void)
{ char I;
Printf ("\ nSuspend record! \ n ");
printf(" \ Nair no[4]"); for(I = 0; I<4; i++)s . air no[I]= getche();
printf(" \ nstart pos[6]"); for(I = 0; I<6; i++)s . start pos[I]= getche();
printf(" \ nend pos[6]"); for(I = 0; I<6; i++)s . end pos[I]= getche();
printf(" \ n start time[ 14]"); for(I = 0; I< 14; i++)s . start time[I]= getche();
printf(" \ n mount[4]"); for(I = 0; I<4; i++)s . Mount[I]= getche();
printf(" \ n price[5]"); for(I = 0; I<5; i++)s . Price[I]= getche();
s . a = 0;
Do {printf ("\ nConfirm Y/N?" );
I = getche();
}while ((me! = ' Y ')& amp; (me! = ' y ')& amp; (me! = ' N ')& amp; (me! = ' n '));
If((i=='Y')|(i=='y')) returns1;
Otherwise, return 0;
}
void Func 1(void)
{ char I;
I = func 1 1();
if(I = = 1)write _ app();
}
Invalid function 2 (invalid)
{ char m,I;
Long curly column;
Printf ("\ nModify the record! \ n ");
Printf ("\ nDisplay input number \ n");
m = getche();
If ((m> =' 0') | (m <; = 9))curposT = disp _ I(m-' 0 ');
getch();
Printf ("\ nffunc1started! \ n ");
printf(" \ Nair no[4]"); for(I = 0; I<4; i++)s . air no[I]= getche();
printf(" \ nstart pos[6]"); for(I = 0; I<6; i++)s . start pos[I]= getche();
printf(" \ nend pos[6]"); for(I = 0; I<6; i++)s . end pos[I]= getche();
printf(" \ n start time[ 14]"); for(I = 0; I< 14; i++)s . start time[I]= getche();
printf(" \ n mount[4]"); for(I = 0; I<4; i++)s . Mount[I]= getche();
printf(" \ n price[5]"); for(I = 0; I<5; i++)s . Price[I]= getche();
s . a = 0;
Do {printf ("\ nConfirm Y/N?" );
I = getche();
}while ((me! = ' Y ')& amp; (me! = ' y ')& amp; (me! = ' N ')& amp; (me! = ' n '));
if((i=='Y')|(i=='y '))
write _ rewrite(curposT);
}
Invalid function 3 (invalid)
{ char m;
Printf ("\ nInsert record! \ n ");
m = getche();
If ((m> =' 0')&; (m & lt='9'))
insert _ I(m-' 0 ');
//getche();
}
Invalid function 4 (invalid)
{ char m;
Printf ("\ nDelete record! \ n ");
m = getche();
If ((m> =' 0')&; (m & lt= ' 9 '))delet _ I(m-' 0 ');
getche();
}
Void disp_title (invalid)
{
Printf ("\ nFlight number \ tDeparture station \ tTerminal station \ tFixed fare for departure time members");
}
Void disp_OneRecord (character number)
{ char I;
printf(" \ n "); for(I = 0; I<4; i++) printf("%c ",ss[num].air no[I]);
printf("/"); for(I = 0; I<6; i++) printf("%c ",ss[num].StartPos[I]);
printf("/"); for(I = 0; I<6; i++) printf("%c ",ss[num].EndPos[I]);
printf("/"); for(I = 0; I< 14; i++) printf("%c ",ss[num].start time[I]);
printf("/"); for(I = 0; I<4; i++) printf("%c ",ss[num].mount[I]);
printf("/"); for(I = 0; I<5; i++)printf("%c ",ss[num].price[I]);
//printf(" \ n ");
}
Void search_by_endpos() // Complete function 2/5.
{
char Tplace[24],I,n;
Int count;
count = Read _ all(); //Read all records to structure ss[0...49]
Printf ("\ nPlease enter the flight arrival location:");
for(I = 0; I<6; i++)
t place[I]= getche(); //scanf("%s ",Tdate);
disp _ title(); //Print information title
/* for(I = 0; I < count; i++)
if(strcmp(ss[i].StartTime,Tdate)= = 0)disp _ one record(I); */
for(I = 0; I < count; i++)
if((ss[i].EndPos[0]= = t place[0])& amp; & amp
(ss[i]。 EndPos[ 1]= = t place[ 1])& amp; & amp
(ss[i]。 EndPos[2]= = t place[2])& amp; & amp
(ss[i]。 EndPos[3]= = t place[3])& amp; & amp
(ss[i]。 EndPos[4]= = t place[4])& amp; & amp
(ss[i]。 EndPos[5]== Tplace[5])
disp _ one record(I);
Printf(" \ N Exit (Y/N)? " ); do { n = getch(); }while((n! = ' Y ')& amp; & amp(n! = ' y '));
}
Voidsearch _ by _ date _ and _ endpos ()//Complete function 3/5.
{
char Tdate[ 14],Tplace[6],I,n;
Int count;
count = Read _ all(); //Read all records to structure ss[0...49]
Printf ("\ nPlease enter the query date:");
scanf("%s ",Tdate);
Printf ("\ nPlease enter the arrival place:");
for(I = 0; I<6; i++)t place[I]= getche();
disp _ title(); //Print information title
for(I = 0; I < count; i++)
if((ss[i].start time[0]= = Tdate[0])& amp; & amp(ss[i]。 EndPos[0]= = t place[0])& amp; & amp
(ss[i]。 start time[ 1]= = Tdate[ 1])& amp; & amp(ss[i]。 EndPos[ 1]= = t place[ 1])& amp; & amp
(ss[i]。 start time[2]= = Tdate[2])& amp; & amp(ss[i]。 EndPos[2]= = t place[2])& amp; & amp
(ss[i]。 start time[3]= = Tdate[3])& amp; & amp(ss[i]。 EndPos[3]= = t place[3])& amp; & amp
(ss[i]。 start time[4]= = Tdate[4])& amp; & amp(ss[i]。 EndPos[4]= = t place[4])& amp; & amp
(ss[i]。 start time[5]= = Tdate[5])& amp; & amp(ss[i]。 EndPos[5]== Tplace[5])
disp _ one record(I);
Printf(" \ N Exit (Y/N)? " ); do { n = getch(); }while((n! = ' Y ')& amp; & amp(n! = ' y '));
}
Void search_by_Mount() // Complete function 4/5.
{
char Max[6],I,n;
Int count;
count = Read _ all(); //Read all records to structure ss[0...49]
Printf ("\ nPlease enter the flight number");
for(I = 0; I<6; i++)Max[I]= getche(); //scanf("%s ",Tdate);
disp _ title(); //Print information title
for(I = 0; I < count; i++)
if((ss[i].AirNo[0]= = Max[0])& amp; & amp
(ss[i]。 AirNo[ 1]= = Max[ 1])& amp; & amp
(ss[i]。 air no[2]= = Max[2])& amp; & amp
(ss[i]。 air no[3]= = Max[3])& amp; & amp
(ss[i]。 air no[4]= = Max[4])& amp; & amp
(ss[i]。 AirNo[5]== Max[5])
disp _ one record(I); //Print information
Printf(" \ N Exit (Y/N)? " ); do { n = getch(); }while((n! = ' Y ')& amp; & amp(n! = ' y '));
}
Long chg (character I)
{dragon n;
n=(ss[i]。 start time[0]-' 0 ')* 100000+
(ss[i]。 start time[ 1]-' 0 ')* 10000+
(ss[i]。 StartTime[2]-'0')* 1000+
(ss[i]。 StartTime[3]-'0')* 100+
(ss[i]。 StartTime[4]-'0')* 10+
(ss[i]。 start time[5]-' 0 ');
Returns n;
}
Void order_by_date() // Complete function 5/5
{
Length a[ 100], b [100];
Int count;
int i,j;
Long-term temperature;
System ("CLS"); //Clear the screen
count = Read _ all(); //Read all records to structure ss[0...49]
for(I = 0; I < count; i++)
a[I]= chg(I); //bubble sorting method
for(I = 0; I < count; i++)b[I]= a[I];
Printf ("\ nThe array before sorting is \ n");
for(I = 0; I < count; i++) printf("%ld ",a[I]);
for(I = 0; I < count; i++)
{
for(j = I; J< counting; j++)
{
if(a[I]& gt; a[j])
{
temp = a[I];
a[I]= a[j];
a[j]= temp;
}
}
}
printf(" \ n ");
for(I = 0; I < count; i++)
printf("%ld-",a[I]);
Printf ("\ nThe sorted array is \ n");
for(j = 0; J< counting; j++)
for(I = 0; I < count; i++)
if(a[j]= = b[I])disp _ one record(I);
}
void search _ by _ date()//template 1/5
{ char Tdate[ 14],I,n;
Int count;
count = Read _ all(); //Read all records to structure ss[0...49]
Printf ("\ nPlease enter the query date:");
scanf("%s ",Tdate);
disp _ title(); //Print information title
/* for(I = 0; I < count; i++)
if(strcmp(ss[i].StartTime,Tdate)= = 0)disp _ one record(I); */
for(I = 0; I < count; i++)
if((ss[i].start time[0]= = Tdate[0])& amp; & amp
(ss[i]。 start time[ 1]= = Tdate[ 1])& amp; & amp
(ss[i]。 start time[2]= = Tdate[2])& amp; & amp
(ss[i]。 start time[3]= = Tdate[3])& amp; & amp
(ss[i]。 start time[4]= = Tdate[4])& amp; & amp
(ss[i]。 StartTime[5]== Tdate[5])
disp _ one record(I);
Printf(" \ N Exit (Y/N)? " ); do { n = getch(); }while((n! = ' Y ')& amp; & amp(n! = ' y '));
}
Invalid function 5 (invalid)
{ char n;
Printf ("\ nPlease select");
Printf("\n 1) counts flight numbers by time, that is, what flights are there on a certain day. " );
Printf("\n 2) counts the flight numbers of a certain destination, that is, which flights can reach a certain place. " );
Printf("\n 3) counts the flight number of a certain day to a certain place. " );
Printf("\n 4) calculates the maximum number of passengers per flight of this airline. );
Printf("\n 5) is sorted by flight time. );
n = getche();
Switch (n)
Case "1":search _ by _ date (); Break;
Case "2": search _ by _ endpos (); Break;
Case "3": search _ by _ date _ and _ endpos (); Break;
Case "4": search _ by _ mount (); Break;
Case "5": order _ by _ date (); Break;
Default: break
}
Printf ("\ nPress any key to exit"); getche();
}
Invalid function 6 (invalid)
{
Printf ("\ nCalculate! \ n ");
getche();
}
void main()
{ char n,m;
Int count;
for(; ; ){
//clrscr();
System ("CLS");
Printf(" \ n \ t \ t \ t tDesign of aircraft reservation system ");
Printf(" \ n \ t \ t \ t- main menu-");
Printf("\n\t\t\t 1。 Enter input ");
Printf ("\ n \ t \ t 2。 Modify ");
Printf("\n\t\t\t 3。 Insert ");
Printf("\n\t\t\t 4。 Delete delete ");
Printf("\n\t\t\t 5。 Query inquire ");
Printf("\n\t\t\t 6。 Statistical calculation ");
printf("\n\t\t\t 7。 display _ I Record”);
printf("\n\t\t\t 8。 Display _ All Records ");
printf("\n\t\t\t 9。 Reserved ");
printf("\n\t\t\t 0。 Exit ");
n = getch();
Switch (n)
{
case“ 1”:func 1(); Break; //input
Case "2": func 2 (); Break; //modify
Case "3": func 3 (); Break; //Insert
Case "4": func 4 (); Break; //Delete succeeded.
Case "5": func 5 (); Break; //* Query
Case "6": func 6 (); Break; //* Calculation
Case '7': printf("\n ("\ nInput number for display \ n");
m = getche();
If ((m> =' 0')&; (m & lt= ' 9 '))disp _ I(m-' 0 ');
getch(); Break;
Case "8": disp _ all (); getch(); Break;
Case "9": getch (); Break;
Case "0": break; //exit to DOS
Case "a":
case“A”:count = Read _ all(); //Read all records to structure ss[0...49]
disp _ title(); //Print information title
for(m = 0; M< counting; m++)
disp _ one record(m); //Print one of all records;
Write_all (count); //Save n records in a file;
Break;
Case "b":
Case "b":
Default: break
}
if(n = = ' 0 ')break;
}
}
Is that enough?