今日,嗨壳技术分享网小编分享求一个c语言火车订票系统代码 相关内容,内容如下。
用C语言编写火车售票系统
如果谁能用C语言能把这么题目就这样顺利的编出来的话,他已经是编程高手了,这太高级了
急寻高人~!!!!C语言的火车订票系统~~~
关于 火车订票就很复杂了。主要考虑只剩一张票,2个人都查到存在一张合适的票,然后同时购买的情况。
C语言高手请进!急求火车订票程序!!!分可追加!!!
3个月前回答的问题,跟你这个比较类似。
一机场每天有n个航班,每个班次都有一班次号(1、2、3…n),固定的发车时间,固定的路线(起始站、终点站),大致的行车时间,固定的额定载客量。如
班次 发车时间 起点站 终点站 行车时间 额定载量 已定票人数
1 8:00 郫县 广汉 2 45 30
2 6:30 郫县 成都 0.5 40 40
3 7:00 郫县 成都 0.5 40 20
4 10:00 郫县 成都 0.5 40 2
功能要求:用c设计一系统
(1)录入班次信息(信息用文件保存),可不定时地增加班次数据
(2)浏览班次信息,可显示出所有班次当前状况(如果当前系统时间超过了某班次的发车时间,则显示“此班已发出”的提示信息)。
(3)查询路线:可按班次号查询 ,可按终点站查询
(4)售票和退票功能
A:当查询出已定票人数小于额定载量且当前系统时间小于发车时间时才能售票,自动更新已售票人数
B:退票时,输入退票的班次,当本班车未发出时才能退票,自动更新已售票人数
提问者: 尉迟忧叶 – 见习魔法师 二级
最佳答案
我今天晚上给你写好.
写好了,花了好长时间写和调试,费了不少力气啊,呵呵.说实话,100分有点少哦,不然到现在肯定有会的人给你解答了.
程序如下,我运行过了,各个功能保证可以实现,你只要先用1功能录入一写信息资料,以1 8:00 郫县 广汉 2 45 30 这样的格式录入.然后再浏览查询,买票等等.因为我的编译器不支持汉字,所以调试的时候很多提示语我用英文写的,不过都是些简单的,相信你看的懂.如果有问题问我q23824056.
#includestdio.h
#includetime.h
#includestring.h
typedef struct information
{
int numb;
char starttime[10];
char begin[21];
char end[21];
float lasttime;
int canload;
int alreadyload;
}INFORMATION;
void AddInformation(void)
{
FILE *fp;
INFORMATION info;
printf(“please input the information you want to insert,input 0 to return back:
”);
scanf(“%d”, info.numb);
if(info.numb == 0) return;
scanf(“%s%s%s%f%d%d”, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
if((fp = fopen(“c:\information.txt”, “a+”)) == 0)
{
printf(“open file error!”);
exit(0);
}
fprintf(fp, “%d %s %s %s %f %d %d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
fclose(fp);
}
int GetHour(char *s)
{
char *p, *q;
p = (char *)malloc(10);
strcpy(p, s);
q = p;
while(*q != ‘:’)
{
q++;
}
*q = ‘0’;
return atoi(p);
}
int GetMinute(char *s)
{
char *p;
p = (char *)malloc(10);
strcpy(p, s);
while(*p != ‘:’)
{
p++;
}
p++;
return atoi(p);
}
void ShowInformation(void)
{
FILE *fp;
INFORMATION info;
time_t t;
struct tm *timeinfo;
if((fp = fopen(“c:\information.txt”, “r+”)) == 0)
{
printf(“open file error!”);
exit(0);
}
time(t);
timeinfo = localtime(t);
while(!feof(fp))
{
fscanf(fp, “%d%s%s%s%f%d%d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
printf(“%d %s %s %s %f %d %d “, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
if(GetHour(info.starttime) timeinfo-tm_hour) printf(“此班已发出!
”);
else if(GetHour(info.starttime) == timeinfo-tm_hour)
{
if(GetMinute(info.starttime)=timeinfo-tm_min) printf(“此班已发出!
”);
else printf(“
”);
}
else printf(“
”);
}
fclose(fp);
}
void SearchbyNum(void)
{
FILE *fp;
INFORMATION info;
int bc;
printf(“please input the number,input 0 to return back:
”);
scanf(“%d”, bc);
if(0 == bc) return;
if((fp = fopen(“c:\information.txt”, “r+”)) == 0)
{
printf(“open file error!”);
exit(0);
}
while(!feof(fp))
{
fscanf(fp, “%d%s%s%s%f%d%d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
if(info.numb == bc)
{
printf(“%d %s %s %s %f %d %d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
fclose(fp);
}
void SearchbyEnd(void)
{
FILE *fp;
INFORMATION info;
char zhongdian[100];
printf(“please input the place,input 0 to return back:
”);
scanf(“%s”, zhongdian);
if(strcmp(zhongdian, “0”) == 0) return;
if((fp = fopen(“c:\information.txt”, “r+”)) == 0)
{
printf(“open file error!”);
exit(0);
}
while(!feof(fp))
{
fscanf(fp, “%d%s%s%s%f%d%d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
if(strcmp(zhongdian, info.end) == 0)
{
printf(“%d %s %s %s %f %d %d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
fclose(fp);
}
void SearchWay(void)
{
int i;
printf(“1. search by number
”);
printf(“2. search by end
”);
printf(“0. return back
”);
printf(“which way do you want?
”);
scanf(“%d”, i);
switch(i)
{
case 1: SearchbyNum(); break;
case 2: SearchbyEnd(); break;
case 0: return;
default : break;
}
}
void Buy(void)
{
FILE *fp;
INFORMATION info;
time_t t;
struct tm *timeinfo;
int bc;
long pos, pos1;
printf(“please input the banci you want to buy,input 0 to return back:
”);
scanf(“%d”, bc);
if(0 == bc) return;
if((fp = fopen(“c:\information.txt”, “r+”)) == 0)
{
printf(“open file error!”);
exit(0);
}
time(t);
timeinfo = localtime(t);
while(1)
{
pos1 = ftell(fp);
fscanf(fp, “%d%s%s%s%f%d%d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
pos = ftell(fp) – pos1;
if(info.numb == bc)
{
if(info.alreadyload info.canload)
{
if(GetHour(info.starttime) timeinfo-tm_hour)
{
printf(“sorry, the plane has taken off!”);
}
else if(GetHour(info.starttime) == timeinfo-tm_hour)
{
if(GetMinute(info.starttime) = timeinfo-tm_min) printf(“sorry, the plane has taken off!”);
else
{
printf(“take your ticket, bye!”);
info.alreadyload ++;
fseek(fp, -pos, SEEK_CUR);
fprintf(fp, “%d %s %s %s %f %d %d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
else
{
printf(“take your ticket, bye!”);
info.alreadyload ++;
fseek(fp, -pos, SEEK_CUR);
fprintf(fp, “%d %s %s %s %f %d %d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
else printf(“sorry, the tickets are all sold out!”);
break;
}
}
fclose(fp);
}
void Cancel(void)
{
FILE *fp;
INFORMATION info;
time_t t;
struct tm *timeinfo;
int bc;
long pos, pos1;
printf(“please input the banci you want to cancel,input 0 to return back:
”);
scanf(“%d”, bc);
if(0 == bc) return;
if((fp = fopen(“c:\information.txt”, “r+”)) == 0)
{
printf(“open file error!”);
exit(0);
}
time(t);
timeinfo = localtime(t);
while(1)
{
pos1 = ftell(fp);
fscanf(fp, “%d%s%s%s%f%d%d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
pos = ftell(fp) – pos1;
if(info.numb == bc)
{
if(GetHour(info.starttime) timeinfo-tm_hour)
{
printf(“sorry, the plane has taken off!”);
}
else if(GetHour(info.starttime) == timeinfo-tm_hour)
{
if(GetMinute(info.starttime) = timeinfo-tm_min) printf(“sorry, the plane has taken off!”);
else
{
printf(“your ticket is canceled, bye!”);
info.alreadyload –;
fseek(fp, -pos, SEEK_CUR);
fprintf(fp, “%d %s %s %s %f %d %d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
}
else
{
printf(“your ticket is canceled, bye!”);
info.alreadyload –;
fseek(fp, -pos, SEEK_CUR);
fprintf(fp, “%d %s %s %s %f %d %d
”, info.numb, info.starttime, info.begin, info.end, info.lasttime, info.canload, info.alreadyload);
}
break;
}
}
fclose(fp);
}
void ForTicket(void)
{
int i;
printf(“1. I want to buy a ticket
”);
printf(“2. I want to return a ticket
”);
printf(“0. return back
”);
printf(“which do you want?”);
scanf(“%d”, i);
switch(i)
{
case 1: Buy(); break;
case 2: Cancel(); break;
case 0: return;
default : break;
}
}
int main()
{
int i;
while(1)
{
printf(“
1. 录入班次信息
”);
printf(“2. 浏览班次信息
”);
printf(“3. 查询路线
”);
printf(“4. 售票退票
”);
printf(“
Please input a number from 1 to 4 like above ,use 0 to exit!
”);
scanf(“%d”,i);
switch(i)
{
case 0: return 0;
case 1: AddInformation(); break;
case 2: ShowInformation(); break;
case 3: SearchWay(); break;
case 4: ForTicket(); break;
default :
printf(“Wrong number!
”); break;
}
}
}
回答者:sunshine66 – 高级经理 六级 6-8 08:58
用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!
”,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(“
The following is the record you want:”);
printf(“number of train: %s
”,p-data.num);
printf(“city the train will reach: %s
”,p-data.city);
printf(“the time the train take off: %s
the time the train reach: %s
”,p-data.takeoffTime,p-data.receiveTime);
printf(“the price of the ticket: %d
”,p-data.price);
printf(“the number of booked tickets: %d
”,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:
1:according to the number of train;
2:according to the city:
”);
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(“
the 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(“
the 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(“
the number of record have %d
”,i);
for(t=0;ti;t++)
printTrainInfo(r[t]);
if(i==0)
printf(“
Sorry!Can’t find the train for you!
”);
else
{
printf(“
do you want to book it?1/0
”);
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(“
Lucky!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(“
there isn’t record for you to modify!
”);
return ;
}
else
{
QueryTrain(l);
if(mark1==0)
{
printf(“
Do you want to modify it?
”);
getchar();
scanf(“%c”,ch);
if(ch==’y’);
{
printf(“
Input 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(“
modifying record is sucessful!
”);
shoudsave=1 ;
}
else
printf(” can’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(“
you can select the following train!
”);
printf(“
please select the fourth operation to book the ticket!
”);
printTrainInfo(r);
}
r=r-next ;
}
if(mar==0)
printf(“
you can’t book any ticket now!
”);
}
/*保存火车信息*/
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
”,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
”,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(“
the file have been changed!do you want to save it(y/n)?
”);
scanf(“%c”,ch1);
if(ch1==’y’||ch1==’Y’)
{
SaveBookmanInfo(k);
SaveTrainInfo(l);
}
}
printf(“
Thank you!!You are welcome too
”);
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(“
please press any key to continue…….”);
getch();
}
return 0;
}
长途汽车站订票系统 c++
C语言:软件课程设计–C语言设计火车票订票系统之源代码(模拟数据库功能)(需求分析+可行性分析)一.需求设计:1.每条线路所涉及的信息有:起点、终点、站名、车次、、票价、时间、座位号。2.作为示意系统,全部数据可以只放在内存中。3.系统能实现的功能和操作如下:①.查询路线:根据旅客提出的终点站名输入下列信息:车次、车站名。②.承订票业务:根据客户提出的要求查询该车次票额的情况,若尚有余票,则为客户订票手续,输出座位号;若已满员或余票额少于订票额,则需重新查询客户要求,若需要可登记排队候补。③.承退票业务:根据客户提供的情况(车次、时间、座位号)为客户退票手续,然后查询该车次是否有人排队候补,首先询问排在第一的客户,若所退票额能满足他的要求,则为他订票手续,否则依次询问其他排队候补的客户。④登记旅客情况:包括旅客姓名,性别,年龄,家庭住址,联系方式等。⑤统计功能:将每次车的订票,退票结果统计出来。⑥管理功能:列车管理员可以通过调用函数来查看车票极其用户情况.⑦.查询功能:用户可以查询自己需要的车辆信息这类资源挺多的,你在百度一搜“火车订票系统代码”出来很多
用C语言写一个模拟火车票管理系统。
#includestdio.h
#includestring.h
#includestdlib.h
#includetime.h
#includeconio.h
#define N 1000
typedef struct TICKET
{
char num[10];
char hour[3];
char min[3];
char from[10];
char to[10];
float hours;
int max;
int now;
}CLASS;
int class_num=0;
CLASS records[N];
int system_time();
void NewMessage();
void ShowTable1();
void ShowTable2(int i);
void Display();
void add();
void save();
void load();
void search();
void change();
void quit();
void Ticketorder();
void Ticketdelete();
int menu_select();
int whether(int);
void find(char s1[],char s2[]);
void deletemessage();
int findnum(char s1[]);
void get(int,int);
char *menu[]={“*****************欢迎使用车票管理系统*****************”,
”
*******************MENU功能菜单***********************”,
”
1. 录入班次 “,
”
2. 显示所有班次 “,
”
3. 查询班次 “,
”
4. 增加班次 “,
”
5. 售票 “,
”
6. 退票 “,
”
7. 修改班次 “,
”
8. 删除班次 “,
”
9. 退出 “};
/**主函数**/
void main()
{
system(“cls”);
while(1)
{
switch(menu_select())
{
case 1: NewMessage();break;
case 2: Display();break;
case 3: search();break;
case 4: add();break;
case 5: Ticketorder();break;
case 6: Ticketdelete();break;
case 7: change();break;
case 8: deletemessage();break;
case 9: quit();break;
}
}
}
/**菜单函数**/
int menu_select()
{
char s[5];
int c,i;
system(“cls”);
for(i=0;i11;i++)
{
printf(“%s”,menu[i])) ;
}
i=0;
printf(“
”);
printf(“******************************************************”);
printf(“
请选择(1-9):”);
scanf(“%s”,s);
c=atoi(s);
while(i0||i9)
{
printf(“
”);
printf(“******************************************************”);
printf(“
请选择(1-9):”);
scanf(“%s”,s);
c=atoi(s);
}
return c;
}
void NewMessage()
{
int i=0,j=5,h;
char s[5];
FILE *fp;
system(“cls”);
if((fp=fopen(“d:number.dat”,”rb”))!=NULL)
{
printf(“车票信息已经存在请选择增加功能!
”);
printf(“任意输入则返回菜单
”);
scanf(“%s”,s);
i=1; //通过是1
}
if(i==0)
{
system(“cls”);
printf(“请输入要录入班次总数:
”);
scanf(“%d”,class_num);
system(“cls”);
for(i=0;iclass_num;i++)
{
system(“cls”);
printf(“请输入第%d个班次信息:
”,i+1);
h=-1;
for(;h!=i;)
{
printf(“请输入班次:”);
scanf(“%s”,records[i].num);
for(h=0;hi;h++)
if(strcmp(records[h].num,records[i].num)==0)
//判断字符串比较是否相等,, 待比较的字符串
{
printf(“输入错误!该班次已存在!
”);
break;
}
}
get(i,j);
j=5;
}
save();
}
}
void Display() //显示所有函数
{
int i,j;
system(“cls”); //刷屏
load(); // 调用按班次查询函数
ShowTable1(); //线框调用1,,,不用每次输
for(i=0,j=0;iclass_num;i++,j+=2) /////按班次顺序输出
{
printf(“
|———-|———-|———-|———-|——–|——–|——–|
”);
if(whether(i))
printf(“|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|”,records[i].num,records[i].hour,
records[i].min, records[i].from,records[i].to,records[i].hours,
records[i].max,records[i].now);
else
printf(“|%10s| 已发车 |%10s|%10s|%8.1f|%8d|%8d|”,records[i].num,
records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);
}
ShowTable2(j); //线框调用2
printf(“
按任意键继续….
”);
getch(); /////从控制台读取一个字符,但不显示在屏幕上
}
/**打印表头**/
void ShowTable1()
{
int i=2;
system(“cls”);
printf(“**************************车票信息系统**********************************
”);
printf(“
|———-|———-|———-|———-|——–|——–|——–|
”);
printf(“
| 班次 | 发车时间 | 起点站 | 终点站 |行车时间|额定载量| 已售票 |
”);
}
void ShowTable2(int i)
{
printf(“
|———-|———-|———-|———-|——–|——–|——–|
”);
}
void search()
{
int i;
char s1[10]={‘0’},s2[10]={‘0’};
system(“cls”);
printf(“1. 按班次查询
”)
printf(“2. 按终点站查询
”);
printf(“3. 退出
”);
printf(“请选择(1-3):
”);
scanf(“%d”,i);
load();
switch(i)
{
case 1: printf(“请输入要查询的班次:”);
scanf(“%s”,s1);
find(s1,s2);
break;
case 2: printf(“请输入要查询终点站:”);
scanf(“%s”,s2);
find(s1,s2);
break;
case 3: break;
default : printf(“输入错误!
”);
break;
}
printf(“按任意键继续….
”);
getch();
}
void find(char s1[],char s2[])
{
int i,h=0,m;
ShowTable1();
if(s2[0]==’0′)
m=1;
else m=0;
for(i=0;iclass_num;i++)
if(strcmp(s1,records[i].num)==0||strcmp(s2,records[i].to)==0)
{
printf(“
|———-|———-|———-|———-|——–|——–|——–|
”);
printf(“|%10s|%5s:%-4s|%10s|%10s|%8.1f|%8d|%8d|”,records[i].num,records[i].hour,records[i].min,
records[i].from,records[i].to,records[i].hours,records[i].max,records[i].now);
h+=1;
if(m==1)
break;
}
ShowTable2(h);
if(h==0)
printf(“要查找的班次不存在!
”);
}
/**增加函数**/
void add()
{
int i,j=5;
load();
system(“cls”);
printf(“1. 增加班次”);
printf(“2. 返回
”);
printf(“请选择(1-2)
”);
scanf(“%d”,i);
if(i==1)
{
system(“cls”); //刷屏
printf(“1. 请输入要增加的班次:”);
scanf(“%s”,records[class_num].num);
for(i=0;iclass_num;i++)
if(strcmp(records[class_num].num,records[i].num)==0)
//判断字符串比较是否相等,待比较的字符串,判断车次没重复
{
printf(“输入错误!
”);
getch(); /////从控制台读取一个字符,但不显示在屏幕上
break;
}
if(i==class_num)
{
get(i,j); ////修改及增加班次*
class_num++; ///使班次数加1
save(); //调用保存函数
}
}
}
/**售票函数**/
void Ticketorder() //*售票函数
{
int i;
char num[10];
system(“cls”); //刷屏
printf(“1. 售票
”);
printf(“2. 返回
”);
printf(“请选择(1-2):
”);
scanf(“%d”,i);
if(i==1)
{
load(); // 加载函数
search(); //查找函数
printf(“请输入要订票的班次(若无请输入0):”);
scanf(“%s”,num);
for(i=0;iclass_num;i++)
if(strcmp(num,records[i].num)==0)//判断字符串比较是否相等,, 待比较的字符串
if(records[i].maxrecords[i].nowwhether(i)==1)
//判断时间是否超出函数并且没超出最大客量
{
records[i].now++; ///使已售票加1
printf(“通向%s班次为%s的票订票成功!
”,records[i].to,records[i].num);
save(); //调用保存函数
getch(); /////从控制台读取一个字符,但不显示在屏幕上
break;
}
else
{
printf(“该班次已满或已发出!
”);
getch(); /////从控制台读取一个字符,但不显示在屏幕上
}
}
}
/**退票函数**/
void Ticketdelete() //删除函数*
{
int i;
char num[10];
system(“cls”); //刷屏
printf(“1. 退票
”);
printf(“2. 返回
”);
printf(“请选择(1-2)
:”);
scanf(“%d”,i);
if(i==1)
{
system(“cls”); //刷屏
load(); // 调用按班次查询函数
printf(“请输入要退票的班次:
”);
scanf(“%s”,num);
i=findnum(num); //调用班次查询函数
if(strcmp(num,records[i].num)==0) //判断字符串比较是否相等 待比较的字符串
if(whether(i)) //判断时间是否超出函数***
{
printf(“确定(Y/N)?”);
scanf(“%s”,num);
if(num[0]==’y’||num[0]==’Y’)
{
records[i].now–; //使已售票减1
printf(“退票成功!
”);
save(); //调用保存函数
getch(); //从控制台读取一个字符,但不显示在屏幕上
}
}
else
{
printf(“该班车已发出,无法退票!
”);
getch(); /////从控制台读取一个字符,但不显示在屏幕上
}
if(i==class_num)
{ printf(“输入错误!
”);
getch(); /////从控制台读取一个字符,但不显示在屏幕上
}
}
}
字数超了。。。。
对于【 求一个c语言火车订票系统代码 】文章有相关疑问,还可以参考嗨壳技术分享网,其他技术类文章吧!
原创文章,作者:语言我知,如若转载,请注明出处:https://www.heikehao.com/612.html