Home > Back-end >  Pray god help to look at, is an airline reservation system, but it's wrong, seat
Pray god help to look at, is an airline reservation system, but it's wrong, seat

Time:10-10

//air passenger reservation system
#include
using namespace std;
#include
# define OK 1
# define the ERROR 0
//define aviation information structure
Typedef struct airline {
Char air_num [8].//flight no.
Char plane_num [8]. No.//the plane
Char start_place [20]. Took off//
Char end_place [20].//destination
Char air_time [20].//landing time
Int total;//the total number of seats
Int left;//remaining seats
Struct airline * next;//the next node
} airline;
//define the passenger information structure
Typedef struct customer {
Char name [8].//customer name
Char air_num [8].//flight no.
Int seat_num;//seat number
Struct the customer * next;//the next node
} the customer;
//initialize the air header node
The airline * start_air () {//initialization list
The airline * a=new airline;
If (a==NULL) cout<& lt;" Overflow "& lt; & lt; endl;//if the list is empty, the output overflow
return a;//otherwise, the output list
}
//initialize the customer header node
The customer * start_cus () {//initialization list
The customer * c=new customer;
If (c==NULL) cout<& lt;" Overflow "& lt; & lt; endl;//if the customer list is empty, the output element overflow
Return the c;//output list
}
//modify the remaining seat
Airline * modefy_airline (airline * l, char * air_num) {//parameters: the flight information, flight no.
The airline * p;//pointer p
P=l - & gt; Next;
for(; P!=NULL; P=p - & gt; Next) {//if p (flight information) is not null:
If (STRCMP (air_num, p - & gt; Air_num)==0) {//if air_num and p - & gt; Air_num equal, execution:
P - & gt; Left++;//the remaining seats plus 1
return l;//function that value is returned to the l
}
}
Cout<& lt;" Without this flight: "& lt; & lt; endl;//output: no this flight
Return 0;
}


//add aviation information table
Int insert_air (airline * * p, char * air_num, char * plane_num, char * start_place, char * end_place, char * air_time, int total, int left) {//add
The airline * q=new airline;
Strcpy (q - & gt; Air_num, air_num);
Strcpy (q - & gt; Plane_num plane_num);
Strcpy (q - & gt; Start_place start_place);
Strcpy (q - & gt; End_place end_place);
Strcpy (q - & gt; Air_time air_time); The airline information//will give p
Q - & gt; Total=total;
Q - & gt; Left=left;
Q - & gt; Next=NULL;
(* p) - & gt; Next=q;
(* p)=(* p) - & gt; Next;
return OK;
}
//add the customer information table
Int insert_cus (customer * * p, char * name, char * air_num, int seat_num) {
The customer * q=new customer;
Strcpy (q - & gt; The name, name);
Strcpy (q - & gt; Air_num, air_num);
Q - & gt; Seat_num=seat_num;
Q - & gt; Next=NULL;//add customer information to q
(* p) - & gt; Next=q;
(* p)=(* p) - & gt; Next;
return OK;
}
//book
Int the book (the airline * a, char * air_num, customer * c, char * name)
{
The airline * p=a - & gt; Next;
The customer * q=c - & gt; Next;
for(; Q - & gt; Next!=NULL; Q=q - & gt; Next) {}
for(; P - & gt; Next!=NULL; P=p - & gt; Next) {
If (p - & gt; Left> 0) {//if the remaining seat
Cout<& lt;" Your seat number is: "& lt; & lt; P - & gt; Total - p - & gt; Left + 1 & lt; & lt; endl;//seat number=total seats remaining seats + 1
Insert_cus (& amp; Q, name, air_num, p - & gt; Total - p - & gt; Left + 1);//call the insert, insert the passenger information
P - & gt; The left -;//the remaining seats minus one
return OK;
}
}
Cout<& lt;" Full "& lt; & lt; endl;//q - & gt; Next is empty, output: full
Return 0;
}
Any cancellation//
Int del_cus (customer * c, airline * l, char * name) {
The customer * p, * pr;
Char air_num [8].
Pr=c;
P=pr - & gt; Next;//the introduction of pr, pr pointer to change, to change the pointer p
while(p!=NULL) {
If (STRCMP (p - & gt; The name, the name)==0) {//if the input name in the passenger list
Strcpy (air_num, p - & gt; Air_num);
L=modefy_airline (l, air_num);//function modifies spare seat
Pr - & gt; Next=p - & gt; Next;//delete
P=pr - & gt; Next;
Cout<& lt;" The end!" & lt; & lt; endl;
return OK;
}
Pr=pr - & gt; Next;
P=pr - & gt; Next;
}
Cout<& lt;" Not the passengers!" & lt; & lt; endl;
Return the ERROR;
}
//query and output all flight information
Int search_air (airline * head, char * start_place, char * end_place, char * airnum) {
The airline * p=head - & gt; Next;
Cout<& lt;" Air_num plane_num start_place end_place air_time left total "& lt; & lt; endl;
for(; P!=NULL; P=p - & gt; Next) {//in turn down from the first line query
If (STRCMP (p - & gt; Air_num, airnum)==0) {
Cout<& lt; P - & gt; Air_num & lt; & lt;" "& lt; & lt; P - & gt; Plane_num & lt; & lt;" "& lt; & lt; P - & gt; Start_place & lt; & lt;" "& lt; & lt; P - & gt; End_place & lt; & lt;" "& lt; & lt; P - & gt; Air_time & lt; & lt;" "& lt; & lt; P - & gt; Left<& lt;" "& lt; & lt; P - & gt; Total<& lt; endl;
return OK; }
}//output
Cout<& lt;" Could not find "& lt; & lt; endl;
Return the ERROR;
}

//according to the customer's name query information
Int search_cus (customer * head, char * name) {
The customer * q=head - & gt; Next;
Cout<& lt;" The name air_num seat_num "& lt; & lt; endl;
for(; Q!=NULL; Q=q - & gt; Next) {
If (STRCMP (q - & gt; Name, name)==0) {//according to the customer's name to query the
Cout<& lt; Q - & gt; Name<& lt;" "& lt; & lt; Q - & gt; Air_num & lt; & lt;" "& lt; & lt; Q - & gt; Seat_num & lt; & lt;" "& lt; & lt; endl;
return OK;
}
}
Cout<& lt;" Not find!" & lt; & lt; endl;
Return the ERROR;
}
//create aviation information table
Int creat_air (airline * * l) {
The airline * p=* l;
int i=0;
Char * air_num [3]={" 007 af ", "008 af", "009 af"};//flight no.
Char * plane_num [3]={" plane1 ", "plane2", "plane3"}; No.//the plane
Char * start_place [4]={" guangdong ", "langfang", "zhejiang"}; Took off//
Char * end_place [3]={" Beijing ", "Shanghai", "tianjin"};//destination
Char * air_time [20]={" 8:00 to 10:00 ", "-" ruler ", "11-12:30"};//landing time
Int total [3]={100100100};//the total number of seats
52,54,76 int left [3]={};//remaining seats
for(i=0; i<3; I++)
Insert_air (& amp; P, air_num [I], plane_num [I], start_place [I], end_place [I], air_time [I], total [I], left [I]); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull