1. c語言程序寫飛機訂票系統

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>//overflow

#define ok 1

typedef struct Yidingkehu
{//單鏈表
char name[15];//已訂票的客戶姓名
int dingpiaoshu;//已訂票數量
struct Yidingkehu *next1;//
}Yidingkehu,*Link;

typedef struct Weidingkehu
{//單鏈隊
char name[15];//預訂票的客戶姓名
int yudingpiao;// 要訂票數量
struct Weidingkehu *next2;//下一個鏈隊結點指針
}Weidingkehu,*Qptr;

typedef struct Hangxian
{//創建一個含有六個信息的結構體
char hangbanhao[15];//航班號-
char feijihao[15];//飛機號
int feixingriqi;//起飛時間
int chenkerenshu;//座位數
int yupiao;//余票
char zhongdianzhai[15];//降落城市
struct Hangxian *next;//指向下一個鏈結點的指針
struct Yidingkehu *yiding;//定義一個指向已訂票客戶的頭結點指針
struct Weidingkehu *yudingqueue;
}Hangxian,*Linklist;

Linklist InitLinklist();//01
int InsertLinklist(Linklist &head1);//02

void hbhchaxun();//通過航班號查詢
void mddchaxun();//通過目的地查詢

void lurugongneng();//初始化錄入功能
void chaxungongnen();//查詢功能
void dingpiaogongnen();//訂票功能
void tuipiaogongnen();//退票功能

void main()
{

int n;
do{ //列印主界面
printf("\t 歡迎使用航空客運訂票系統\n");
printf("\t+++++++++++++++++++++++++++++\n");
printf("\t==>1. 錄入功能 ==\n");
printf("\t==>2. 查詢功能 ==\n");
printf("\t==>3. 訂票功能 ==\n");
printf("\t==>4. 退票功能 ==\n");
printf("\t==>5. 退出 ==\n");
printf("\t+++++++++++++++++++++++++++++\n");
printf("\t請選擇:");
scanf("%d",&n);printf("\n");
switch(n)
{
case 1: lurugongneng();//錄入功能
break;
case 2: chaxungongnen();//查詢功能
break;
case 3: dingpiaogongnen();//訂票功能
break;
case 4:tuipiaogongnen();//退票功能
break;
default :exit(0);//退出
}
}while(n==1||n==2||n==3||n==4);
}

void lurugongneng()//初始化的單鏈表*********************************************************錄入功能
{

Linklist p;
//int m,n;
if(!p) exit(OVERFLOW);
printf("\t請依次輸入下面幾項內容:\n\n");//這里的輸入採用一個個單獨輸入,避免了亂賦值的現象
printf("航班號\n");
gets(p->hangbanhao);//這里的二個gets主要是因為在回車鍵的輸入,其中的第一個是來接收上次的回車
gets(p->hangbanhao);
printf("飛機號\n");
gets(p->feijihao);
printf("終點站\n");
gets(p->zhongdianzhai);
printf("飛行日期\n");
scanf("%d",&p->feixingriqi);
printf("乘客總數\n");
scanf("%d",&p->chenkerenshu);
printf("余票數\n");
scanf("%d",&p->yupiao);

}

void chaxungongnen()//******************************************************************查詢功能
{
int n;
printf("\t 查 找 航 線 信 息 \n");
printf("\t+++++++++++++++++++++++++++++\n");
printf("\t==>1. 通過目的地查詢 ==\n");
printf("\t==>2. 通過航班號查詢 ==\n");
printf("\t+++++++++++++++++++++++++++++\n");
printf("\t請選擇:");
scanf("%d",&n);
printf("\n");//格式化
switch(n)
{
case 1:mddchaxun();
break;
case 2:hbhchaxun();
break;
default :break;
}
}

void mddchaxun()//通過目的地查詢
{
char c[15];
int m;
Linklist p=L;
printf("\t請輸入要查詢的目的地:");
gets(c);
gets(c);//原因同上
do{
p=p->next;
if(p)
{
m=strcmpi((*p).zhongdianzhai,c);//如果==的話則m=0;
if(m==0)
{
printf("\t航班信息:\n");
printf("\t航班號:%s\n",p->hangbanhao);
printf("\t飛機號:%s\n",p->feijihao);
printf("\t飛行時間:周%d\n",p->feixingriqi);
printf("\t余票量:%d\n",p->yupiao);
}
}
else
{//如果不匹配的話就做
printf("\t對不起沒有你要找的目的地:\n\n"); m=0;
}
}while(m!=0);
}

void hbhchaxun()//通過目的地查詢
{
char c[15];
int m;
Linklist p=L;
printf("\t請輸入要查詢的航班號:");
gets(c); gets(c);printf("\n");
do{
p=p->next;
if(p)
{
m=strcmpi((*p).hangbanhao,c);//如果==的話則m=0;這里的(*p).與p->的作用是一樣的
if(m==0)
{
printf("\t航班信息:\n");
printf("\t航班號:%s\n",p->hangbanhao);
printf("\t飛機號:%s\n",p->feijihao);
printf("\t飛行時間:周%d\n",p->feixingriqi);
printf("\t余票量:%d\n\n",p->yupiao);
}
}
else
{//如果不匹配的話就做
printf("\t對不起沒有你要找的航班號:\n"); m=0;
}
}while(m!=0);
}

void dingpiaogongnen()//***************************************************************訂票功能
{

char c[15];
int m=1,piao,ydpiao=0,yd=0,n;//
gets(c);
printf("請輸入終點站名:"); gets(c); printf("\n");
p=L->next;
if(p) {
do{//查找一下,是否有這個航班
if(!p)
{
printf("對不起,沒有你要找的航班:\n\n");
goto loop1;
}
m=strcmpi(p->zhongdianzhai,c);
if(m==0)
{
printf("航班信息:\n");
printf("航班號:%s\n",p->hangbanhao);
printf("飛機號:%s\n",p->feijihao);
printf("飛行時間:周%d\n",p->feixingriqi);
printf("余票量:%d\n",p->yupiao);}
else p=p->next;
}while(m!=0);
if(m==0)
{
do{
printf("\n請輸入你要訂的票數:"); scanf("%d",&piao);
if(piao<=p->yupiao)
{
h=p->yiding;
if(h)
{
h1=h;
h=h->next1;
h=(struct Yidingkehu*)malloc(sizeof(Yidingkehu));
printf("請輸入你的名字:");
gets(h->name);gets(h->name);
h->dingpiaoshu=piao;
h->next1=h1->next1;
h1->next1=h;
p->yupiao=p->yupiao-piao;
printf("訂票成功:\n"); m=2;
}
}
else
{
printf("余票量:%d\n",p->yupiao);
printf("對不起,余票 %d 張不足,不能完成訂票\n\n",p->yupiao);
printf(" 是否要重新訂票?\n");
printf("需要請輸入1 否則請按2 預訂請輸入3 : ");
scanf("%d",&m);
printf("\n");
if(m==3) goto loop3;
}
}while(m==1);
}
}
else if(!p)
{
loop3: struct Weidingkehu *q3;
printf("對不起,該航班的票已售完\n");
q.front=p->yudingqueue;
if(q.front==q.rear) printf("沒有人預訂票,是否要預訂?\n");
else if(q.front!=q.rear) printf("已有人預訂票,是否要預訂?\n");
printf("預訂請輸入1 否則輸入2 : ");
scanf("%d",&n);
printf("\n");
if(n==1)
{

printf("請輸入你的姓名"); gets(q3->name); gets(q3->name);//q3不能指向name???
printf("請輸入訂票數"); scanf("%d",&q3->yudingpiao);
q3->next2=NULL;
q.rear->next2=q3;
q.rear=q3;
printf(" 你已經預訂了 !\n");
}
}
loop1:;
}

void tuipiaogongnen()//***************************************************************退票功能
{

}
請點贊答案,支持我一下。

2. c語言飛機訂票系統

這個我可以幫你寫

3. C語言 訂票系統

可以對資料庫操作不?還是將所有信息自己寫入臨時數據文件???

如果有資料庫的話這個倒是很簡單實現,用文件的話稍微麻煩點...還有就是在修改數據文件的時候運行可能比較慢,因為我的辦法是刪除現有文件然後重新寫入...如果記錄很多的話是比較慢的...直接更新表記錄的話就很快了

4. c語言程序設計火車票訂票系統

很多軟體網站有下載。
推薦去:www.newhua.com去看看,。有你要的。

5. 用c語言編寫航班訂票系統。

你覺不覺的這個軟體已經達到商業化標准了?這樣的東西是不可能在這里給你解答的。
你還是自己寫吧,如果中途有問題可以找我,一起研究下。

6. c語言如何編寫飛機訂票系統

java">#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>//overflow

#defineok1

typedefstructYidingkehu
{//單鏈表
charname[15];//已訂票的客戶姓名
intdingpiaoshu;//已訂票數量
structYidingkehu*next1;//
}Yidingkehu,*Link;

typedefstructWeidingkehu
{//單鏈隊
charname[15];//預訂票的客戶姓名
intyudingpiao;//要訂票數量
structWeidingkehu*next2;//下一個鏈隊結點指針
}Weidingkehu,*Qptr;

typedefstructHangxian
{//創建一個含有六個信息的結構體
charhangbanhao[15];//航班號-
charfeijihao[15];//飛機號
intfeixingriqi;//起飛時間
intchenkerenshu;//座位數
intyupiao;//余票
charzhongdianzhai[15];//降落城市
structHangxian*next;//指向下一個鏈結點的指針
structYidingkehu*yiding;//定義一個指向已訂票客戶的頭結點指針
structWeidingkehu*yudingqueue;
}Hangxian,*Linklist;

LinklistInitLinklist();//01
intInsertLinklist(Linklist&head1);//02

voidhbhchaxun();//通過航班號查詢
voidmddchaxun();//通過目的地查詢

voidlurugongneng();//初始化錄入功能
voidchaxungongnen();//查詢功能
voiddingpiaogongnen();//訂票功能
voidtuipiaogongnen();//退票功能

voidmain()
{

intn;
do{//列印主界面
printf(" 歡迎使用航空客運訂票系統 ");
printf(" +++++++++++++++++++++++++++++ ");
printf(" ==>1.錄入功能== ");
printf(" ==>2.查詢功能== ");
printf(" ==>3.訂票功能== ");
printf(" ==>4.退票功能== ");
printf(" ==>5.退出== ");
printf(" +++++++++++++++++++++++++++++ ");
printf(" 請選擇:");
scanf("%d",&n);printf(" ");
switch(n)
{
case1:lurugongneng();//錄入功能
break;
case2:chaxungongnen();//查詢功能
break;
case3:dingpiaogongnen();//訂票功能
break;
case4:tuipiaogongnen();//退票功能
break;
default:exit(0);//退出
}
}while(n==1||n==2||n==3||n==4);
}

voidlurugongneng()//初始化的單鏈表*********************************************************錄入功能
{

Linklistp;
//intm,n;
if(!p)exit(OVERFLOW);
printf(" 請依次輸入下面幾項內容: ");//這里的輸入採用一個個單獨輸入,避免了亂賦值的現象
printf("航班號 ");
gets(p->hangbanhao);//這里的二個gets主要是因為在回車鍵的輸入,其中的第一個是來接收上次的回車
gets(p->hangbanhao);
printf("飛機號 ");
gets(p->feijihao);
printf("終點站 ");
gets(p->zhongdianzhai);
printf("飛行日期 ");
scanf("%d",&p->feixingriqi);
printf("乘客總數 ");
scanf("%d",&p->chenkerenshu);
printf("余票數 ");
scanf("%d",&p->yupiao);

}

voidchaxungongnen()//******************************************************************查詢功能
{
intn;
printf(" 查找航線信息 ");
printf(" +++++++++++++++++++++++++++++ ");
printf(" ==>1.通過目的地查詢== ");
printf(" ==>2.通過航班號查詢== ");
printf(" +++++++++++++++++++++++++++++ ");
printf(" 請選擇:");
scanf("%d",&n);
printf(" ");//格式化
switch(n)
{
case1:mddchaxun();
break;
case2:hbhchaxun();
break;
default:break;
}
}

voidmddchaxun()//通過目的地查詢
{
charc[15];
intm;
Linklistp=L;
printf(" 請輸入要查詢的目的地:");
gets(c);
gets(c);//原因同上
do{
p=p->next;
if(p)
{
m=strcmpi((*p).zhongdianzhai,c);//如果==的話則m=0;
if(m==0)
{
printf(" 航班信息: ");
printf(" 航班號:%s ",p->hangbanhao);
printf(" 飛機號:%s ",p->feijihao);
printf(" 飛行時間:周%d ",p->feixingriqi);
printf(" 余票量:%d ",p->yupiao);
}
}
else
{//如果不匹配的話就做
printf(" 對不起沒有你要找的目的地: ");m=0;
}
}while(m!=0);
}

voidhbhchaxun()//通過目的地查詢
{
charc[15];
intm;
Linklistp=L;
printf(" 請輸入要查詢的航班號:");
gets(c);gets(c);printf(" ");
do{
p=p->next;
if(p)
{
m=strcmpi((*p).hangbanhao,c);//如果==的話則m=0;這里的(*p).與p->的作用是一樣的
if(m==0)
{
printf(" 航班信息: ");
printf(" 航班號:%s ",p->hangbanhao);
printf(" 飛機號:%s ",p->feijihao);
printf(" 飛行時間:周%d ",p->feixingriqi);
printf(" 余票量:%d ",p->yupiao);
}
}
else
{//如果不匹配的話就做
printf(" 對不起沒有你要找的航班號: ");m=0;
}
}while(m!=0);
}

voiddingpiaogongnen()//***************************************************************訂票功能
{

charc[15];
intm=1,piao,ydpiao=0,yd=0,n;//
gets(c);
printf("請輸入終點站名:");gets(c);printf(" ");
p=L->next;
if(p){
do{//查找一下,是否有這個航班
if(!p)
{
printf("對不起,沒有你要找的航班: ");
gotoloop1;
}
m=strcmpi(p->zhongdianzhai,c);
if(m==0)
{
printf("航班信息: ");
printf("航班號:%s ",p->hangbanhao);
printf("飛機號:%s ",p->feijihao);
printf("飛行時間:周%d ",p->feixingriqi);
printf("余票量:%d ",p->yupiao);}
elsep=p->next;
}while(m!=0);
if(m==0)
{
do{
printf(" 請輸入你要訂的票數:");scanf("%d",&piao);
if(piao<=p->yupiao)
{
h=p->yiding;
if(h)
{
h1=h;
h=h->next1;
h=(structYidingkehu*)malloc(sizeof(Yidingkehu));
printf("請輸入你的名字:");
gets(h->name);gets(h->name);
h->dingpiaoshu=piao;
h->next1=h1->next1;
h1->next1=h;
p->yupiao=p->yupiao-piao;
printf("訂票成功: ");m=2;
}
}
else
{
printf("余票量:%d ",p->yupiao);
printf("對不起,余票%d張不足,不能完成訂票 ",p->yupiao);
printf("是否要重新訂票? ");
printf("需要請輸入1否則請按2預訂請輸入3:");
scanf("%d",&m);
printf(" ");
if(m==3)gotoloop3;
}
}while(m==1);
}
}
elseif(!p)
{
loop3:structWeidingkehu*q3;
printf("對不起,該航班的票已售完 ");
q.front=p->yudingqueue;
if(q.front==q.rear)printf("沒有人預訂票,是否要預訂? ");
elseif(q.front!=q.rear)printf("已有人預訂票,是否要預訂? ");
printf("預訂請輸入1否則輸入2:");
scanf("%d",&n);
printf(" ");
if(n==1)
{

printf("請輸入你的姓名");gets(q3->name);gets(q3->name);//q3不能指向name???
printf("請輸入訂票數");scanf("%d",&q3->yudingpiao);
q3->next2=NULL;
q.rear->next2=q3;
q.rear=q3;
printf("你已經預訂了! ");
}
}
loop1:;
}

voidtuipiaogongnen()//***************************************************************退票功能
{

}
///////////以下是人家的要求//////////
1、本系統採用一個包含N個數據的結構體數組,每個數據的結構應當包括:起飛地、目的地航班號、座次號碼、座次訂出與否標記、訂座者的姓名和訂座者的身份證號碼。
2、本系統顯示這樣的菜單:
(1)輸入航班信息
(2)輸出航班信息
(3)查找航班信息
a.顯示空座的數量
b.顯示空座的信息
c.顯示已訂座的信息
d.起飛時間
(4)訂票預約
(5)刪除定票預約
(6)退出系統
1、本系統成功執行菜單的每個信息,選項4)和5)將要求額外的輸入,並且它們都允許用戶收回其輸入。
2、查找航班信息既可按線路查,也可按目的地查。
4、在兩次運行之間,數據被保存於一個文件里,當本程序重新開
始的時候,它首先從該文件讀入數據

7. 用C語言做火車訂票系統

20分,你想弄到這個系統,我看不可能.
這個是要RMB的.

8. c語言編寫飛機訂票系統程序

這是個非可視化軟體
沒有意義,只為教學!

9. c語言程序設計飛機訂票系統

呵呵 這個也是我在網上搜的 挺不錯 沒有錯誤
#include<stdio.h> //標准輸入、輸出頭文件
#include<string.h> //包含字元串函數處理頭文件
#include<stdlib.h> //包含動態存儲與釋放函數頭文件
#define N 10000
struct air //定義結構體數組
{
int num;
char start[20];
char over[20];
char time[10];
int count;
}s[N];
int i;
int m=0;
#define PRINT "%-d%12s%12s%10s%12d\n",s[i].num,s[i].start,s[i].over,s[i].time,s[i].count //定義輸出格式
void input(); //輸入航班信息
void print(); //輸出航班信息
void save(); //保存航班信息
void read(); //讀取航班信息
void search(); //查找航班信息
void shanchu(); //刪除航班信息
void dingpiao(); //訂票信息
void tuipiao(); //退票信息
void xiugai(); //修改信息
void main()
{

int j;
printf(" ★---您好,歡迎進入中國民航管理系統!---★\n");
printf("================================================================================\n");
do
{
printf(" -------- ☆ 1.輸入航班信息 ☆-------- \n\n"
" -------- ☆ 2.瀏覽航班信息 ☆-------- \n\n"
" -------- ☆ 3.修改航班信息 ☆-------- \n\n"
" -------- ☆ 4.查找航班信息 ☆-------- \n\n"
" -------- ☆ 5.刪除航班信息 ☆-------- \n\n"
" -------- ☆ 6.訂票信息 ☆-------- \n\n"
" -------- ☆ 7.退票信息 ☆-------- \n\n"
" -------- ☆ 0.退出 ☆-------- \n\n");
printf("================================================================================\n");
printf("請在0-7中選擇以回車鍵結束:\n\n");
scanf("%d",&j);
switch(j)
{
case 1: input();//調用輸入模塊
break;
case 2:print();//調用列印模塊
break;
case 3:xiugai();//調用修改模塊
break;
case 4:search();//調用查找模塊
break;
case 5:shanchu(); //調用刪除模塊
break;
case 6:dingpiao();//調用訂票模塊
break;
case 7:tuipiao();//調用退票模塊
break;
case 0:;
break;
}
}while(j!=0); //判斷結束
printf("謝謝使用,再見!\n");
}//主函數結束
void input()//列印模塊程序
{
char f[]="2008china"; //設置密碼
int y;
printf("請輸入密碼並以回車鍵結束:\n\n");
scanf("%s",f); //讀取密碼
if(strcmp(f,"2008china")==0)
{
printf("請依次輸入航班信息(機票數位0結束輸入):\n\n"
"完成輸入信息請鍵入w以回車鍵結束\n\n"); //列印提示信息
printf("--------------------------------------------------------------------------\n");
for(i=0;i<N;i++)
{

printf("請輸入航班號:\n");
scanf("%d",&s[i].num); //讀取航班號
printf("請輸入起始站:\n");
scanf("%s",s[i].start);//讀取起始站
printf("請輸入終點站:\n");
scanf("%s",s[i].over);//讀取終點站
printf("請輸入時間:\n");
scanf("%s",s[i].time);//讀取時間
printf("請輸入機票數(機票數為0結束輸入):\n",m);
scanf("%d",&s[i].count);//讀取機票數
m++;

printf("第%d個信息已經輸完是否繼續?按任意鍵繼續,按 0結束",m);
scanf("%d",&y);
if(y==0)
{
save();//將結構體信息存檔
print();//輸出輸入的航班信息
break;
}

}

}
else
printf("輸入密碼錯誤!請檢查您的密碼是否正確!謝謝!再見!\n\n");
}
void save()//保存模塊程序
{
FILE *fp,*fp1;//定義文件指針
if((fp=fopen("chen.dat","wb"))==NULL)//打開文件並判斷是否出錯
{
printf("創建文件失敗!\n\n");//列印出錯提示
getchar();
return;
}
if((fp1=fopen("hao.dat","wb"))==NULL)//打開文件並判斷是否出錯
{
printf("創建文件失敗!\n\n");//列印出錯提示
getchar();
return;
}

for(i=0;i<m;i++)
if(fwrite(&s[i],sizeof(struct air),1,fp)==0)//向文件寫入數據,並判斷是否出錯
printf("向文件輸入數據失敗!\n\n");
fprintf(fp1,"%d",m);
fclose(fp);//關閉文件
fclose(fp1);//關閉文件
}

void read()//從文件讀取信息模塊
{
FILE *fp,*fp1;//定義文件指針
if((fp=fopen("chen.dat","rb"))==NULL)//打開文件,並判斷是否出錯
{
printf("出錯,請檢查文件是否存在,按任意鍵返回住菜單");//列印出錯提示
getchar();
}
if((fp1=fopen("hao.dat","rb"))==NULL)//打開文件並判斷是否出錯
{
printf("創建文件失敗!\n\n");//列印出錯提示
getchar();
return;
}
fscanf(fp1,"%d",&m);
fclose(fp1);//關閉文件
for(i=0;i<m;i++)
{
fread(&s[i],sizeof(air),1,fp);//從文件中讀取信息
}
fclose(fp);//關閉文件
}
void print()//列印模塊
{
char w[10];
read();//調用讀取文件函數
printf("航班號 起始站 終點站 時間 機票數\n");
for(i=0;i<m;i++)
{
printf(PRINT);//列印信息
}
printf("請按任意鍵回車鍵結束返回上層菜單以:\n");
scanf("%s",w);
}

void search()//查詢模塊
{
char name1[20];
char name2[20];
char ii[10];
int n,no;
do
{
printf("請選擇查找方式:\n\n");//列印查詢方式菜單
printf("1.按航班號查找\n\n"
"2.按終點站查找\n\n"
"3.按航線查找\n\n"
"0.返回\n\n");
printf("請在0-3中選擇:\n\n"
"按其他鍵以回車鍵結束返回主菜單:\n\n");
scanf("%d",&n);//讀取查找方式
if(n==0)
break;
switch(n)
{
case 1:
printf("請輸入航班號:\n");
scanf("%d",&no);//航班號
break;
case 2:
printf("請輸入終點站名稱:\n");
scanf("%s",name2);//讀取終點站
break;
case 3:
printf("請輸入起始站名稱:\n");
scanf("%s",name1);//讀取起始站
printf("請輸入終點站名稱:\n");
scanf("%s",name2);//終點站
break;
}
read();//調用讀取函數
for(i=0;i<m;i++)
{
if(strcmp(s[i].over,name1)==0||strcmp(s[i].over,name2)==0)//按終點站起始站判斷輸出條件
{
printf("\n查找航班信息成功!\n");
printf("航班號 起始站 終點站 時間 機票數\n");
printf(PRINT);//列印信息
break;
}
if(s[i].num==no)//按航班號判斷輸出條件
{
printf("\n查找航班信息成功!\n");
printf("航班號 起始站 終點站 時間 機票數\n");
printf(PRINT);//列印信息
break;
}
}
no=0;//將航班號賦值為0
printf("沒有您需要的信息或查找完畢:\n\n"
"是否繼續查找?請鍵入yes或no以回車鍵結束\n");
scanf("%s",ii);
}while(strcmp(ii,"yes")==0);//判斷結束
}
void shanchu()//刪除模塊
{
char name1[20];
char name2[20];
char ii[10];
char f[]="2008china";//設置密碼
int no,n;
printf("請輸入密碼並以回車鍵結束:\n\n");
scanf("%s",f);//讀取密碼
if(strcmp(f,"2008china")==0) //判斷密碼是否正確
{
do
{
printf("請選擇刪除以方式回車鍵結束:\n\n");//列印刪除方式菜單
printf("*1.按航班號刪除\n\n"
"*2.按航線刪除\n\n"
"*0.返回\n\n");
printf("請在0-2中選擇以回車鍵結束:\n");
scanf("%d",&n);//讀取刪除方式
if(n==0)
break; //跳出循環
switch(n)
{
case 1:
printf("請輸入航班號:\n");
scanf("%d",&no);//讀取航班號
read();//調用讀取函數
break;//跳出循環
case 2:
printf("請輸入起始站 名稱:\n");
scanf("%s",name1);//讀取起始站
printf("請輸入終點站名稱:\n");
scanf("%s",name2);//讀取終點站
read();//調用讀取函數
break;//跳出循環
}
for(i=0;i<m;i++)
{
if(s[i].num==no||strcmp(s[i].start,name1)==0&&strcmp(s[i].over,name2)==0)//判斷輸入信息是否存在
{
s[i]=s[m-1];
m--;
}

}
printf("查找完畢或沒有這個信息\n\n");
printf("是否繼續刪除\n");
printf("請鍵入yes或no以回車鍵結束\n");
scanf("%s",ii); //讀取是否繼續信息
save(); //調用讀取函數
if(!strcmp(ii,"yes")) //判斷是否繼續刪除
printf("請按任意鍵以回車鍵結束返回上層菜單:\n");
break;
}while(n!=1&&n!=2&&n!=3&&n!=4&&n!=0); //判斷結束
}
else
printf("對不起密碼錯誤!您不是管理員,不能使用此項功能!謝謝!再見!\n\n");
}

void dingpiao()//訂票模塊
{
int n;
char a[10];
do
{
search();//調用查詢模塊
printf("請輸入您要訂的機票數以回車鍵結束:\n");
scanf("%d",&n);//讀取所訂機票數
if(n<0)
{
printf("請輸入有效的機票數!\n");//判斷機票數是否出錯
break;
}
if(s[i].count!=0&&s[i].count>=n)//判斷是否出錯
{
s[i].count=s[i].count-n;
save();//調用保存函數
printf("訂票成功!\n\n");
break;
}
if(s[i].count<n)//判斷是否出錯
{
printf("請輸入有效的機票數:\n");
break;
}
printf("是否繼續? 請輸入yes或no以回車鍵結束:\n");//判斷是否繼續訂票
scanf("%s",a);
}while(!strcmp(a,"yes"));//判斷結束

}
void tuipiao()//退票模塊
{
int n;
char a[10];
do
{
search();//調用查詢模塊
printf("請輸入您要退的機票數目:\n");
scanf("%d",&n);//輸入所退票數
if(n<0) //判斷票數是否有效
printf("請輸入有效的機票數!\n");
s[i].count=s[i].count+n;
save(); //調用保存模塊
printf("退票成功!\n\n");
printf("是否繼續? 請鍵入yes或no以回車鍵結束:\n\n");//判斷是否繼續退票
scanf("%s",a);
}while(!strcmp(a,"yes"));//判斷並跳出循環
getchar();
}
void xiugai() //修改模塊
{
struct xiu //定義結構體
{
int no;
char name1[20];
char name2[20];
char time[20];
int count;
}x[1];
char j[10];
char f[]="2008china";//設置密碼
int n;
printf("請輸入密碼並以回車鍵結束:\n\n");
scanf("%s",f);//讀取密碼
if(strcmp(f,"2008china")==0)//判斷是否出錯
{
read();//調用讀取模塊
do
{
printf( "請選擇修改方式:\n\n"
"*1,按航班號修改:\n\n"
"*2,按航線修改: \n\n");
printf("請在1---2中修改以回車鍵結束:\n\n");
scanf("%d",&n);//讀取修改方式
switch(n)
{
case 1:printf("請輸入航班號:\n");
scanf("%d",&x[0].no);//讀取航班號
break;
case 2:printf("請輸入起始站:\n");
scanf("%s",x[0].name1);//讀取起始站
printf("請輸入終點站:\n");
scanf("%s",x[0].name2);//讀取終點站
break;
}
for(i=0;i<m;i++)
{
if(strcmp(s[i].over,x[0].name1)==0&&strcmp(s[i].over,x[0].name2)==0)//判斷輸出條件
{
printf("航班號 起始站 終點站 時間 機票數\n");
printf(PRINT);
break;
}
if(s[i].num==x[0].no)//判斷輸出條件
{
printf("航班號 起始站 終點站 時間 機票數\n");
printf(PRINT);
break;
}
}
x[0].no=0; //將結構體中的號為零
printf("請輸入新航班號、起始站、終點站、時間(星期幾)、機票數:\n");
scanf("%d%s%s%s%d",&x[0].no,x[0].name1,x[0].name2,x[0].time,&x[0].count);//定義輸入格式
s[i].num=x[0].no;//替換航班號
strcpy(s[i].start,x[0].name1);//替換其始站
strcpy(s[i].over,x[0].name2);//替換終點站
strcpy(s[i].time,x[0].time);//替換時間
s[i].count=x[0].count;//替換機票數
save();//調用保存模塊
printf("是否繼續?請鍵入yes或no以回車鍵結束:\n\n");
scanf("%s",j);
}while(strcmp(j,"yes")==0); //判斷結束
}
else
printf("對不起密碼錯誤!您不是管理員,不能使用此項功能!謝謝!再見!\n\n");
}

10. 用C語言寫火車訂票系統

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int shoudsave=0 ;
int count1=0,count2=0,mark=0,mark1=0 ;
/*定義存儲火車信息的結構體*/
struct train
{
char num[10];/*列車號*/
char city[10];/*目的城市*/
char takeoffTime[10];/*發車時間*/
char receiveTime[10];/*到達時間*/
int price;/*票價*/
int bookNum ;/*票數*/
};
/*訂票人的信息*/
struct man
{
char num[10];/*ID*/
char name[10];/*姓名*/
int bookNum ;/*需求的票數*/
};
/*定義火車信息鏈表的結點結構*/
typedef struct node
{
struct train data ;
struct node * next ;
}Node,*Link ;
/*定義訂票人鏈表的結點結構*/
typedef struct people
{
struct man data ;
struct people*next ;
}bookMan,*bookManLink ;
/* 初始界面*/
void printInterface()
{
puts("********************************************************");
puts("* Welcome to use the system of booking tickets *");
puts("********************************************************");
puts("* You can choose the operation: *");
puts("* 1:Insert a train information *");
puts("* 2:Inquire a train information *");
puts("* 3:Book a train ticket *");
puts("* 4:Update the train information *");
puts("* 5:Advice to you about the train *");
puts("* 6:save information to file *");
puts("* 7:quit the system *");
puts("********************************************************");
}
/*添加一個火車信息*/
void InsertTraininfo(Link linkhead)
{
struct node *p,*r,*s ;
char num[10];
r = linkhead ;
s = linkhead->next ;
while(r->next!=NULL)
r=r->next ;
while(1)
{
printf("please input the number of the train(0-return)");
scanf("%s",num);
if(strcmp(num,"0")==0)
break ;
/*判斷是否已經存在*/
while(s)
{
if(strcmp(s->data.num,num)==0)
{
printf("the train '%s'has been born!\n",num);
return ;
}
s = s->next ;
}
p = (struct node*)malloc(sizeof(struct node));
strcpy(p->data.num,num);
printf("Input the city where the train will reach:");
scanf("%s",p->data.city);
printf("Input the time which the train take off:");
scanf("%s",p->data.takeoffTime);
printf("Input the time which the train receive:");
scanf("%s",&p->data.receiveTime);
printf("Input the price of ticket:");
scanf("%d",&p->data.price);
printf("Input the number of booked tickets:");
scanf("%d",&p->data.bookNum);
p->next=NULL ;
r->next=p ;
r=p ;
shoudsave = 1 ;
}
}
/*列印火車票信息*/
void printTrainInfo(struct node*p)
{
puts("\nThe following is the record you want:");
printf(">>number of train: %s\n",p->data.num);
printf(">>city the train will reach: %s\n",p->data.city);
printf(">>the time the train take off: %s\nthe time the train reach: %s\n",p->data.takeoffTime,p->data.receiveTime);
printf(">>the price of the ticket: %d\n",p->data.price);
printf(">>the number of booked tickets: %d\n",p->data.bookNum);
}

struct node * Locate1(Link l,char findmess[],char numorcity[])
{
Node*r ;
if(strcmp(numorcity,"num")==0)
{
r=l->next ;
while(r)
{
if(strcmp(r->data.num,findmess)==0)
return r ;
r=r->next ;
}
}
else if(strcmp(numorcity,"city")==0)
{
r=l->next ;
while(r)
{
if(strcmp(r->data.city,findmess)==0)
return r ;
r=r->next ;
}
}
return 0 ;
}

/*查詢火車信息*/
void QueryTrain(Link l)

{
Node *p ;
int sel ;
char str1[5],str2[10];
if(!l->next)
{
printf("There is not any record !");
return ;
}
printf("Choose the way:\n>>1:according to the number of train;\n>>2:according to the city:\n");
scanf("%d",&sel);
if(sel==1)
{
printf("Input the the number of train:");
scanf("%s",str1);
p=Locate1(l,str1,"num");
if(p)
{
printTrainInfo(p);
}
else
{
mark1=1 ;
printf("\nthe file can't be found!");
}
}
else if(sel==2)
{
printf("Input the city:");
scanf("%s",str2);
p=Locate1(l,str2,"city");
if(p)
{
printTrainInfo(p);
}
else
{
mark1=1 ;
printf("\nthe file can't be found!");
}
}
}

/*訂票子模塊*/
void BookTicket(Link l,bookManLink k)
{
Node*r[10],*p ;
char ch,dem ;
bookMan*v,*h ;
int i=0,t=0 ;
char str[10],str1[10],str2[10];
v=k ;
while(v->next!=NULL)
v=v->next ;
printf("Input the city you want to go: ");
scanf("%s",&str);
p=l->next ;
while(p!=NULL)
{
if(strcmp(p->data.city,str)==0)
{
r[i]=p ;
i++;
}
p=p->next ;
}
printf("\n\nthe number of record have %d\n",i);
for(t=0;t<i;t++)
printTrainInfo(r[t]);
if(i==0)
printf("\n\t\t\tSorry!Can't find the train for you!\n");
else
{
printf("\ndo you want to book it?<1/0>\n");
scanf("%d",&ch);
if(ch == 1)
{
h=(bookMan*)malloc(sizeof(bookMan));
printf("Input your name: ");
scanf("%s",&str1);
strcpy(h->data.name,str1);
printf("Input your id: ");
scanf("%s",&str2);
strcpy(h->data.num,str2);
printf("Input your bookNum: ");
scanf("%d",&dem);
h->data.bookNum=dem ;
h->next=NULL ;
v->next=h ;
v=h ;
printf("\nLucky!you have booked a ticket!");
getch();
shoudsave=1 ;
}
}
}
bookMan*Locate2(bookManLink k,char findmess[])
{
bookMan*r ;
r=k->next ;
while(r)
{
if(strcmp(r->data.num,findmess)==0)
{
mark=1 ;
return r ;
}
r=r->next ;
}
return 0 ;
}
/*修改火車信息*/
void UpdateInfo(Link l)
{
Node*p ;
char findmess[20],ch ;
if(!l->next)
{
printf("\nthere isn't record for you to modify!\n");
return ;
}
else
{
QueryTrain(l);
if(mark1==0)
{
printf("\nDo you want to modify it?\n");
getchar();
scanf("%c",&ch);
if(ch=='y');
{
printf("\nInput the number of the train:");
scanf("%s",findmess);
p=Locate1(l,findmess,"num");
if(p)
{
printf("Input new number of train:");
scanf("%s",&p->data.num);
printf("Input new city the train will reach:");
scanf("%s",&p->data.city);
printf("Input new time the train take off");
scanf("%s",&p->data.takeoffTime);
printf("Input new time the train reach:");
scanf("%s",&p->data.receiveTime);
printf("Input new price of the ticket::");
scanf("%d",&p->data.price);
printf("Input new number of people who have booked ticket:");
scanf("%d",&p->data.bookNum);
printf("\nmodifying record is sucessful!\n");
shoudsave=1 ;
}
else
printf("\t\t\tcan't find the record!");
}
}
else
mark1=0 ;
}
}
/*系統給用戶的提示信息*/
void AdvicedTrains(Link l)
{
Node*r ;
char str[10];
int mar=0 ;
r=l->next ;
printf("Iuput the city you want to go: ");
scanf("%s",str);
while(r)
{
if(strcmp(r->data.city,str)==0&&r->data.bookNum<200)
{
mar=1 ;
printf("\nyou can select the following train!\n");
printf("\n\nplease select the fourth operation to book the ticket!\n");
printTrainInfo(r);
}
r=r->next ;
}
if(mar==0)
printf("\n\t\t\tyou can't book any ticket now!\n");

}
/*保存火車信息*/
void SaveTrainInfo(Link l)
{
FILE*fp ;
Node*p ;
int count=0,flag=1 ;
fp=fopen("c:\\train.txt","wb");
if(fp==NULL)
{
printf("the file can't be opened!");
return ;
}
p=l->next ;
while(p)
{
if(fwrite(p,sizeof(Node),1,fp)==1)
{
p=p->next ;
count++;
}
else
{
flag=0 ;
break ;
}
}
if(flag)
{
printf("the number of the record which have been saved is %d\n",count);
shoudsave=0 ;
}
fclose(fp);
}
/*保存訂票人的信息*/
void SaveBookmanInfo(bookManLink k)
{
FILE*fp ;
bookMan*p ;
int count=0,flag=1 ;
fp=fopen("c:\\man.txt","wb");
if(fp==NULL)
{
printf("the file can't be opened!");
return ;
}
p=k->next ;
while(p)
{
if(fwrite(p,sizeof(bookMan),1,fp)==1)
{
p=p->next ;
count++;
}
else
{
flag=0 ;
break ;
}
}
if(flag)
{
printf("the number of the record which have been saved is %d\n",count);
shoudsave=0 ;
}
fclose(fp);
}

int main()
{
FILE*fp1,*fp2 ;
Node*p,*r ;
char ch1,ch2 ;
Link l ;
bookManLink k ;
bookMan*t,*h ;
int sel ;
l=(Node*)malloc(sizeof(Node));
l->next=NULL ;
r=l ;
k=(bookMan*)malloc(sizeof(bookMan));
k->next=NULL ;
h=k ;
fp1=fopen("c:\\train.txt","ab+");
if((fp1==NULL))
{
printf("can't open the file!");
return 0 ;
}
while(!feof(fp1))
{
p=(Node*)malloc(sizeof(Node));
if(fread(p,sizeof(Node),1,fp1)==1)
{
p->next=NULL ;
r->next=p ;
r=p ;
count1++;
}
}
fclose(fp1);
fp2=fopen("c:\\man.txt","ab+");
if((fp2==NULL))
{
printf("can't open the file!");
return 0 ;
}

while(!feof(fp2))
{
t=(bookMan*)malloc(sizeof(bookMan));
if(fread(t,sizeof(bookMan),1,fp2)==1)
{
t->next=NULL ;
h->next=t ;
h=t ;
count2++;
}
}
fclose(fp2);
while(1)
{
system("cls");
printInterface();
printf("please choose the operation: ");
scanf("%d",&sel);
system("cls");
if(sel==8)
{
if(shoudsave==1)
{
getchar();
printf("\nthe file have been changed!do you want to save it(y/n)?\n");
scanf("%c",&ch1);
if(ch1=='y'||ch1=='Y')
{
SaveBookmanInfo(k);
SaveTrainInfo(l);
}
}
printf("\nThank you!!You are welcome too\n");
break ;

}
switch(sel)
{
case 1 :
InsertTraininfo(l);break ;
case 2 :
QueryTrain(l);break ;
case 3 :
BookTicket(l,k);break ;
case 4 :
UpdateInfo(l);break ;
case 5 :
AdvicedTrains(l);break ;
case 6 :
SaveTrainInfo(l);SaveBookmanInfo(k);break ;
case 7 :
return 0;
}
printf("\nplease press any key to continue.......");
getch();
}
return 0;
}