首页 > 编程知识 正文

票价系统c语言,c语言票务管理系统

时间:2024-03-25 09:50:05 阅读:332823 作者:OVMU

本文目录一览:

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: %sn",p-data.num);

printf("city the train will reach: %sn",p-data.city);

printf("the time the train take off: %snthe time the train reach:

%sn",p-data.takeoffTime,p-data.receiveTime);

printf("the price of the ticket: %dn",p-data.price);

printf("the number of booked tickets:

%dn",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("nnthe number of record have %dn",i);

for(t=0;t

printTrainInfo(r[t]);

if(i==0)

printf("ntttSorry!Can't find the train for you!n");

else

{

printf("ndo you want to book it?1/0n");

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("tttcan'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("nnplease select the fourth operation to book the ticket!n");

printTrainInfo(r);

}

r=r-next ;

}

if(mar==0)

printf("ntttyou 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 %dn",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 %dn",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 toon");

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: %sn",p-data.num);

printf("city the train will reach: %sn",p-data.city);

printf("the time the train take off: %snthe time the train reach: %sn",p-data.takeoffTime,p-data.receiveTime);

printf("the price of the ticket: %dn",p-data.price);

printf("the number of booked tickets: %dn",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("nnthe number of record have %dn",i);

for(t=0;ti;t++)

printTrainInfo(r[t]);

if(i==0)

printf("ntttSorry!Can't find the train for you!n");

else

{

printf("ndo you want to book it?1/0n");

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("tttcan'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("nnplease select the fourth operation to book the ticket!n");

printTrainInfo(r);

}

r=r-next ;

}

if(mar==0)

printf("ntttyou 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 %dn",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 %dn",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 toon");

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,航班号:%sn----起飞时间:%s,抵达时间:%snn",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);

    }

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。