データ構造——航空機予約システム
9160 ワード
/**************************************************
* (c)2014,Li Jiajun
*
* :ticket.c
* :
* :
* :
* :V1.0
* :
* :2017 12 22
***************************************************
ljj.h
#ifndef LJJ_H_INCLUDED
#define LJJ_H_INCLUDED
#define MaxSize 200
typedef struct plane //
{
char plane_number[10];
char plane_start[20];
char plane_finish[20];
int seat;
int left_seat;
struct plane *next;
}plane;
typedef struct individual //
{
char in_name[30];
char in_id[10];
char plane_number[20];//
int in_seat;//
struct individual *next;
}individual;
typedef struct plane_head //
{
int count;
plane *next;
}plane_head;
typedef struct in_head //
{
int count;
individual *next;
}in_head;
//
plane_head *import(int n,plane_head *phead_line);//
plane *query(plane_head *phead);//
void display_plane(plane *node);//
void all_display_plane(plane_head *headline);//
int change_plane(plane_head *headline); //
//
void display_in(individual *node);//
void all_display_in(in_head *headline);//
int buyticket(plane_head *pheadline,in_head *headline);//
int returnticket(plane_head *headline,in_head *client);//
//
int savemessage(plane_head *pheadline,in_head *headline);// txt
void main_menu();//
#endif // LJJ_H_INCLUDED
ljj.cpp
#include
#include
#include
#include
#include
#include
#include
#include "ljj.h"
using namespace std;
/**************************************************
* :
* : plane_number
plane_start
plane_finish
* :
* : pheadline
* : (;)
***************************************************
plane_head *import(int n,plane_head *pheadline)//
{
plane *temp= new plane;
temp->next=NULL;
pheadline->next=temp;
pheadline->count=n;
for(int i=0;i>temp->plane_number;
cout<>temp->plane_start;
cout<>temp->plane_finish;
temp->left_seat=temp->seat=200;
cout<next=new plane;
while(i>1)
{
if(temp->plane_number==temp->next->plane_number)
{
cout<next->next=NULL;
temp=temp->next;
}
}
return pheadline;
}
/**************************************************
* :
* : s
plane_number
plane_start
plane_finish
* :
* : NULL find
* : find
***************************************************
plane *query(plane_head *phead)//
{
int s;
plane *find=NULL;
plane *temp;
cout<>s;
cout<>plane_number;
temp=phead->next;
while(temp)
{
if(strcmp(temp->plane_number,plane_number)==0)
{
find=temp;
return temp;
break;
}
else
{
temp=temp->next;
}
}
if(!temp)
{
cout<>plane_start;
cout<>plane_finish;
temp=phead->next;
while(temp)
{
if(strcmp(temp->plane_start,plane_start)==0&&strcmp(temp->plane_finish,plane_finish)==0)
{
find =temp;
break;
}
temp=temp->next;
}
if(!temp)
{
cout<plane_number<plane_start<plane_finish<seat<left_seat<next;
if(!node)
{
cout<count<next;
}
}
void display_in(individual *node)// 。
{
if(node==NULL)
{
cout<in_name<in_id<in_seat<plane_number<next;
if(!node)
{
cout<next;
}
}
/**************************************************
* :
* : plane_number[10]
in_id
in_name
* :
* : 0 1
* :
***************************************************
int buyticket(plane_head *headline,in_head *headclient)//
{
//headline->count=0;
cout<>plane_number;
plane *temp;
temp=headline->next;
while(temp)
{
if(strcmp(temp->plane_number,plane_number)==0)
{
break;
}
temp=temp->next;
}
if(!temp)
{
cout<left_seat==0)
{
cout<>n;
}
individual *custom=new individual;
cout<>custom->in_id;
cout<>custom->in_name;
cout<in_seat=temp->seat - temp->left_seat + 1;
custom->next=NULL;
strcpy(custom->plane_number,plane_number);
temp->left_seat--;
headclient->count++;
custom->next = headclient->next;
headclient->next = custom;
cout<>name;
cout<>in_id;
cout<>number;
plane *airlinetemp= headline->next;
individual *clienttemp= headclient->next;
if(NULL==airlinetemp)
{
cout<in_id,in_id)==0)// 。。。
{
strcpy(plane_number,clienttemp->plane_number);
headclient->next=clienttemp->next;
delete clienttemp;
while(airlinetemp)// 。
{
if(strcmp(plane_number,airlinetemp->plane_number)== 0 )
{
airlinetemp->left_seat++;
break;
}
airlinetemp = airlinetemp->next;
}
cout<next)// 。。。
{
if(strcmp(clienttemp->next->in_id,in_id)==0)
{
strcpy(plane_number,clienttemp->next->plane_number);
delnext = clienttemp->next->next;
delete clienttemp->next;
clienttemp->next=delnext;
while(airlinetemp)// 。
{
if(strcpy(plane_number,airlinetemp->plane_number)== 0 )
{
airlinetemp->left_seat++;
break;
}
airlinetemp = airlinetemp->next;
}
cout<next;
}
cout<count<next;
while(linetemp)
{
outline<plane_number<plane_start<plane_finish<seat<left_seat<next;
}
outline.close();
cout<count<next;
while(clienttemp)
{
outclient<in_name<in_id<plane_number<in_seat<next;
}
outclient.close();
cout<plane_number
tem->plane_start
tem->plane_finish
plane_number
a
s[20]
d[20]
* :
* : NULL find
* : find
, next
***************************************************
int change_plane(plane_head *headline)//
{
cout<next;
plane * t = headline->next;
while(t)
{
display_plane(t);
t=t->next;
}
cout<>select;
cout<3 || select<1)
{
cout<next = (plane*)malloc(sizeof(plane));
plane *tem= new plane;
cout<>tem->plane_number;
cout<>tem->plane_start;
cout<>tem->plane_finish;
cout<>tem->seat;
tem->left_seat = tem->seat;
tem->next=NULL;
headline->count++;
cout<next;
else
{
tem->next=temp->next;
temp->next=tem;
}
break;
}
case 2:
{
cout<>plane_number;
plane *delline=new plane;
delline = headline->next;
while(delline)
{
if(strcmp(delline->plane_number, plane_number)==0)
{
plane *plink;
plink = delline->next;
delete delline;
headline->next=plink;
headline->count--;
cout<next;
}
break;
}
case 3:
{
cout<>plane_number3;
temp = headline->next;
while(temp)
{
if(strcmp(temp->plane_number, plane_number3)==0)
{
cout<>p;
switch(p)
{
case(1):
{
cout<>a;
temp->left_seat=a;
cout<>s;
strcpy(temp->plane_start,s);
cout<plane_finish,d);
cout<next;
break;
}
}
return 1;
}
}
void main_menu()
{
cout<
main.cpp
#include
#include
#include
#include
#include
#include
#include "ljj.h"
using namespace std;
int main()
{
plane_head *headline = new plane_head;
headline->count=0;
headline->next=NULL;
in_head *headclient = new in_head;
headclient->count=0;
headclient->next=NULL;
while(1)
{
main_menu();
int n;
cout<>n;
cout<>num;
cout<