//Your main question: 1, the function name password () has the same name as the variable password in main. I changed it to inputpassword ()
//2. The following printf ("\ n ") and getchar () in the inputpassword () function are redundant.
//3. I don't know what cc[9] returned in your inputpassword is? I changed it to return strlen(cc). Returns the password length.
-
//# include & lt; stdafx.h & gt
# include & ltconio.h & gt
# include & ltstdio.h & gt
# include & ltstring.h & gt
# include & ltstdlib.h & gt
# Define OK 1
# Define true 1
# Define false 0
# Definition error 0
# Define Overflow -2
# define PR printf
Typedef int status;
Typedef structure route
{
char line _ num[8]; //flight number
char plane _ num[8]; //Aircraft number
char end _ place[20]; //purposeful
Int total// total number of seats
Int left// Remaining seats
Structure airline * next//Next node
} airlines;
Typedef structure customer
{
char name[9]; //Customer name
char line _ num[8]; //flight number
Int seat _ num// seat number
Structured customers * Next step; //Next node
} customers;
Airline *init_airline ()
{//Initialize the linked list
Airline * l;;
l =(airline *)malloc(sizeof(airline));
if(l==NULL)
{Exit (0);
}
l-& gt; next = NULL
Return l;
}
Customer * init_customer(){// Initializes the linked list.
Customer * l;;
L= (customer *)malloc(sizeof);
if(l==NULL){
Exit (0);
}
l-& gt; next = NULL
Return l;
}
Status insert _ airline (airline * * p, char * line _ num, char * plane _ num, char * end _ place, int total, int left){// Insert operation of route list.
Airline * q;;
q =(airline *)malloc(sizeof(airline));
strcpy(q-& gt; line_num,line _ num);
strcpy(q-& gt; plane_num,plane _ num);
strcpy(q-& gt; end_place,end _ place);
q->; Total = total;
q->; Left = left;
q->; next = NULL
(* p)-& gt; next = q;
(* p)=(* p)-& gt; Next;
// PR("insert %d, %d succeeded! \n ",e,bl);
Return ok;
}
Status insert _ customer (customer * * p, char * name, char * line _ num, int seat){// customer linked list insert operation.
Customer * q;;
Q= (customer *)malloc(sizeof);
/* {PR ("Memory allocation failed \ n");
Return overflow; }*/
strcpy(q-& gt; Name, name);
strcpy(q-& gt; line_num,line _ num);
q->; Seat _ num = seat;
q->; next = NULL
(* p)-& gt; next = q;
(* p)=(* p)-& gt; Next;
// PR ("Insert %d,% d succeeded! \n ",e,bl);
Return ok;
}
Airline * mode fy _ airline (airline * l, char * line _ num)// Modify the data in the airline linked list.
{airline * p;;
p = l-& gt; Next;
for(; p! = NULLp = p-& gt; Next)
{ if(strcmp(line_num,p-& gt; line _ num)= 0)
{ p->; Left++;
// PR("modefy %s\n ",p-& gt; line _ num);
Return l;
}
}
PR ("Without this flight, the refitting task can't be completed! \ n ");
Returns 0;
}
Status delete _ airline (airline * h, char * line _ num)// Delete the flight.
{airline *p, * public relations;
pr = h;
p = pr-& gt; Next;
And (p! = empty)
{ if(strcmp(line_num,p-& gt; line _ num)= 0)
{ pr-& gt; next = p-& gt; Next;
PR ("delete %s flight \n", p-> line _ num);
Return ok;
}
pr = pr-& gt; Next;
p = pr-& gt; Next;
}
PR ("There is no such flight, so it cannot be deleted! \ n ");
Error returned;
}
Status delete _ customer (customer * h, char * line _ num)// Delete the customer.
{customer *p, * public relations;
pr = h;
p = pr-& gt; Next;
And (p! = empty)
{ if(strcmp(line_num,p-& gt; line _ num)= 0)
{ pr-& gt; next = p-& gt; Next;
}
pr = pr-& gt; Next;
p = pr-& gt; Next;
}
// PR ("There is no such flight, so it cannot be deleted! \ n ");
Return ok;
}
Status delete _ cus (customer * h, airline * l, char * name)// The customer refunded the ticket.
{customer *p, * public relations;
char line _ num[8];
//QR = h;
pr = h;
p = pr-& gt; Next;
// PR ("Start deleting \ n");
And (p! = empty)
{ if(strcmp(name,p-& gt; name )==0)
{ strcpy(line_num,p-& gt; line _ num);
l=modefy_airline(l,line _ num);
pr-& gt; next = p-& gt; Next;
PR ("Customer %s successfully refunded! \n ",p-& gt; Name);
Return ok;
}
pr = pr-& gt; Next;
p = pr-& gt; Next;
}
PR ("Without this customer, you can't get a refund! \ n ");
Error returned;
}
Save _ airline(airline * l)// Save airline.dat
{ FILE * fp _ airline
char ch = ' #
The airline. Next;
char filename[]= " c:\ \ airline . dat ";
If((fp_airline=fopen (file name, "WB") = = null)
{printf ("Unable to open file for writing: %s\n", file name);
Error returned;
}
for(; p! = NULLp = p-& gt; Next)
{ // printf("%s,%s,%s,%d,%d\n ",p-& gt; line_num,p-& gt; plane_num,p-& gt; end_place,p-& gt; Total, p- > left);
fprintf(fp_airline," %s,%s,%s,%d,%d%c\n ",p-& gt; line_num,p-& gt; plane_num,p-& gt; end_place,p-& gt; Total, p- > left, ch);
}
fclose(FP _ airline);
Return ok;
}
Save _ customer(customer * l)// Save customer information customer.dat
{ FILE * fp _ customer
char ch = ' #
customer * p = l-& gt; Next;
char filename[]= " c:\ \ customer . dat ";
if((fp_customer=fopen(filename,“WB”))= = NULL)
{printf ("Unable to open file for writing: %s\n", file name);
Error returned;
}
for(; p! = NULLp = p-& gt; Next)
{ // PR("%s,%s,%d\n ",p-& gt; Name, p-> line_num,p-& gt; Seat number);
fprintf(fp_customer," %s,%s,%d%c ",p-& gt; Name, p-> line_num,p-& gt; seat_num,ch);
}
fclose(FP _ customer);
Return ok;
}
Int changStrInt(char *ch)// Converts a string into an integer.
{ int a= 1,b=0,c=0,I;
for(I = strlen(ch)- 1; I & gt=0; I-)
{ if(ch[I]& lt; 58 & amp& ampch[I]& gt; 47)
{ b = a *(ch[I]-48);
a = a * 10;
c = c+b;
}
other
{PR("%c ") is illegal. This string cannot be converted into an integer! \n ",ch[I]);
Returns 0;
}
//printf(" c is %d\n ",c);
}
Return to c;
}
Status insert _ air (airline * l, char * line _ num, char * plane _ num, char * end _ place, int total, int left){// Insert operation of route list.
Airline * q;;
q =(airline *)malloc(sizeof(airline));
strcpy(q-& gt; line_num,line _ num);
strcpy(q-& gt; plane_num,plane _ num);
strcpy(q-& gt; end_place,end _ place);
q->; Total = total;
q->; Left = left;
q->; next = l-& gt; Next;
l-& gt; next = q;
// PR ("Insert %d,% d succeeded! \n ",e,bl);
Return ok;
}
Status insert _ cus (customer * l, char * name, char * line _ num, int seat){// customer linked list insert operation.
Customer * q;;
Q= (customer *)malloc(sizeof);
strcpy(q-& gt; Name, name);
strcpy(q-& gt; line_num,line _ num);
q->; Seat _ num = seat;
q->; next = l-& gt; Next;
l-& gt; next = q;
Return ok;
}
Status Load _ Airline (Airline *l)
{ FILE * fp _ airline
int flag=0,I = 0;
char ch
char line _ num[8]; //flight number
char plane _ num[8]; //Aircraft number
char end _ place[20]; //purposeful
char total _ str[5];
char left _ str[5];
Int total// total number of seats
Int left// Remaining seats
//airline * p = l;
char filename[]= " c:\ \ airline . dat ";
if((fp_airline=fopen(filename," Rb))= = NULL)
{printf ("Cannot open the file to be loaded: %s\n", file name);
Error returned;
}
And (! airline
{ ch = fgetc(FP _ airline);
If (ch! ='#')
{ if(flag = = 0 & amp; & ampch! =',')
{ line _ num[I]= ch;
i++;
}
else if(flag = = 1 & amp; & ampch! =',')
{ plane _ num[I]= ch;
i++;
}
else if(flag = = 2 & amp; & ampch! =',')
{ end _ place[I]= ch;
i++;
}
else if(flag = = 3 & amp; & ampch! =',')
{ total _ str[I]= ch;
i++;
}
else if(flag = = 4 & amp; & ampch! =',')
{ left _ str[I]= ch;
i++;
}
else if (ch== ',')
{ flag++;
I = 0;
}
/* Otherwise
{ PR(" Error \ n ");
Error returned;
}*/
}
other
{ flag = 0;
I = 0;
total = changs trint(total _ str);
left = changs trint(left _ str);
PR("%8s%8s%8s%9d%9d\n ",line_num,plane_num,end_place,total,left);
insert_air(l,line_num,plane_num,end_place,total,left);
}
}
fclose(FP _ airline);
Return ok;
}
Status Load _ Customer (Customer *l)
{ FILE * fp _ customer
int flag=0,I = 0;
char ch
char name[9];
char line _ num[8]; //flight number
char seat _ num _ str[5];
Int seat _ num// seat
//customer * p = * l;
char filename[50]= " c:\ \ customer . dat ";
if((fp_customer=fopen(filename," Rb))= = NULL)
{printf ("Cannot open the file to be loaded: %s\n", file name);
Error returned;
}
And (! feof(fp_customer))
{ ch = fgetc(FP _ customer);
printf("%c\n ",ch);
If (ch! ='#')
{ if(flag = = 0 & amp; & ampch! =',')
{ name[I]= ch;
i++;
}
else if(flag = = 1 & amp; & ampch! =',')
{ line _ num[I]= ch;
i++;
}
else if(flag = = 2 & amp; & ampch! =',')
{ seat _ num _ str[I]= ch;
i++;
}
else if (ch== ',')
{ flag++;
I = 0;
}
other
{ PR(" Error \ n ");
Error returned;
}
}
other
{ flag = 0;
seat _ num = changs trint(seat _ num _ str);
PR("% 10s % 10s %d\n ",name,line_num,seat _ num);
insert_cus(l,name,line_num,seat _ num);
//p = p-& gt; Next;
}
}
fclose(FP _ customer);
Return ok;
}
Statuscreat _ airline (airline * * l)//Create an airline single linked list.
{airline * p = * l;;
int I = 0;
char * line _ num[3]= { " bjnc 0 1 "," bjsh02 "," shgz 03 " };
char * plane _ num[3]= { " plane 1 "," plane2 "," plane 3 " };
char *end_place[3]={"nc "," sh "," gz " };
int total[3]={ 100, 100, 100 };
int left[3]={5 1,50,78 };
for(I = 0; I<3; i++){
Insert _ airline (& ampp, line_num[i], plane_num[i], end_place[i], total[i], left [i]);
}
Return ok;
}
Statuscreat _ customer (customer * * l)//Create a single customer link list.
{customer * p = * l;;
int I = 0;
Char *name[3]={ "Ouyang j0", "yhl", "fs" };;
char * line _ num[3]= { " bjnc 0 1 "," bjsh02 "," shgz 03 " };
int seat_num[3]={ 1,5, 10 };
for(I = 0; I<3; i++){
Insert customer (& ampp, name[i], line_num[i], seat _ num [i]);
}
Return ok;
}
Status increase _ air (airline * l, char * line _ num, char * plane _ num, char * end _ place, int total)// Add a route.
{ airline * p = l-& gt; Next;
for(; p->; Au Suivant! = NULLp = p-& gt; Next step) {}
Insert _ airline (& ampp, line_num, plane_num, end_place, total, total);
PR ("Add flight %s successfully! \n ",line _ num);
Return ok;
}
Statusbook (airline * l, char * line _ num, customer * c, char * name)// reservation function.
{airline * p = l;;
Customer * q = c-& gt;; Next;
p = l-& gt; Next;
for(; q->; Au Suivant! = NULLq = q-& gt; Next step) {}
// PR("%s\n ",q-& gt; Name);
for(; p! = NULLp = p-& gt; Next)
{ if(strcmp(line_num,p-& gt; line _ num)= 0)
{ if(p-& gt; left & gt0)
{PR ("Congratulations! The reservation was successful! \ n ");
PR ("Your seat number is: %d\n", (p-> Total -p- > left+1);
Insert customer (& ampq, name, line_num, p->total -p- > left+1);
p->; Left-;
Return ok;
}
Else PR ("Sorry, the seats are full! \ n ");
Returns 0;
}
}
PR ("Sorry, there is no such flight number! \ n ");
Error returned;
}
Statusprint _ airline (airline * l)//Print airline information.
{ airline * p = l-& gt; Next;
for(; p! = NULLp = p-& gt; Next)
{ PR("%8s%8s%8s%9d%9d\n ",p-& gt; line_num,p-& gt; plane_num,p-& gt; end_place,p-& gt; Total, p- > left);
}
Return ok;
}
Statusprint _ customer (customer * l)//Print customer information.
{
customer * p = l-& gt; Next;
for(; p! = NULLp = p-& gt; Next)
{ PR("% 10s % 10s %d\n ",p-& gt; Name, p-> line_num,p-& gt; Seat number);
}
Return ok;
}
Status input password (charcc[9])// Hidden password is *-Landlord, please pay attention here!
{
char c;
int I;
for(I = 0; c = getch(); i++)
{
If(c== 13) is broken; /* 13 is the ascii code for carriage return, but' \n' cannot be used. I don't know what happened */
other
{
cc[I]= c;
printf(" * ");
}
}
cc[I]= ' \ 0 ';
//printf(" \ n ");
//printf("%s ",cc);
//getchar();
Returns strlen (cc);
}
void main()
{ char choice,choice2,name[9],line_num[8],password[9],plane_num[8],end _ place[9];
char pass[9]= " 1985 1 102 ",re_pass_ 1[9],re _ pass _ 2[9];
Int t= 1, t t= 1, total;
airline * air = init _ airline();
Customer * cus = init _ customer ();
PR ("Computer 054 1 Course Design (1) \ n");
PR ("air ticket reservation system \ n");
PR ("Member: Yan Kai \ n");
Create airlines. Air);
Create a customer. cus);
//save _ airline(air);
//save _ customer(cus);
while(t== 1)
{ PR(" *-* \ n ");
PR(" *- air ticket reservation system selection menu-* \ n ");
PR(" * Booking-0 * \ n ");
PR("* Refund-1* \ n ");
PR(" * query-2 * \ n ");
PR("* modify route-3 * \ n ");
PR(" * read file-4 * \ n ");
PR(" * Exit-5 * \ n ");
PR(" *-* \ n ");
PR ("please select");
choice = getch();
PR("%c\n ",choice);
if(choice=='0 ')
{PR ("Please enter the flight number you want to book:");
scanf( "%s ",line _ num);
PR ("Please enter your name:");
Scanf( "%s ",name);
book(air,line_num,cus,name);
Save_airline (aviation);
Save _ customer (cus);
}
else if(choice==' 1 ')
{pr ("\ nPlease enter your name:");
Scanf( "%s ",name);
delete_cus(cus,air,name);
Save_airline (aviation);
Save _ customer (cus);
}
else if(choice=='2 ')
{pr ("\ nFlight number and total number of votes remaining at the destination of flight number \ n");
Print_airline (aviation);
PR ("name, flight number, seat number \ n");
Print _ customer (CUS);
}
else if(choice=='3 ')
{ TT = 1;
PR ("Please enter the password:");
//scanf("%s ",password);
Enter the password (password); -Landlord, pay attention here! I changed it!
If(strcmp (password, password) ==0)
{ while (tt== 1){
PR(" \ n *-* \ n ");
PR("*-routing information modification: * \ n ");
PR("* Add flight number-'0' * \ n ");
PR("* delete flight number-'1'* \ n ");
PR("* change password-'2' * \ n ");
PR("* Query airline information-'3' * \ n ");
PR("* Exit route modification-'4' * \ n ");
PR(" *-* \ n ");
PR ("please select");
choice 2 = getch();
PR("%c\n ",option 2);
If (choose 2=='0')
{PR ("Please enter the flight number you want to add:");
scanf("%s ",line _ num);
PR ("Please enter the plane number:");
scanf("%s ",plane _ num);
PR ("Please enter destination:");
scanf("%s ",end _ place);
PR ("Please enter the total number of seats:");
Scanf("%d ",& total);
Increase_air(air, line_num, plane_num, end_place, total);
Save_airline (aviation);
Save _ customer (cus);
}
else if (choice2==' 1 ')
{PR ("Please enter the flight number to be deleted:");
scanf("%s ",line _ num);
delete_airline(air,line _ num);
Delete _ customer (cus, line _ num);
Save_airline (aviation);
Save _ customer (cus);
}
Else if (choose 2=='2')
{PR ("Note: the password cannot exceed 8 digits! \ n ");
PR ("Please enter a new password:");
scanf("%s ",re _ pass _ 1);
PR ("Please re-enter:");
scanf("%s ",re _ pass _ 2);
if(strcmp(re_pass_ 1,re_pass_2)==0)
{ strcpy(pass,re _ pass _ 1);
PR ("Password changed successfully! Please remember. \ n ");
}
Else {PR ("The passwords you entered twice are inconsistent! \ n ");
}
}
Else if (option 2=='3')
{pr ("\ nFlight number and total number of votes remaining at the destination of flight number \ n");
Print_airline (aviation);
}
Else if (choose 2=='4')
{ TT = 0;
}
Otherwise {
PR ("You typed it wrong \ n");
TT = 0;
}
}//End time
}//End if
Otherwise {
PR ("Sorry! The password you entered is incorrect! \ n ");
}
}//The modification is finished, otherwise,
else if(choice=='4 ')
{load_airline (aviation);
load _ customer(cus);
}
else if(choice=='5 ')
{PR ("Goodbye!" );
t = 0;
}
other
{PR ("Your input is wrong \ n");
}
}
getch();
}