當前位置:首頁 » 編程語言 » c語言航空訂票系統

c語言航空訂票系統

發布時間: 2025-03-28 10:54:06

Ⅰ 編寫c語言:飛機訂票系統

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <conio.h>
#define MAXSIZE 3

typedef struct wat_ros
{
char name[10];
int req_amt;
struct wat_ros *next;
}qnode,*qptr;

typedef struct pqueue
{
qptr front;
qptr rear;
}linkqueue;

typedef struct ord_ros
{
char name[10];
int ord_amt;
int grade;
struct ord_ros *next;
}linklist;

struct airline
{
char ter_name[10]; /* 站點名 */
char air_num[10]; /* 航班號 */
char plane_num[10]; /* 飛機號 */
char date[7]; /* 飛行日期 */
int tkt_amt; /* 乘員定額 */
int tkt_sur; /* 余票量 */
linklist *order;
linkqueue wait;
}lineinfo;

struct airline *start;
struct airline air[MAXSIZE]={
{"beijing", "1", "B8571", "SUN", 3, 1},
{"shanghai","2","S1002","MON",2,5},
{"london","3","L1003","FRI",1,3}
};;

void display(struct airline *info)
{
printf("%8s\t%3s\t%s\t%4s\t\%d\t\%d\t\n",info->ter_name,info->air_num,info->plane_num,info->date,info->tkt_amt,info->tkt_sur);
}

/* 瀏覽航線信息函數 */
void list()
{
struct airline *info;
int i = 0;
info = start;
printf("終點站名\t航班號\t飛機號\t飛行日期" "乘員定額" "余票量\n");
while(i < MAXSIZE){
display(info);
info++;
i++;
}
printf("\n\n");
}

void search()
{
struct airline *info,*find();
char name[10];
int i=0;
info=start;
printf("請輸入終點站名:");
scanf("%s",name);
while(i<MAXSIZE)
{
if(!strcmp(name,info->ter_name)) break;
info++;
i++;
}
if(i>=MAXSIZE)
printf("對不起,該航線未找到!\n");
else
{
printf("終點站名\t航班號\t飛機號\t飛行日期\t乘員定額\t余票量\n");
display(info);
}
}

struct airline *find()
{
struct airline *info;
char number[10];
int i=0;
info=start;
printf("請輸入航班號:");
scanf("%s",number);

while(i<MAXSIZE)
{
if(!strcmp(number,info->air_num)) return info;
info++;
i++;
}
printf("對不起,該航線末找到!\n");
return NULL;
}

/* 瀏覽已訂票客戶信息 */
void prtlink()
{
linklist *p;
struct airline *info;
info=find();
p=info->order;

if(p!=NULL){
printf("客戶姓名 訂票數額 艙位等級\n");
while(p){
printf("%s\t\t%d\t%d\n",p->name,p->ord_amt,p->grade);
p=p->next;
}
}
else
printf("該航線沒有客戶信息!!\n");
}

linklist *insertlink(linklist *head,int amount,char name[],int grade)

{ linklist *p1,*new1;
p1=head;
new1=(linklist *)malloc(sizeof(linklist));
if(!new1) {printf("\nOut of memory!!\n");return NULL;}
strcpy(new1->name,name);
new1->ord_amt=amount;
new1->grade=grade;
new1->next=NULL;
if(head==NULL)
{head=new1;new1->next=NULL;}
else
head=new1;
new1->next=p1;
return head;
}

linkqueue appendqueue(linkqueue q,char name[],int amount)

{ qptr new1;
new1=(qptr)malloc(sizeof(qnode));
strcpy(new1->name,name);
new1->req_amt=amount;
new1->next=NULL;
if(q.front==NULL)
q.front=new1;
else
q.rear->next=new1;
q.rear=new1;
return q;
}

void order()

{ struct airline *info;
int amount,grade;
char name[10];
info=start;
if(!(info=find())) return;
printf("請輸入你訂票所需要的數量:");
scanf("%d",&amount);
if(amount>info->tkt_amt)
{ printf("\n對不起,您輸入的票的數量已經超過乘員定額!");
return;
}
if(amount<=info->tkt_sur)
{
int i;
printf("請輸入您的姓名(訂票客戶):");
scanf("%s",name);
printf("請輸入%s票的艙位等級:",name);
scanf("%d",&grade);
info->order=insertlink(info->order,amount,name,grade);
for(i=0;i<amount;i++)
printf("%s的座位號是:%d\n",name,info->tkt_amt-info->tkt_sur+i+1);
info->tkt_sur-=amount;
printf("\n祝您乘坐愉快!\n");
}
else
{ char r;
printf("\n已經沒有更多的票,您需要排隊等候嗎?(Y/N)");
//r=getch();
//printf("%c",r);
scanf ( "回車繼續等待%c", &r );
if(r=='Y'||r=='y')
{ printf("\n請輸入您的姓名(排隊訂票客戶):");
scanf("%s",name);
info->wait=appendqueue(info->wait,name,amount);
printf("\n注冊成功!\n");
}
else printf("\n歡迎您下次再次訂購!\n");
}
}

void return_tkt()

{ struct airline *info;
qnode *t,*back,*f,*r;
int grade;
linklist *p1,*p2,*head;
char cusname[10];
if(!(info=find())) return;
head=info->order;
p1=head;
printf("請輸入你的姓名(退票客戶):");
scanf("%s",cusname);
while(p1!=NULL) {
if(!strcmp(cusname,p1->name)) break;
p2=p1;p1=p1->next;
}
if(p1==NULL){ printf("對不起,你沒有訂過票!\n");return;}
else
{
if(p1==head) head=p1->next;
else p2->next=p1->next;
info->tkt_sur+=p1->ord_amt;
grade=p1->grade;
printf("%s成功退票!\n",p1->name);
free(p1);
}

info->order=head;
f=(info->wait).front;
r=(info->wait).rear;
t=f;
while(t)
{
if((info->tkt_sur = info->wait.front->req_amt))
{
int i;
info->wait.front=t->next;
printf("%s訂票成功!\n",t->name);
for(i=0;i<t->req_amt;i++)
printf("%s的座位號是:%d\n",t->name,(info->tkt_sur)-i);
info->tkt_sur-=t->req_amt;
info->order=insertlink(info->order,t->req_amt,t->name,grade);
free(t);
break;
}
back=t;t=t->next;
if((info->tkt_sur)>=(t->req_amt)&&t!=NULL)
{ int i;
back->next=t->next;
printf("%s訂票成功!\n",t->name);
for(i=0;i<t->req_amt;i++)
printf("<%s>'s seat number is:%d\n",t->name,(info->tkt_sur)-i);
info->tkt_sur-=t->req_amt;
info->order=insertlink(info->order,t->req_amt,t->name,grade);
free(t);break;
}
if(f==r) break;
}
}

void sort_tkt()
{
int j;
struct airline t,*info,*p,*q;
p=info=air;
for(p=info;(p+1)->tkt_sur;p++)
for(q=p+1;q->tkt_sur;q++)
{
if(p->tkt_sur<q->tkt_sur)
{
t=*p;
*p=*q;
*q=t;
}
}
printf("終點站名\t航班號\t飛機號\t飛行日期\t乘員定額\t余票量\n");
for(j=0;j<MAXSIZE;j++)
{
display(info);
info++;
}

}

int menu_select()
{
int c;
char s[20];
printf("\n\t\t 航空客運訂票系統(by zjhxmjl)\n");
printf(" ******************************************\n");
printf(" ** 1.瀏覽航線信息 **\n");
printf(" ** 2.瀏覽已訂票客戶信息 **\n");
printf(" ** 3.查詢航線 **\n");
printf(" ** 4.辦理訂票業務 **\n");
printf(" ** 5.辦理退票業務 **\n");
printf(" ** 6.查看剩餘票數並排序 **\n");
printf(" ** 0.退出系統 **\n");
printf(" *******************************************\n");
do
{
printf("請選擇:");
scanf("%s",s);
c = atoi(s); /* atoi將字元串轉換為整型 */
}while(c < 0||c > 7);
return c;
}

int main()
{
start = air;
for(;;)
{
switch(menu_select())
{
case 1:list();break;
case 2:prtlink();break;
case 3:search();break;
case 4:order();break;
case 5:return_tkt();break;
case 6:sort_tkt();break;
case 0:printf("\n歡迎使用本系統,再見!\n");exit(0);
}
printf("\nPress any key to continue!\n");
getchar();
}
return 0;
}

Ⅱ 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、在兩次運行之間,數據被保存於一個文件里,當本程序重新開
始的時候,它首先從該文件讀入數據

Ⅲ 用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;
}

Ⅳ C語言程序設計 飛機訂票管理系統

編制一個航班訂票系統。應具備如下功能:該航班僅有一架100座飛機;該飛機座位分為吸煙區(30個座位)和無煙區(70個);訂票系統界面是選擇菜單:1.選吸煙區座位號;2.選無煙區座位號;用戶輸入自己的選擇後,該區若有空位,則順序地分配一個座號;否則致歉;若吸煙區已滿而無煙區有空位,則徵求顧客意見,是否願意得到無煙區的空位,若願意,則在無煙區分配一個座號,否則致歉退出;顧客不得自主挑選座位號;
#include<cstdio>
#include<stdlib.h>
#include<string.h>
#include<memory.h>
#define LIN 31
#define LIE 71
static int smok[LIN];//吸煙區票
static int nosmoke[LIE];//無煙區票
void Initnosmoke();//初始化
void ASK();void Initsmok();
void nosmok();
void smoke();
int search(int *array,int size);
void show();
int main()
{
Initnosmoke();
Initsmok();show();return 0;}void Initnosmoke()//初始化無煙區票{int sun=0;for(int j=0;j<LIE;j++){sun+=1;nosmoke[j]=sun;}}void Initsmok()//初始化吸煙區票{int k=0;for(int i=0;i<LIN;i++){k+=1;smok[i]=k;}}int search(int *array,int size)/*該函數的作用是用來查看系統中某類票是否賣完,入股賣完了返回1,反之返回的是0*/{int i;for(i=0;i<size;i++){if(array[i]!=0){return 0;}else{;}}return 1;}void nosmok()//購買無煙區票{for(int i=0;i<LIE;i++){if(i<LIE-1){if(nosmoke[i]!=0){printf("你票是:NOSMOKE_%d\n",nosmoke[i]);nosmoke[i]=0;break;}else{;}}else{printf("對不起!NOSMOKE票已售完!");}}}void ASK()/*該函數用來詢問客戶是否需要買NOSMOKE票當SMOKE票賣完的情況下*/{char ask;printf("NOSMOKE票你要嗎?(y/n)\n");ask=getchar();if(ask =='y' || ask=='Y' ){nosmok();}else if(ask=='n' || ask=='N'){printf("謝謝!再見\n");}else{printf("輸入錯誤!\n");}}void smoke()//購買吸煙區票{for(int j=0;j<LIN;j++){if(j<LIN-1){if(smok[j]!=0){printf("你票是: SMOKE_%d\n",smok[j]);smok[j]=0;break;}else{;}}else{printf("對不起!SMOKE票已售完!");{fflush(stdin);int rec=search(nosmoke,LIE);if(rec==0){ASK();}else{printf("謝謝!\n");}}}}}void window(){printf("\t\t歡迎使用航班訂票系統\n");printf("\t\t1.吸煙區座位\n");printf("\t\t2.無煙區座位\n");printf("\t\t3.退出系統\n");printf("\t\t請選擇(1~3)進行操作:\n");}void show(){system("color 4a");char ch=' ';window();while(ch!='3'){fflush(stdin);ch=getchar();switch(ch){case '1':{smoke();break;}case '2':{nosmok();break;}case '3':{break;}default:break;}window();ch=getchar();}}

Ⅳ c語言車票訂購系統

#include

#include

#include

#include

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
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;

}

熱點內容
109五開最便宜怎麼配置 發布:2025-03-31 10:55:49 瀏覽:70
優酷視頻上傳加密碼 發布:2025-03-31 10:44:18 瀏覽:675
OCM伺服器地址基站地址 發布:2025-03-31 10:44:17 瀏覽:645
頁游傳奇腳本 發布:2025-03-31 10:43:44 瀏覽:35
java文件上傳視頻 發布:2025-03-31 10:34:03 瀏覽:985
win7怎麼搜索文件夾 發布:2025-03-31 10:34:03 瀏覽:871
qq怎麼用手機改密碼 發布:2025-03-31 10:34:01 瀏覽:928
堆糖批量上傳圖片 發布:2025-03-31 10:32:20 瀏覽:351
列表分組演算法 發布:2025-03-31 10:26:01 瀏覽:228
安卓廣告是什麼app 發布:2025-03-31 10:21:49 瀏覽:522