C語言實現(xiàn)航班訂票系統(tǒng)
本文實例為大家分享了C語言實現(xiàn)航班訂票系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
描述:
點定義兩個鏈表,一個存儲航班信息,一個存儲客戶信息;
進行一系列簡單的增刪查找;
代碼如下
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std;
const int MAXN=250;
typedef struct
{
string p_id;
int sum;
int r;
int c;
int selected;
int select;
string start;
string startp;
string arrive;
string arrivep;
int acx[MAXN][MAXN];
} node;
typedef struct Pnode
{
node data;
struct Pnode *next;
} Pnode,*Plist;
typedef struct
{
int r;
int c;
string name;
string kp_id;
string k_id;
} node1;
typedef struct Knode
{
node1 data;
struct Knode *next;
} Knode,*Klist;
void init(Plist &l)
{
l=new Pnode;
l->next=NULL;
}
void init(Klist &L)
{
L=new Knode;
L->next=NULL;
}
void creatp(Plist &l,int e)
{
cout<<endl<<endl;
Plist r=new Pnode;
r=l;
for(int i=0; i<e; i++)
{
Plist ll=new Pnode;
cout<<endl;
cout<<"請依次輸入航班班次,起飛時間,起飛地點,到達時間,到達地點,座位行數(shù),列數(shù),總座位數(shù),已被購買的數(shù)目,未被購買的數(shù)目"<<endl;
cout<<'\t';
cin>>ll->data.p_id;
cout<<" ";
cin>>ll->data.start;
cout<<" ";
cin>>ll->data.startp;
cout<<" ";
cin>>ll->data.arrive;
cout<<" ";
cin>>ll->data.arrivep;
cout<<" ";
cin>>ll->data.r;
cout<<" ";
cin>>ll->data.c;
cout<<" ";
cin>>ll->data.sum;
cout<<" ";
cin>>ll->data.selected;
cout<<" ";
cin>>ll->data.select;
for(int j=1; j<=ll->data.r; j++)
for(int v=1; v<=l->data.c; v++)
ll->data.acx[j][v]=0;
ll->next=NULL;
r->next=ll;
r=ll;
}
}
void creatk(Klist &L,node1 e)
{
Klist LL=new Knode;
LL->data=e;
LL->next=NULL;
Klist r;
r=L;
while(r->next!=NULL)
{
r=r->next;
}
r->next=LL;
//cout<<L->next->data.r<<endl;
}
void show(Plist &l)
{
Plist p=new Pnode;
p=l->next;
while(p!=NULL)
{
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<p->data.p_id<<" "<<p->data.start<<" "<<p->data.startp<<" "<<p->data.arrive<<" "<<p->data.arrivep<<" "<<p->data.sum<<" "<<p->data.selected<<" "<<p->data.select<<endl;
for(int i=1; i<=p->data.r; i++)
{
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t';
for(int j=1; j<=p->data.c; j++)
cout<<p->data.acx[i][j];
cout<<endl;
}
p=p->next;
}
return ;
}
void alter(Plist &l,node1 e,int flag)
{
Pnode *p,*pre;
p=l->next;
while(p->data.p_id!=e.kp_id)
{
pre=p;
p=p->next;
}
if(flag)
{
p->data.select-=1;
p->data.selected+=1;
p->data.acx[e.r][e.c]=1;
}
else
{
p->data.select+=1;
p->data.selected-=1;
p->data.acx[e.r][e.c]=0;
}
return ;
}
int delet(Klist &L,node1 e)
{
Klist p,pre;
p=L;
while(p->next!=NULL)
{
if(p->data.name==e.name&&p->data.k_id==e.k_id&&p->data.kp_id==e.kp_id)
break;
pre=p;
p=p->next;
}
if(p==NULL)
return 0;
else
{
//cout<<"hjdhfjks"<<endl;
pre->next=p->next;
free(p);
return 1;
}
}
int searchh(Klist &L,node1 e)
{
Knode *p;
p=L->next;
while(p!=NULL)
{
if(p->data.name==e.name&&p->data.k_id==e.k_id&&p->data.kp_id==e.kp_id)
{
cout<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"您的位置是"<<p->data.r<<"行"<<p->data.c<<"列"<<endl;
return 1;
}
p=p->next;
}
return 0;
}
void showone(Plist &l,node1 e)
{
Pnode *p;
p=l->next;
while(p!=NULL)
{
if(p->data.p_id==e.kp_id)
{
cout<<endl;
cout<<'\t'<<"您的航班信息如下(依次為航班班次,起飛時間,起飛地點,到達時間,到達地點,座位總數(shù),已購座位數(shù),未購座位數(shù))"<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<p->data.p_id<<" "<<p->data.start<<" "<<p->data.startp<<" "<<p->data.arrive<<" "<<p->data.arrivep<<" "<<p->data.sum<<" "<<p->data.selected<<" "<<p->data.select<<endl;
return ;
}
}
return ;
}
int judge(Plist &l,node1 e)
{
Pnode *p;
p=l->next;
while(p!=NULL)
{
//cout<<p->data.acx[e.r][e.c]<<endl;
if(p->data.p_id==e.kp_id)
{
if(p->data.acx[e.r][e.c])
return 0;
}
p=p->next;
}
return 1;
}
int main()
{
Plist l;
Klist L;
init(l);
init(L);
int choose,n;
node p;
node1 k;
cout<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"初始化存儲航班信息"<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"輸入航班總數(shù):";
cin>>n;
system("cls");
creatp(l,n);
system("cls");
while(1)
{
cout<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"1.客戶訂票"<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"2.客戶退票"<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"3.客戶查詢航班信息"<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"0.退出系統(tǒng)"<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"選擇功能:";
cin>>choose;
system("cls");
if(!choose)
{
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<endl;
break;
}
else if(choose==1)//訂票
{
cout<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"航班信息如下"<<endl;
show(l);
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"輸入客戶姓名,證件號:";
cin>>k.name>>k.k_id;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"輸入客戶選擇的航班號,位置(行,列):";
cin>>k.kp_id>>k.r>>k.c;
if(judge(l,k))
{
creatk(L,k);
alter(l,k,1);
}
else
{
cout<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"座位已有人,不能訂票,請重新選擇!"<<endl;
}
getchar();
getchar();
system("cls");
}
else if(choose==2)//退票
{
cout<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"輸入客戶信息(名字,證件號,航班)"<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t';
cin>>k.name>>k.k_id>>k.kp_id;
int flag=delet(L,k);
if(flag)
{
alter(l,k,0);
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"退票成功"<<endl;
}
else
{
cout<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"查找失敗,請重新輸入"<<endl;
}
getchar();
getchar();
system("cls");
}
else if(choose==3)
{
cout<<endl<<endl;
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"輸入客戶信息(名字,證件號,航班):";
cin>>k.name>>k.k_id>>k.kp_id;
int flag=searchh(L,k);
if(flag)
{
showone(l,k);
}
else
{
cout<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"查找失敗,請重新輸入"<<endl;
}
getchar();
getchar();
system("cls");
}
}
}
更多學習資料請關注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持我們。
您可能感興趣的文章
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用函數(shù)刪除字符
- 04-02c語言的正則匹配函數(shù) c語言正則表達式函數(shù)庫
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言中對數(shù)函數(shù)的表達式 c語言中對數(shù)怎么表達
- 04-02c語言用函數(shù)寫分段 用c語言表示分段函數(shù)
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排序法函數(shù)
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段函數(shù)
- 04-02C語言中怎么打出三角函數(shù) c語言中怎么打出三角函數(shù)的值
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求階乘


閱讀排行
本欄相關
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對數(shù)函數(shù)的表達式 c語言中對
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機閱讀
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-11ajax實現(xiàn)頁面的局部加載
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 04-02jquery與jsp,用jquery
- 01-10delphi制作wav文件的方法
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10C#中split用法實例總結(jié)
- 01-10SublimeText編譯C開發(fā)環(huán)境設置


