票價系統c語言,c語言票務管理系統

本文目錄一覽:

C語言 電影院售票(坐位)系統

這是我自己做的, 是用C# 實現的,,如果你的其它語言,稍做修改,應該符合你的題目:

選題的根據:1) 本選題的理論、實際意義

2) 綜述國內外有關本選題的研究動態和自己的見解

1) 本選題的理論、實際意義

影院售票系統是計算機技術與影院管理相結合的產物,通過影院售票系統實現了對影院的高效

管理。隨著計算機技術的不斷提高,計算機已經深入到社會生活的各個角落.而採用人工售票的方

法,不僅效率低,易出錯,手續繁瑣,而且耗費大量人力。為了滿足售票人員對售票,訂票,退

票等進行高效的管理,在工作人員的具備一定的計算機操作能力的前提下,特編此影院售票系統

軟體以提高影院的管理效率。

2) 綜述國內外有關本選題的研究動態和自己的見解

面對全球方興未艾的影院觀看熱潮,國內外對影院觀看的視覺需求,以及其規模的優勢,其獨有的互動效果和場內氣氛贏得了越來越多的人心。

國外研究動態

1829年,比利時著名物理學家約瑟夫普拉多發現:當一個物體在人的眼前消失後,該物體的形象 還

會在人的視網膜上滯留一段時間,這一發現,被稱之為「視象暫留原理」。普拉多根據此原理於1832

年發明了「詭盤」。「詭盤」能使被描畫在鋸齒形的硬紙盤上的畫片因運動而活動起來,而且能使視

覺上產生的活動畫面分解為各種不同的形象。「詭盤」的出現,標誌著電影的發明進入到了科學實驗

階段。1834年,美國人霍爾納的「活動視盤」試驗成功;1853年,奧地利的馮烏卻梯奧斯將軍在上

述的發明基礎上,運用幻燈,放映了原始的動畫片。

國內研究動態

1979年10月電影事業獲得發展,鄧小平同志代表黨中央肯定了文化大革命前17年的文藝路線基本

是正確的,總結了歷史的經驗教訓,糾正了過去提出的「文藝服從政治 、文藝從屬政治」的偏頗提法 ,

重申執行雙百方針。1977年電影生產開始復甦,1980~1984年平均年產量達120部左右,每年觀眾

人次平均在250億左右,中國電影進入一個蓬勃發展的新時期。中國美術片從形式到內容都極富有民族風格和特色。中華人民共和國建立以後,美術片是中國影片在國際上獲獎最多的一個片種。新聞紀錄片已向縱深發展,充分利用豐富的資料,系統地編輯一些重要的文獻片,並對群眾普遍關心的問題與重要事件進行綜合報道、專題報道;還注意表現人物和人物的精神世界,抓住真人真事中豐富的細節,以情動人。

主要內容:

1) 項目規劃

完成一個完整的影院售票系統,分為影院內部管理和網路服務2個系統,影院內部管理子系統主要實現影院售票員對影院的售票功能,網路服務實現網上查詢瀏覽約定電影院功能。這些功能可以分為以下二部個部分:前台管理,,後台管理

前台現場售票:電影名稱,票價,票價打折,售票,座位,列印票,結帳

後台管理模塊: 管理員主要用於電影類型管理:添加電影種類,介紹,票價,放映場次,放映時間,放映大廳,近幾日放映訂劃管理。具體的功能可以分為以下幾個部分:

影院介紹

預訂電影

2) 系統功能結構圖

研究方法:

廣泛查閱、收集論文資料和研究資源,了解以及參考國內外對影院售票系統的研究成果;研究已存在的影院售票系統,學習他人的設計思想和方法,並在導師的指導下,利用在大學所學的一些軟體開發知識完成該系統。本系統後台資料庫採用目前最新的Microsoft SQL Server 2005,該資料庫系統在安全性、準確性和運行速度方面有絕對的優勢,並且處理數據量大、效率高;前台採用Microsoft 公司的Visual Studio 2005 作為主要的開發工具,其可與 SQL Server 2005資料庫無縫連接。

完成期限和採取的主要措施:

1) 完成期限

階段 階 段 內 容 起止時間

一 準備階段:閱讀搜集相關資料,搭建工作環境,制定設計方案,開題; 10.2.16—10.2.22

二 需求分析、系統設計階段:各模塊功能的設計,資料庫的設計,系統文件夾的設計; 10.2.23—10.2.28

三 網站系統的開發與實現; 10.3.01—10.04.08

四 系統聯調及測試階段:完成各模塊的集成測試,與管理子系統集成,進行聯調和測試,編寫論文。 10.4.10—10.04.30

五 編寫並提交畢業設計論文、設計源文件、源代碼,參加畢業設計答辯。 10.5.01—10.05.20

2) 採取的主要措施

在開發本系統時,系統的界面設計和內核設計使用Visual Studio 2005進行開發,主要措施如下:

使用母版頁構建網站的整體風格

主題的應用

使用存儲過程實現站內模糊查詢

使用哈希表和Session對象實現購物功能

Free TextBox組件的配置使用

主要參考文獻:

[1] 梅曉冬,顏燁青. Visual C#網路編程技術與實踐 [M]. 北京: 清華大學出版社

[2] 劉瑞新 C#網路編程及應用 機械工業出版社

[3] 王平 柴晟 C#程序設計語言任務驅動式教程 北京航空航天大學出版社

[4] 武馬群 SQL Server 2000 資料庫基礎與應用

[5] Christian Nagel. C#高級編程(第6版) [M]. 北京: 清華大學出版社

[6] [美]麥克金,赫特克. SQL Server 2005資料庫伺服器架構設計[M]. 北京: 清華大學出版社

[7] 張躍廷,顧彥玲. ASP.NET 從入門到精通[M]. 北京: 清華大學出版社

[8] 王宏編 C#程序設計案例教程 清華大學出版社

[9] 劉冰 軟體工程實踐教程 機械工程出版社

[10]馬丁. 敏捷軟體開發:原則、模式與實踐(C#版)[M]. 北京: 人民郵電出版社

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:\n1:according to the number of

train;\n2: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)==0r-data.bookNum200)

{

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語言編程設計,分段計算乘坐地鐵票價,速度速度~

#includestdio.h

main()

{

    double km;

    int price = 0;

    scanf(“%lf”,km);

    if (km = 0  km = 6)

    {

        price = 3;

    }

    else if (km  6  km = 16)

    {

        price = 4;

    }

    if (km  16  km = 26)

    {

        price = 5;

    }

    if (km  26)

    {

        price = 6;

    }

     printf(“%d”,price);

}

用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:\n1:according to the number of train;\n2: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;ti;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)==0r-data.bookNum200)

{

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語言

(已修改,請用最新的代碼)代碼說明:

1級菜單:選擇購買的航班號,並顯示對應座位狀態。

(我只做測試,所以初始化initFlight函數中我只初始了2個航班,需要自己按照我的代碼添)

(注意:實際開發軟體,鏈表數據是從資料庫中讀取的,需要實時同步,如果要多次調用initFlight函數,記得自己寫一個釋放內存的函數,把所有鏈表「SINFO和FLINFO」節點都釋放掉,釋放函數我沒寫,需要你自己寫!!!)

2級菜單:選擇購買對應座位號,完成購買,並實時顯示購買結果。

位置編號、座位最大排數、艙室類型、折扣等參數均由常量參數空值,需要修改自行改常量。

注意:艙室類型(我默認3個類型頭等艙、公務艙、經濟艙)對應折扣參數:tDiscount二維數組。如要如要添加新的艙室類型,必須將參數常量TYPESIZE、typeName、types、tDiscount這4個同時修改,具體看代碼備註!!

座位票價=基礎票價*類型折扣*時段折扣。

因為飛機不讓吸煙,所以我沒做吸煙區(笑),如果你需要,可以作為類型自行添加!

#includestdio.h

#includestdlib.h

#includeconio.h

#includestring.h

#includemalloc.h

#includetime.h

//———————–相關參數,想改變,在這裡修改!!!!!!!—————————–

const float timeDiscount=1;//時段折扣,影響所有航班最終價格,默認1

const char cID[5]=”ABCD”;//位置編號

const int maxRow=20;//位置最大排號

//注意:如果修改類型數量,types和tDiscount必須同時修改!!!

#define TYPESIZE 3//類型數量

const char typeName[TYPESIZE][10]={“頭等艙”,”公務艙”,”經濟艙”};

const int types[TYPESIZE][2]={{1,2},{3,4},{5,20}};//排號對應類型。1~2排頭等艙,3~4排公務艙,5~20排經濟艙

const float tDiscount[TYPESIZE]={1.5,1.3,1};//類型折扣。頭等艙1.5倍,公務艙1.3倍,經濟艙1倍

//——————————————————————————-

typedef struct seatInfo//座位信息,一條鏈表對應一個航班信息,鏈表順序從第一排左邊第一個開始往後A1~D1,A2~D2。。。

{

    char cloID;//位置編號A、B、C、D

    int row;//位置排號

    int type;//座位所屬類型:0:頭等艙、1:公務艙、2:經濟艙,不同類型對應不同的類型折扣tDiscount

    int sell;//出售狀態,0:未出售;1:已出售

    struct seatInfo *next;

}SINFO;

typedef struct flightInfo//航班信息

{

    char fid[10];//航班號

    time_t tfTime;//起飛時間

    time_t ldTime;//降落時間

    char toCity[20];//抵達城市

    float tPrice;//基礎票價,不同位置具有不同折扣,座位票價=基礎票價*類型折扣*時段折扣

    struct flightInfo *next;

    struct seatInfo *sHead;//對應座位鏈表的頭節點

}FLINFO;

void meError(void *p);

SINFO *getSINFO();//獲取座位鏈表

//addFLINFO:添加航班信息鏈表的節點flinfoHead:頭節點(第一次傳NULL會自動生成),flinfoTail:尾節點,fNew:要添加的結構信息(成員指針無需賦值)

FLINFO *addFLINFO(FLINFO **ffHead,FLINFO *flinfoTail,FLINFO fNew);//返回尾節點

time_t getTime_tfromStr(char *sTime);//將YYYY-MM-DD hh:mm:ss格式的時間字元串轉換成time_t型數值

FLINFO *initFlight();//初始化航班信息,返回航班鏈表頭節點,如果想手動輸入,請在這裡添加!!!正常軟體開發,這一步應該是從資料庫讀取!

char *getTString(struct tm *tm0);//通過tm獲取時間字元串

void showSinfo(FLINFO *flinfo);//顯示航班對應座位信息

void printfFlinfo(FLINFO * flinfoHead);

FLINFO *selectFlinfo(FLINFO *flinfoHead,char *fid);//選擇航班號,返回節點

void showSinfo(FLINFO *flinfo);//顯示航班對應座位信息

SINFO *selectSinfo(FLINFO *flinfo,char *sid);//選擇座位,返回節點

int main()

{

    FLINFO *flinfoHead=initFlight(),*ffSelect=NULL;

    SINFO *sfSelect=NULL;

    char fid[10]={0},sid[10]={10};

    while(1)

    {

        ffSelect=NULL;

        sfSelect=NULL;

        memset(fid,0,10);

        memset(sid,0,10);

        printfFlinfo(flinfoHead);

        printf(“請輸入要購買的航班號:”);

        scanf(“%s”,fid);

        ffSelect=selectFlinfo(flinfoHead,fid);

        if(!ffSelect)

        {

            printf(“未找到對應航班,按任意鍵繼續—–\n”);

            getch();

            system(“cls”);

            continue;

        }

        system(“cls”);

        printf(“航班號:%s 座位信息如下:\n”,ffSelect-fid);

        showSinfo(ffSelect);

        printf(“請輸入要購買的座位編號(輸入0返回主菜單):”);

        scanf(“%s”,sid);

        if(!strcmp(sid,”0″))

        {

            system(“cls”);

            continue;

        }

        else

        {

            sfSelect=selectSinfo(ffSelect,sid);

            if(!sfSelect||sfSelect-sell)

            {

                printf(“未找到對應座位或該座位已出售,請重新輸入!按任意鍵繼續—–\n”);

                getch();

                system(“cls”);

                continue;

            }

            printf(“購買成功!按任意鍵繼續—–“);

            sfSelect-sell=1;

            getch();

            system(“cls”);

        }

    }

    return 0;

}

SINFO *selectSinfo(FLINFO *flinfo,char *sid)//選擇座位,返回節點

{

    SINFO *sinfoHead=flinfo-sHead;

    while(sinfoHead-next)

    {

        if(sinfoHead-next-cloID==sid[0]  sinfoHead-next-row==atoi(sid+1))

            return sinfoHead-next;

        sinfoHead=sinfoHead-next;

    }

    return NULL;

}

void showSinfo(FLINFO *flinfo)//顯示航班對應座位信息

{

    SINFO *sinfoHead=flinfo-sHead,*sfp=NULL;

    int i,j,k,row=maxRow,clo=strlen(cID);

    char typeStr[10]={0};

    for(i=0;irow;i++)

    {

        //———讀取座位所屬艙室————

        memset(typeStr,0,10);

        for(k=0;kTYPESIZE;k++)

            if(i+1=types[k][0]  i+1=types[k][1])

                strcpy(typeStr,typeName[k]);

        //————————————–

        printf(“\n”);

        for(j=0;jclo;j++)

            printf(“————- “);

        printf(“\n”);

        sfp=sinfoHead;

        for(j=0;jclo;j++)

        {

            printf(“|    %c%02d    | “,sfp-next-cloID,sfp-next-row);

            sfp=sfp-next;

        }

        printf(“\n”);

        sfp=sinfoHead;

        for(j=0;jclo;j++)

        {

            printf(“|     %c     | “,sfp-next-sell?2:1);

            sfp=sfp-next;

        }

        printf(“\n”);

        sfp=sinfoHead;

        for(j=0;jclo;j++)

        {

            printf(“|%6s:%4.0f| “,typeStr,flinfo-tPrice*tDiscount[sfp-next-type]*timeDiscount);

            sfp=sfp-next;

        }

        printf(“\n”);

        sinfoHead=sfp;

    }

    for(j=0;iclo;j++)

            printf(“——- “);

    printf(“\n”);

}

FLINFO *selectFlinfo(FLINFO *flinfoHead,char *fid)//選擇航班號,返回節點

{

    while(flinfoHead-next)

    {

        if(!strcmp(flinfoHead-next-fid,fid))

            return flinfoHead-next;

        flinfoHead=flinfoHead-next;

    }

    return NULL;

}

void printfFlinfo(FLINFO * flinfoHead)

{

    while(flinfoHead-next)

    {

        printf(“目的地:%s,航班號:%s\n—-起飛時間:%s,抵達時間:%s\n\n”,flinfoHead-next-toCity,flinfoHead-next-fid,getTString(localtime(flinfoHead-next-tfTime)),getTString(localtime(flinfoHead-next-ldTime)));

        flinfoHead=flinfoHead-next;

    }

}

char *getTString(struct tm *tm0)//通過tm獲取時間字元串

{

    char *str=(char *)malloc(sizeof(char)*20),num[5]={0};

    meError(str);

    memset(str,0,20);

    sprintf(num,”%4d”,tm0-tm_year+1900);

    strcat(str,num);

    strcat(str,”-“);

    memset(num,0,5);

    sprintf(num,”%02d”,tm0-tm_mon);

    strcat(str,num);

    strcat(str,”-“);

    memset(num,0,5);

    sprintf(num,”%02d”,tm0-tm_mday);

    strcat(str,num);

    strcat(str,” “);

    memset(num,0,5);

    sprintf(num,”%02d”,tm0-tm_hour);

    strcat(str,num);

    strcat(str,”:”);

    memset(num,0,5);

    sprintf(num,”%02d”,tm0-tm_min);

    strcat(str,num);

    strcat(str,”:”);

    memset(num,0,5);

    sprintf(num,”%02d”,tm0-tm_sec);

    strcat(str,num);

    return str;

}

time_t getTime_tfromStr(char *sTime)//將YYYY-MM-DD hh:mm:ss格式的時間字元串轉換成time_t型數值

{

    time_t rt;

    struct tm *tm1=NULL;

    rt=time(NULL);

    tm1=localtime(rt);

    sscanf(sTime,(“%4d-%2d-%2d %2d:%2d:%2d”),tm1-tm_year,tm1-tm_mon,tm1-tm_mday,tm1-tm_hour,tm1-tm_min,tm1-tm_sec);

    tm1-tm_year-=1900;

    tm1-tm_mon–;

    rt=mktime(tm1);

    return rt;

}

FLINFO *initFlight()//初始化航班信息,返回航班鏈表頭節點,如果想手動輸入,請在這裡添加!!!正常軟體開發,這一步應該是從資料庫讀取!

{

    FLINFO *ffHead=NULL,*flinfoTail=NULL,fNew;

    //——–添加一個航班信息—-需要增加按照我下面調用方式寫——————————–

    strcpy(fNew.fid,”CI502″);

    fNew.tfTime=getTime_tfromStr(“2019-02-20 03:30:30”);

    fNew.ldTime=getTime_tfromStr(“2019-02-20 05:20:30”);

    strcpy(fNew.toCity,”台北”);

    fNew.tPrice=1000;

    fNew.next=NULL;

    flinfoTail=addFLINFO(ffHead,flinfoTail,fNew);

    //——————————————————————————————–

    strcpy(fNew.fid,”9C8921″);

    fNew.tfTime=getTime_tfromStr(“2019-02-20 14:30:30”);

    fNew.ldTime=getTime_tfromStr(“2019-02-20 16:40:30”);

    strcpy(fNew.toCity,”香港”);

    fNew.tPrice=500;

    fNew.next=NULL;

    flinfoTail=addFLINFO(ffHead,flinfoTail,fNew);

    return ffHead;

}

FLINFO *addFLINFO(FLINFO **ffHead,FLINFO *flinfoTail,FLINFO fNew)//返回尾節點

//添加航班信息鏈表的節點flinfoHead:頭節點(第一次傳NULL會自動生成),flinfoTail:尾節點,fNew:要添加的結構信息(成員指針無需賦值)

{

    FLINFO *flinfoHead=*ffHead;

    if(flinfoHead==NULL)

    {

        *ffHead=(FLINFO *)malloc(sizeof(FLINFO));

        flinfoHead=*ffHead;

        meError(flinfoHead);

        flinfoHead-next=NULL;

    }

    FLINFO *flinfoNew=(FLINFO *)malloc(sizeof(FLINFO));

    meError(flinfoNew);

    flinfoNew-next=NULL;

    flinfoNew-fid[0]=0;

    strcpy(flinfoNew-fid,fNew.fid);

    flinfoNew-ldTime=fNew.ldTime;

    flinfoNew-tfTime=fNew.tfTime;

    flinfoNew-toCity[0]=0;

    strcpy(flinfoNew-toCity,fNew.toCity);

    flinfoNew-tPrice=fNew.tPrice;

    flinfoNew-sHead=getSINFO();

    if(flinfoHead-next==NULL)

        flinfoHead-next=flinfoNew;

    else

        flinfoTail-next=flinfoNew;

    flinfoTail=flinfoNew;

    return flinfoTail;

}

SINFO *getSINFO()//獲取座位鏈表

{

    int maxClo=strlen(cID),cnt=maxClo*maxRow,clo=0,row=1,i;

    SINFO *sinfoHead=(SINFO *)malloc(sizeof(SINFO)),*sinfoTail=NULL;

    meError(sinfoHead);

    sinfoHead-next=NULL;

    SINFO *sinfoNew=NULL;

    while(cnt–)//按順序生成對應數量的座位鏈表

    {

        if(clo==maxClo)

            clo=0,row++;

        if(row==maxRow+1)

            row=1;

        sinfoNew=(SINFO *)malloc(sizeof(SINFO));

        meError(sinfoNew);

        sinfoNew-cloID=cID[clo];

        sinfoNew-row=row;

        for(i=0;iTYPESIZE;i++)

            if(row=types[i][0]  row=types[i][1])

            {

                sinfoNew-type=i;

                break;

            }

        sinfoNew-sell=0;

        sinfoNew-next=NULL;

        if(sinfoHead-next==NULL)

            sinfoHead-next=sinfoNew;

        else

            sinfoTail-next=sinfoNew;

        sinfoTail=sinfoNew;

        clo++;

    }

    return sinfoHead;

}

void meError(void *p)//內存申請失敗

{

    if(p==NULL)

    {

        printf(“\n異常:內存申請失敗!回車結束程序!\n”);

        while(getch()!=’\r’);

        exit(0);

    }

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/292058.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-25 14:07
下一篇 2024-12-25 14:07

相關推薦

  • 銀行資金管理系統總結

    銀行資金管理系統是銀行日常業務運營的核心支撐系統,主要負責處理銀行的資金流動、結算、清算等業務。本文將從功能特點、技術架構、安全性以及未來發展趨勢等多個方面對銀行資金管理系統進行詳…

    編程 2025-04-29
  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • 北化教務管理系統介紹及開發代碼示例

    本文將從多個方面對北化教務管理系統進行介紹及開發代碼示例,幫助開發者更好地理解和應用該系統。 一、項目介紹 北化教務管理系統是一款針對高校學生和教職工的綜合信息管理系統。系統實現的…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28

發表回復

登錄後才能評論