C语言编程---火车订票系统源代码(小编整理)

时间:2019-05-14 03:58:50下载本文作者:会员上传
简介:写写帮文库小编为你整理了多篇相关的《C语言编程---火车订票系统源代码》,但愿对你工作学习有帮助,当然你在写写帮文库还可以找到更多《C语言编程---火车订票系统源代码》。

第一篇:C语言编程---火车订票系统源代码

火车订票系统源码

#include #include #include #include

intshoudsave=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;/*票价*/ intbookNum;/*票数*/ };/*订票人的信息*/ struct man { charnum[10];/*ID*/

char name[10];/*姓名*/ intbookNum;/*需求的票数*/ };/*定义火车信息链表的结点结构*/ typedefstruct node { struct train data;struct node * next;}Node,*Link;/*定义订票人链表的结点结构*/ typedefstruct people { struct man data;struct people*next;}bookMan,*bookManLink;/* 初始界面*/ voidprintInterface(){ 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(“********************************************************”);} /*添加一个火车信息*/ voidInsertTraininfo(Link linkhead){ struct node *p,*r,*s;charnum[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;

} } /*打印火车票信息*/ voidprintTrainInfo(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,charfindmess[],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;}

/*查询火车信息*/ voidQueryTrain(Link l){

Node *p;intsel;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!”);

}

} }

/*订票子模块*/ voidBookTicket(Link l,bookManLink k){

Node*r[10],*p;charch,dem;bookMan*v,*h;int i=0,t=0;charstr[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

{ 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(bookManLinkk,charfindmess[]){ bookMan*r;

r=k->next;while(r)

{ if(strcmp(r->data.num,findmess)==0)

{ mark=1;return r;

}

r=r->next;

} return 0;} /*修改火车信息*/ voidUpdateInfo(Link l){

Node*p;charfindmess[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;

} } /*系统给用户的提示信息*/ voidAdvicedTrains(Link l){

Node*r;charstr[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(“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”);} /*保存火车信息*/ voidSaveTrainInfo(Link l){

FILE*fp;

Node*p;int count=0,flag=1;fp=fopen(“c: rain.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);} /*保存订票人的信息*/ voidSaveBookmanInfo(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;intsel;

l=(Node*)malloc(sizeof(Node));l->next=NULL;

r=l;

k=(bookMan*)malloc(sizeof(bookMan));k->next=NULL;

h=k;

fp1=fopen(“c: rain.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语言课程设计——飞机订票系统源代码

#include //标准输入、输出头文件 #include //包含字符串函数处理头文件 #include

//包含access函数的头文件 #define N 9999

//定义最多的航班数

#define PRINT “%dtt%stt%stt星期%stt%dn ”,s[i].num,s[i].start,s[i].over,s[i].time,s[i].count

//宏定义输出格式

struct air

//定义结构体数组 { int num;

//定义航班号

char start[20];//航班起始站

char over[20];//终点站

char time[10];//飞行时间

int count;

//机票数量 }s[N];

int i,m=0;

//定义全局变量 char ii[10];

void add();//函数声明增加航班信息函数 void print();

//显示航班信息 void search();//查找航班信息 void dingpiao();//订票业务 void tuipiao();//退票 void read();//读取文件

void save();//保存文件 void output();//输出格式 void paixu();//航班排序 void chushihua();//系统初始化 void build();//建立数据文件 void paixu1();//按航班号从小到大排序 void paixu2();//从大到小

void main()//主函数 { int j;

chushihua();//系统初始化判断是否存在原始数据文件

printf(“

欢迎使用飞机订票系统n”);//打印出系统主界面

do {

printf(“================================== ”);

printf(“1.增加航班信息n”

“t2.浏览航班信息n”

“tt3.查找航班信息(按航班号)tt╮(╯_╰)╭n”

“ttt4.航班排序(按航班号)n”

“tttt5.订票业务n”

“to(︶︿︶)ottt6.退票业务n”

“tttttt0.退出n”);printf(“================================== ”);

printf(“请在0-6中选择以回车键结束: ”);scanf(“%d”,&j);switch(j){

case 1: add();//调用增加航班函数

break;

case 2:print();//调用显示模块

break;

case 3:search();//调用查找模块

break;

case 4:paixu();//调用排序函数

break;

case 5:dingpiao();//调用订票模块

break;

case 6:tuipiao();//调用退票模块

break;

case 0:

//退出系统

save();

printf(“谢谢使用,再见!”);

break;} }while(j!=0);//判断是否调用其他函数

}

void chushihua()//定义系统初始化函数 { if(access(“hangban.dat”,0)){

build();} else

read();} void build()//定义建立数据文件函数 { FILE *fp;//定义文件指针

if((fp=fopen(“hangban.dat”,“wb”))==NULL)//打开文件并判定是否出错

{

printf(“创建文件失败!”);//打印出错提示

getchar();

return;} printf(“请依次输入航班信息(以回车键结束):n”);

//打印提示信息

printf(“------------n”);for(i=0;i

printf(“请输入航班号: ”);

scanf(“%d”,&s[i].num);//输入航班号

printf(“请输入起始站: ”);

scanf(“%s”,s[i].start);//输入起始站

printf(“请输入终点站: ”);

scanf(“%s”,s[i].over);//输入终点站

printf(“请输入时间(星期几): ”);

scanf(“%s”,s[i].time);//输入时间

printf(“请输入机票数: ”);

scanf(“%d”,&s[i].count);//输入机票数

fwrite(&s[i],sizeof(struct air),1,fp);

m++;

printf(“添加完毕,是否继续添加?请键入y或n以回车键结束:”);

scanf(“%s”,ii);

if(strcmp(ii,“y”)!=0)

//判断是否继续添加航班信息

{

fclose(fp);

//关闭文件

return;

} } }

void read()

//定义读取文件函数 { FILE *fp;if((fp=fopen(“hangban.dat”,“r”))==NULL){

printf(“创建文件失败!”);

getchar();

return;} i=0;while(!feof(fp)){

fread(&s[i],sizeof(struct air),1,fp);//逐块读取数据

i++;

m++;//计算存在航班数

} m--;fclose(fp);}

void save()//定义保存函数 { FILE *fp;if((fp=fopen(“hangban.dat”,“wb”))==NULL)

{

printf(“创建文件失败!”);

getchar();

return;} for(i=0;i

//逐块保存数据

fwrite(&s[i],sizeof(struct air),1,fp);fclose(fp);}

void add()//定义增加航班信息函数 { do{

printf(“请依次输入您要增加的航班信息(以回车键结束): n”);

//打印提示信息

printf(“------------n”);

printf(“请输入航班号: ”);

scanf(“%d”,&s[m].num);//读取航班号

printf(“请输入起始站: ”);

scanf(“%s”,s[m].start);//读取起始站

printf(“请输入终点站: ”);

scanf(“%s”,s[m].over);//读取终点站

printf(“请输入时间: ”);

scanf(“%s”,s[m].time);//读取时间

printf(“请输入机票数: ”);

scanf(“%d”,&s[m].count);//读取机票数

m++;

printf(“添加完毕,是否继续添加?请键入y或n以回车键结束:”);

scanf(“%s”,ii);}while(!strcmp(ii,“y”));//判断是否继续添加 }

void output()//定义输出格式函数 { printf(“航班号tt起始站tt终点站tt时间tt机票数n”);//信息标题

for(i=0;i

printf(PRINT);//打印出信息

}

void print()//定义显示航班信息函数 { printf(“n目前我们有如下航班:n”);output();

//调用输出格式函数

printf(“n请按回车键返回上层菜单 ”);getchar();getchar();}

void search()//定义查询函数 { int n;

do {

printf(“n请输入航班号: ”);

scanf(“%d”,&n);//输入查询的航班号

for(i=0;i

{

if(s[i].num==n)//按航班号判定输出条件

{

printf(“n您所查找的航班信息为:n ”);

printf(“航班号tt起始站tt终点站tt时间tt机票数 nn”);

printf(PRINT);//显示信息

printf(“n查询完毕,按回车键继续”);

getchar();

getchar();

return;

} } printf(“n对不起,没有您需要的信息!n ”);printf(“是否重新查找?请键入y或n以回车键结束 ”);scanf(“%s”,ii);}while(!strcmp(ii,“y”));//判定是否重新查找 }

void dingpiao()//定义订票业务函数 { int n;char a[10]=“y”;do {

search();//调用查询模块

if(!strcmp(ii,“n”))

{

printf(“对不起!没有找到您所需要的航班,所以不能订票。n”);//未查找到所需航班

printf(“n请按回车键返回上层菜单 ”);

getchar();

getchar();

strcpy(ii,“n”);

break;

}

do

{

printf(“请输入您要订的机票数(以回车键结束): ”);

scanf(“%d”,&n);//输入所订机票数

if(n<=0)

//判定机票数是否出错

{

printf(“输入错误!至少需订1张机票。n”);

}

else if(s[i].count==0)//判定机票是否售完

{

printf(“对不起,你所选择的航班的机票已售完!n”);

break;

}

else if(s[i].count!=0&&s[i].count>=n)//判定机票数是否大于等于订票数

{

s[i].count=s[i].count-n;

printf(“订票成功!”);

break;

}

else if(s[i].count

{

printf(“对不起,你所选择的航班只剩 %d张机票n”, s[i].count);

printf(“是否需要重新输入机票数?请输入y或n以回车键结束: ”);//判定是否重新输入订票数

scanf(“%s”,a);

}

}while(!strcmp(a,“y”));

printf(“是否需要订其他航班的机票?请输入y或n以回车键结束: ”);

scanf(“%s”,a);}while(!strcmp(a,“y”));//判定是否继续订票 }

void tuipiao()//定义退票函数 { int n;char a[10];do {

search();//调用查询函数

if(!strcmp(ii,“n”))

{

printf(“对不起!没有找到您所需要的航班,所以不能退票。n”);

printf(“n请按回车键返回上层菜单 ”);

getchar();

getchar();

strcpy(ii,“n”);

break;

}

printf(“请输入您要退的机票数目: ”);

scanf(“%d”,&n);//输入所退票数

if(n<=0)

//判定票数是否有效

printf(“输入错误!至少需退1张机票。”);

else

{

s[i].count=s[i].count+n;

printf(“退票成功!”);

}

printf(“是否继续? 请键入y或n以回车键结束: ”);//判定是否继续退票

scanf(“%s”,a);}while(!strcmp(a,“y”));//判定并跳出循环

}

void paixu()//定义排序函数 { int n;

printf(“n******************************************************************************** ”);

printf(“1.按航班号从小到大排序n”

“t2.按航班号从大到小排序n”);printf(“******************************************************************************** ”);

printf(“请在1-2中选择以回车键结束: ”);scanf(“%d”,&n);//输入排序方式

switch(n){

case 1:paixu1();//调用从小到大排序函数

break;

case 2:paixu2();//调用从大到小排序函数

break;} printf(“排序后的航班信息为:n”);output();

//显示排序后航班信息

printf(“n请按回车键返回上层菜单 ”);

getchar();

getchar();}

void paixu1()//定义从小到大排序函数 { int k,j;struct air t;for(i=0;i

{

k=i;

for(j=i+1;j

if(s[k].num>s[j].num)

k=j;

if(i!=k)

{

t=s[k];

s[k]=s[i];

s[i]=t;

} } }

void paixu2()//定义从大到小排序函数 {

} int k,j;struct air t;for(i=0;i

if(s[k].num

k=j;if(i!=k){

t=s[k];

s[k]=s[i];

s[i]=t;} }

第三篇:C语言机票订票管理系统源代码

#include //标准输入、输出头文件 #include //包含字符串函数处理头文件 #include

//包含access函数的头文件 #include #include #include #include #define N 9999

//定义最多的航班数 #define PRINT “%dtt%stt%stt星”,s[i].num,s[i].start,s[i].over,s[i].time,s[i].count

//宏定义输出格式

struct air

{ int num;

char start[20];char over[20];char time[10];int count;

}s[N];

int i,a,m=0;char ii[10];//定义结构体数组

//定义航班号 //航班起始站

//终点站

//飞行时间

//机票数量

期%stt%dn //定义全局变量

void add();//函数声明增加航班信息函数

void print();

//显示航班信息 void search();//查找航班信息 void dingpiao();//订票业务 void tuipiao();//退票 void read();//读取文件

void save();//保存文件 void output();//输出格式 void paixu();//航班排序 void chushihua();//系统初始化 void build();//建立数据文件 void paixu1();//按航班号从小到大排序 void paixu2();//从大到小 int head();//进入订票系统

int main()//主函数 { int j;

system(“color b0”);chushihua();//系统初始化判断是否存在原始数据文件

system(“cls”);

head();//打印出系统主界面

system(“cls”);do {

printf(“================================== ”);

printf(“1.增加航班信息n”

“t2.浏览航班信息n”

“tt3.查找航班信息(按航班号)ttn”

“ttt4.航班排序(按航班号)n”

“tttt5.订票业务n”

“ttttt6.退票业务n”

“tttttt0.退出n”);printf(“================================== ”);

printf(“请在0-6中选择以回车键结束: ”);scanf(“%d”,&j);switch(j){

}

case 1: add();system(“cls”);

break;

//调用增加航班函数

case 2:print();system(“cls”);//调用显示模块

break;case 3:search();system(“cls”);//调用查找模块

break;case 4:paixu();system(“cls”);//调用排序函数

break;case 5:dingpiao();system(“cls”);break;

//调用订票模块

case 6:tuipiao();system(“cls”);//调用退票模块

break;

case 0:

//退出系统

save();system(“cls”);

printf(“nnnttttnnt谢谢使用,再见!”);

printf(“nnnnnnnnnnnnn”);

break;} }while(j!=0);//判断是否调用其他函数

void chushihua()//定义系统初始化函数 { if(access(“hangban.dat”,0)){

build();} else

read();}

void build(){

//定义建立数据文件函数

FILE *fp;//定义文件指针

if((fp=fopen(“hangban.dat”,“wb”))==NULL){

//打开文件并判定是否出错

printf(“创建文件失败!”);//打印出错提示

getchar();return;} printf(“请依次输入航班信息(以回车键结束):n”);

//打印提示信息 printf(“------------n”);for(i=0;i

printf(“请输入航班号: ”);

scanf(“%d”,&s[i].num);//输入航班号 printf(“请输入起始站: ”);scanf(“%s”,s[i].start);//输入起始站 printf(“请输入终点站: ”);scanf(“%s”,s[i].over);//输入终点站 printf(“请输入时间(星期几): ”);scanf(“%s”,s[i].time);//输入时间 printf(“请输入机票数: ”);scanf(“%d”,&s[i].count);//输入机票数 fwrite(&s[i],sizeof(struct air),1,fp);m++;printf(“添加完毕,是否继续添加?请键入y或n以回车键结束:”);scanf(“%s”,ii);if(strcmp(ii,“y”)!=0)//判断是否继续添加航班信息 { fclose(fp);

//关闭文件

return;} } }

void read()

//定义读取文件函数 { FILE *fp;if((fp=fopen(“hangban.dat”,“r”))==NULL){

} printf(“创建文件失败!”);getchar();return;} i=0;while(!feof(fp)){ fread(&s[i],sizeof(struct air),1,fp);

i++;m++;//计算存在航班数 } m--;fclose(fp);printf(“请稍候,正在初始化”);for(a=0;a<3;a++){

printf(“.”);

Sleep(600);} printf(“n”);

//逐块读取数据

void save()//定义保存函数 { FILE *fp;if((fp=fopen(“hangban.dat”,“wb”))==NULL)

{

printf(“创建文件失败!”);getchar();return;} for(i=0;i

//逐块保存数据

fwrite(&s[i],sizeof(struct air),1,fp);fclose(fp);printf(“正在保存数据并退出”);for(a=0;a<3;a++)

} {

printf(“.”);

Sleep(600);} printf(“n”);printf(“n”);void add(){ do{

//定义增加航班信息函数

printf(“请依次输入您要增加的航班信息(以回车键结束): n”);

//打印提示信printf(“------------n”);

printf(“请输入航班号: ”);

scanf(“%d”,&s[m].num);//读取航班号 printf(“请输入起始站: ”);scanf(“%s”,s[m].start);//读取起始站 printf(“请输入终点站: ”);scanf(“%s”,s[m].over);//读取终点站 printf(“请输入时间(星期几): ”);scanf(“%s”,s[m].time);//读取时间 printf(“请输入机票数: ”);scanf(“%d”,&s[m].count);//读取机票数 m++;

printf(“添加完毕,是否继续添加?请键入y或n以回车键结束:”);

scanf(“%s”,ii);}while(!strcmp(ii,“y”));//判断是否继续添加

printf(“正在保存,请稍候”);for(a=0;a<5;a++)

{

printf(“.”);

Sleep(600);

}

printf(“n”);}

void output()//定义输出格式函数 {

printf(“航班号tt起始站tt终点站tt时间tt机票数n”);//信息标题

for(i=0;i

} printf(PRINT);//打印出信息

void print()//定义显示航班信息函数 { printf(“正在加载,请稍候”);

for(a=0;a<5;a++)

{

printf(“.”);

Sleep(400);

}

printf(“n”);

system(“cls”);printf(“n目前我们有如下航班:nn”);output();

//调用输出格式函数

printf(“n请按回车键返回上层菜单 ”);getchar();getchar();}

void search()//定义查询函数 { int n;

do {

printf(“n请输入航班号: ”);

scanf(“%d”,&n);//输入查询的航班号

printf(“正在查询”);

for(a=0;a<5;a++)

{

printf(“.”);

Sleep(400);

}

printf(“n”);

for(i=0;i

{

if(s[i].num==n)//按航班号判定输出条件

{

printf(“n您所查找的航班信息为:n ”);

printf(“航班号tt起始站tt终点站tt时间tt机票数 nn”);

printf(PRINT);//显示信息

printf(“n查询完毕,按回车键继续”);

getchar();

getchar();

return;

} } printf(“n对不起,没有您需要的信息!n ”);printf(“是否重新查找?请键入y或n以回车键结束 ”);scanf(“%s”,ii);}while(!strcmp(ii,“y”));//判定是否重新查找

}

void dingpiao()//定义订票业务函数 { int n,x;char a[10]=“y”;do {

search();//调用查询模块

if(!strcmp(ii,“n”))

{

printf(“对不起!没有找到您所需要的航班,所以不能订票。n”);所需航班

printf(“n请按回车键返回上层菜单 ”);

getchar();

getchar();

strcpy(ii,“n”);

break;

}

do

{

printf(“请输入您要订的机票数(以回车键结束): ”);

scanf(“%d”,&n);//输入所订机票数

printf(“请稍候,正在订票”);

for(x=0;x<3;x++)

{

printf(“.”);

Sleep(600);

}

printf(“n”);

if(n<=0)

//判定机票数是否出错

//未查找到

{ printf(“输入错误!至少需订1张机票。n”);} else if(s[i].count==0)//判定机票是否售完 {

} printf(“对不起,你所选择的航班的机票已售完!n”);break;else if(s[i].count!=0&&s[i].count>=n)//判定机票数是否大于等于订票数 { s[i].count=s[i].count-n;printf(“订票成功!”);break;} else if(s[i].count

printf(“对不起,你所选择的航班只剩 %d张机票n”, s[i].count);

printf(“是否需要重新输入机票数?n请输入y或n以回车键结束: ”);//判定是否重新输入订票数

scanf(“%s”,a);

}

printf(“请稍候,正在订票”);

for(x=0;x<3;x++)

{

printf(“.”);

Sleep(600);

}

printf(“n”);

} }while(!strcmp(a,“y”));printf(“是否需要订其他航班的机票?n请输入y或n以回车键结束: ”);scanf(“%s”,a);}while(!strcmp(a,“y”));//判定是否继续订票

void tuipiao()//定义退票函数 { int n,x;char a[10];do {

search();//调用查询函数

if(!strcmp(ii,“n”))

{

printf(“对不起!没有找到您所需要的航班,所以不能退票。n”);printf(“n请按回车键返回上层菜单 ”);getchar();getchar();strcpy(ii,“n”);break;} printf(“请输入您要退的机票数目: ”);scanf(“%d”,&n);

//输入所退票数 printf(“请稍候,正在退票”);for(x=0;x<3;x++){

printf(“.”);

Sleep(600);} printf(“n”);if(n<=0)

//判定票数是否有效

printf(“输入错误!至少需退1张机票。”);else { s[i].count=s[i].count+n;printf(“退票成功!”);}

printf(“是否继续? 请键入y或n以回车键结束: ”);scanf(“%s”,a);

//判定是否继续退票

}while(!strcmp(a,“y”));//判定并跳出循环

}

void paixu()//定义排序函数 { int n;

printf(“n******************************************************************************** ”);

printf(“1.按航班号从小到大排序n”

“t2.按航班号从大到小排序n”);printf(“******************************************************************************** ”);

printf(“请在1-2中选择以回车键结束: ”);scanf(“%d”,&n);//输入排序方式

switch(n){

case 1:paixu1();//调用从小到大排序函数

break;

case 2:paixu2();//调用从大到小排序函数

break;} printf(“排序后的航班信息为:n”);output();

//显示排序后航班信息

printf(“n请按回车键返回上层菜单 ”);

getchar();getchar();/*for(a=0;a<5;a++)

{

printf(“.”);

Sleep(400);

}

printf(“n”);*/ }

void paixu1()//定义从小到大排序函数 { int k,j;struct air t;for(i=0;i

{

k=i;

for(j=i+1;j

if(s[k].num>s[j].num)

k=j;

if(i!=k)

{

t=s[k];

s[k]=s[i];

s[i]=t;

} } printf(“正在排序,请稍后”);

for(a=0;a<5;a++)

{

printf(“.”);

Sleep(400);

}

printf(“n”);}

void paixu2()//定义从大到小排序函数 { int k,j;struct air t;for(i=0;i

k=i;

for(j=i+1;j

if(s[k].num

k=j;

if(i!=k)

{

t=s[k];

s[k]=s[i];

s[i]=t;

} } printf(“正在排序,请稍后”);

for(a=0;a<5;a++){

printf(“.”);

Sleep(400);} printf(“n”);}

int head()

//进入订票系统

{ printf(“===================n”);printf(“*

*n”);

printf(“*

欢迎使用机票订票管理系统

*n”);printf(“*

*n”);printf(“*

此处可以适当的加点文字

*n”);printf(“*

*n”);printf(“===================n”);printf(“请按回车键进入界面”);getchar();printf(“正在进入系统选项”);for(a=0;a<3;a++){ printf(“.”);Sleep(600);

} } printf(“n”);return 0;

第四篇:火车订票管理系统

学号11~15 选题三:火车票订票管理系统

1.基本要求:为方便管理火车票购买信息,编写一个火车票订票管理系统软件。系统记录必须包括订票人姓名、订票人身份证号、始发站、终到站、票价、席别、订票时间等。2.基本管理功能: [1] [2] 添加:增加一条订票人的记录到管理系统中。

查询:根据订票人身份证查找订票人的相关信息并显示,若找不到也要给出相应提示。[3] [4] 修改:在管理系统中修改订票人的订票记录。

保存:将所有订票信息保存在一个文件中(数据库文件或普通的文本文件)。[5] [6] [7] [8] 读取:从文件中读取已保存了数据。删除:从管理系统中删除一条记录。恢复:能恢复被删除的记录。

统计:(A)统计每天订票张数和总车票金额;(B)统计单价在100元以下、100~400元之间和400元以上的票数总张数及总金额;(C)以表格形式打印所有订票信息。

源代码:

#include #include #include #include using namespace std;

int d;//用于选择(按1继续,按2退出,按他其他报错待完善)int x=1;//用于脱出while循环

string sfz;//身份证号码,用户输入可用到

class ticket {public: string ID;string name;string Sstation;string Tstation;float price;string seat;string time;ticket *next;ticket(string I,string n,string S, string T,float p, string s,string t){ID=I;name=n;Sstation=S;Tstation=T;price=p;seat=s;time=t;} void display();};

void ticket::display(){cout<

cout<<“|”<void menu(){cout<

************欢迎使用 ************”<

**请输入选项前的编号**”<

**************************************************************”<

*

1.添加车票信息

*”<

*

2.查询车票信息

*”<

*

3.修改车票信息

*”<

*

4.删除车票信息

*”<

*

5.恢复车票信息

*”<

*

6.显示车票信息

*”<

*

7.统计车票信息

*”<

*

8.保存车票信息

*”<

*

9.读取车票信息

*”<

*

0.离开

*”<

**************************************************************”<

ticket *head=NULL,*del=NULL,*p0,*p1,*p2,*p3,*p4;//head数据链表头指针,p0,p1,p2添加函数专用,避免发生错误

int check(string b)//身份证号码作为功能基本辨别数据,应该有一个函数专门检查其是否重复,0 表示重复,1 表示不重复 {ticket *ch;ch=head;int che=1;while(ch!=NULL)

{if(ch->ID==b){che=0;ch=NULL;}

else {ch=ch->next;}

} return che;}

int check1(string b)// sbl {ticket *ch;ch=del;int che=1;while(ch!=NULL)

{if(ch->ID==b){che=0;ch=NULL;}

else {ch=ch->next;}

} return che;}

int add()//将订票数据保存在一个基础链表中 {system(“cls”);float price;string name,ID,Sstation,Tstation,seat,time;

if(head==NULL)//以下为链表为空的情况 { cout<<“=============开始输入订票信息=============”<

cout<<“请输入订票人身份证号码:”;cin>>ID;cout<<“请输入订票人姓名:”;cin>>name;cout<<“请输入始发站:”;cin>>Sstation;

cout<<“请输入终点站:”;cin>>Tstation;

cout<<“请输入票价:”;cin>>price;cout<<“请输入席别:”;cin>>seat;cout<<“请输入订票时间(年月日以“-”隔开):”;cin>>time;

head=p1=p2=new ticket(ID,name,Sstation,Tstation,price,seat,time);x=1;while(x){system(“cls”);

cout<<“按1继续输入,按2退出-》”;

cin>>d;

if(d==1)

{system(“cls”);

p1->next=NULL;

cout<<“=============开始输入订票信息=============”<

cout<<“请输入订票人身份证号码:”;

cin>>ID;

if(check(ID)==0){cout<<“身份证号码重复!”<

system(“pause”);

return 0;}

cout<<“请输入订票人姓名:”;

cin>>name;

cout<<“请输入始发站:”;

cin>>Sstation;

cout<<“请输入终点站:”;

cin>>Tstation;

cout<<“请输入票价:”;

cin>>price;

cout<<“请输入席别:”;

cin>>seat;

cout<<“请输入订票时间(年月日以“-”隔开):”;

cin>>time;

p1=new ticket(ID,name,Sstation,Tstation,price,seat,time);

p2->next=p1;

p2=p1;

}

else if(d==2)

{p1->next=NULL;

x=0;

}

else {cout<<“非法输入!”<

} //以上为链表为空的情况

else //以下为链表已有数据,往末尾添加

{p3=head;

while(p3->next!=NULL)

{p3=p3->next;}

x=1;

while(x)

{system(“cls”);

cout<<“=============开始输入订票信息=============”<

cout<<“请输入订票人身份证号码:”;

cin>>ID;

if(check(ID)==0){cout<<“身份证号码重复!”<

system(“pause”);

return 0;}

cout<<“请输入订票人姓名:”;

cin>>name;

cout<<“请输入始发站:”;

cin>>Sstation;

cout<<“请输入终点站:”;

cin>>Tstation;

cout<<“请输入票价:”;

cin>>price;

cout<<“请输入席别:”;

cin>>seat;

cout<<“请输入订票时间(年月日以“-”隔开):”;

cin>>time;

p0=new ticket(ID,name,Sstation,Tstation,price,seat,time);

p3->next=p0;

p3=p0;

system(“cls”);

cout<<“按1继续输入,按2退出-》”;

cin>>d;

if(d==1){x=1;p3->next=NULL;}

else if(d==2){p3->next=NULL;x=0;}

else

{cout<<“非法输入!”<

} } //以上为链表已有数据,往末尾添加

return 1;}

ticket *search1(string a)//查询函数1,用于输入身份证号码返回一个指针,可在其他部分被使用

{ticket *cha1;cha1=head;x=1;while(x)

{if(cha1==NULL){x=0;}

else if(cha1->ID==a){x=0;}

else {cha1=cha1->next;}

} return cha1;}

ticket *search_1(string a)//改查1后面都得改,嗯,就这样了(~ ̄▽ ̄)~ {ticket *cha1;cha1=del;x=1;while(x)

{if(cha1==NULL){x=0;}

else if(cha1->ID==a){x=0;}

else {cha1=cha1->next;}

} return cha1;}

ticket *search2(string b)//查询函数2,返回所要查询结点的前一个结点的指针,在删除部分使用

{ticket *cha2,*cha3;cha2=cha3=head;x=1;while(x)

{if(cha2->next==NULL){x=0;}

else if(cha2->ID==b){x=0;}

else {cha3=cha2;

cha2=cha2->next;}

} return cha3;}

ticket *search_2(string b)//-_-{ticket *cha2,*cha3;cha2=cha3=del;x=1;while(x)

{if(cha2->next==NULL){x=0;}

else if(cha2->ID==b){x=0;}

else {cha3=cha2;

cha2=cha2->next;}

} return cha3;}

void search()//用于用户查询功能(目前只能查询一次,然后退出,待完善){system(“cls”);cout<<“请输入身份证号码:”;cin>>sfz;p3=search1(sfz);if(p3==NULL){cout<<“无相关信息!”<

cout<<“|”<

cout<<“----------”<

p3->display();system(“pause”);} }

void display1()// {system(“cls”);ticket *dis;cout<

{dis->display();

dis=dis->next;

} while(dis!=NULL);}

void modify()//修改函数,用于修改数据(目前只可以修改单个订票信息,待完善){system(“cls”);display1();cout<<“请输入要修改信息的身份证号码:”;cin>>sfz;p3=search1(sfz);if(p3==NULL){cout<<“无相关信息!”<

while(x)

{system(“cls”);

cout<<“1.身份证号码 2.姓名 3.始发站 4.终点站 5.票价 6.席别 7.时间”<

cout<<“请输入要修改的选项前的编号:”;

cin>>d;

if(d==1){hui2: cout<<“请输入身份证号码:”;

cin>>sfz;

if(check(sfz)==0){cout<<“身份证号码重复!”<

goto hui2;}

p3->ID=sfz;

}

else if(d==2){cout<<“请输入姓名:”;cin>>p3->name;}

else if(d==3){cout<<“请输入始发站:”;cin>>p3->Sstation;}

else if(d==4){cout<<“请输入终点站:”;cin>>p3->Tstation;}

else if(d==5){cout<<“请输入票价:”;cin>>p3->price;}

else if(d==6){cout<<“请输入席别:”;cin>>p3->seat;}

else if(d==7){cout<<“请输入时间:”;cin>>p3->time;}

else {cout<<“非法输入!”<

hui1: cout<<“按1继续输入,按2退出-》”;

int d1;

cin>>d1;

if(d1==1){x=1;}

else if(d1==2){x=0;}

else {cout<<“非法输入!”<

}

} }

void Darea(ticket *c)//将删除信息储存在另一链表中 {if(del==NULL){del=c;del->next=NULL;} else {ticket *Dar;

Dar=del;

while(Dar->next!=NULL)

{Dar=Dar->next;}

Dar->next=c;

Dar=c;

Dar->next=NULL;

} }

void Delete()//删除函数将要删除的订票信息移出链表,并将所有删除信息结成另一链表,供恢复使用 {system(“cls”);display1();cout<<“请输入要删除订票信息的身份证号码:”;cin>>sfz;p3=search1(sfz);p4=search2(sfz);if(p3==NULL){cout<<“无相关信息!”<next;Darea(p3);cout<<“删除成功!”<next==NULL){p4->next=NULL;Darea(p3);cout<<“删除成功!”<next=p3->next;Darea(p3);cout<<“删除成功!”<next;} else if(p3->next==NULL){p4->next=NULL;} else {p4->next=p3->next;} }

void recover()//恢复函数,用于将已经删除的订票信息恢复 {system(“cls”);ticket *r1,*r2,*r3;if(del==NULL){cout<<“无可恢复订票信息!”<

cout<<“|”<

cout<<“----------”<

r1=del;

if(del!=0)

do

{r1->display();

r1=r1->next;

}

while(r1!=NULL);hui3: cout<<“请输入要恢复的订票信息的身份证号码:”;

cin>>sfz;

if(check1(sfz)==1){cout<<“非法输入!”<

r2=head;

while(r2->next!=NULL){r2=r2->next;}

r3=search_1(sfz);

r2->next=r3;

r3->next=NULL;

Rdel(sfz);

cout<<“成功恢复!”<

system(“pause”);

} }

void display()//显示基础链表中的所有订票信息 {system(“cls”);ticket *dis;cout<

{dis->display();

dis=dis->next;

} while(dis!=NULL);system(“pause”);}

void count()//统计部分 {system(“cls”);if(head==NULL){cout<<“无可统计信息!”<

n=0,n1=0,n2=0,n3=0;

float i,m=0,m1=0,m2=0,m3=0;

p3=head;

while(p3!=NULL)

{i=p3->price;

n=n+1;

m=m+i;

if(i<100){n1=n1+1;m1=m1+i;}

if(i>=100&&i<=400){n2=n2+1;m2=m2+i;}

if(i>400){n3=n3+1;m3=m3+i;}

p3=p3->next;

}

cout<

cout<<“|”<

cout<<“-------------------”<

cout<<“|”<

cout<<“|”<

cout<<“|”<

cout<<“|”<

system(“pause”);

} }

void save()//保存函数 {system(“cls”);string filename,filename1;ofstream file;cout<<“请输入文件名:”;cin>>filename1;filename1=filename1+“.txt”;filename=“C:Program Files(x86)Microsoft Visual StudioMyProjects火车票订票管理系统savedata”+filename1;//此处路径根据需要自行更改

/*file.open(filename.c_str(),ios::in);//功能失败部分待完善

if(!file){d=1;} else

{d=2;} file.close();if(d==1){file.open(filename.c_str(),ios::out);

p1=head;

x=1;

while(x)

{if(p1!=NULL)

{file<

ID<

name<

Sstation<

Tstation<

price<

seat<

time<

p1=p1->next;}

else {x=0;}

}

file.close();

cout<<“保存成功”<

if(d==2){ */ int i;// cout<<“文件已存在!”<

cin>>i;

if(i==1)

{file.open(filename.c_str(),ios::out);

p3=head;

x=1;

while(x)

{if(p3!=NULL)

{file<

ID<name<Sstation<Tstation<price<seat<time<

p3=p3->next;}

else {x=0;}

}

file.close();

cout<<“保存成功”<

} else if(i==2)

{file.open(filename.c_str(),ios::app);

p3=head;

x=1;

while(x)

{if(p3!=NULL)

{file<

ID<name<Sstation<Tstation<price<seat<time<

p3=p3->next;}

else {x=0;}

}

file.close();

cout<<“保存成功”<

} else {cout<<“非法输入!”;goto hui;} //} }

int load()//读取函数 {system(“cls”);int i=0,ii=0,j=0;ifstream infile;string filename,filename1;cout<<“请输入文件名:”;cin>>filename1;filename1=filename1+“.txt”;filename=“C:Program Files(x86)Microsoft Visual StudioMyProjects火车票订票管理系统savedata”+filename1;//此处路径根据需要自行更改

infile.open(filename.c_str(),ios::in);

if(!infile){cerr<<“读取失败!”<

system(“pause”);

return-1;}

string a[1000];//能力有限,不会动态大小,只能这样了(+﹏+)~ while(!infile.eof()){getline(infile,a[i],'n');

i++;} ticket *L1,*L2;float f;for(ii=0;ii

{f=atof(a[ii+4].c_str());

head=new ticket(a[ii],a[ii+1],a[ii+2],a[ii+3],f,a[ii+5],a[ii+6]);

head->next=NULL;

}

else

{L1=head;

while(L1->next!=NULL)

{L1=L1->next;}

f=atof(a[ii+4].c_str());

L2=new ticket(a[ii],a[ii+1],a[ii+2],a[ii+3],f,a[ii+5],a[ii+6]);

L1->next=L2;

L1=L2;

L1->next=NULL;

} }

infile.close();cout<<“读取成功”<

void select()//选择功能分支 {system(“cls”);menu();cin>>d;

if(d==1){add();select();}

if(d==2){search();select();}

if(d==3){modify();select();}

if(d==4){Delete();select();}

if(d==5){recover();select();}

if(d==6){display();select();}

if(d==7){count();select();}

if(d==8){save();select();}

if(d==9){load();select();} else if(d==0)

{ticket *ex1,*ex2,*ex3,*ex4;

ex1=head;

while(ex1!=NULL)

{ex2=ex1;

ex1=ex1->next;

delete ex2;

}

ex3=del;

while(ex3!=NULL)

{ex4=ex3;

ex3=ex3->next;

delete ex4;

}

cout<<“离开!”<

exit(0);} else {cout<<“错误!”<

int main(){head=NULL;select();return 0;}

//较多bug,比如,如果先恢复第一个会导致后面的数据全部丢失,时间能力有限,实在抱歉->_<-

第五篇:火车订票系统c++程序

/* 头文件 */ #include //标准输入、输出头文件

#include //包含字符串函数处理头文件

#include //包含动态存储与释放函数头文件 /* 宏定义 */ #define GESHI “ 车次 站数 起始站 终点站 开车时间 到达时间 票数n” //输出表头 #define PRINT “ %5s%10s%10s%10s%13s%13s%10dn”,s[i].code,s[i].data,s[i].lp,s[i].ap,s[i].lt,s[i].at,s[i].count //输出记录格式 #define N 1000 //最大列车组数 /* 结构定义 */ struct train //定义结构体数组 { char code[10];//车次 char data[10];//站数 char lp[20];//起始站 char ap[20];//终点站

char lt[10];//开车时间 char at[10];//到达时间 int count;//票数 }s[N];/* 全局变量 */ int i;//输入计数器 int m=0;//合计计数器 char l[20];//纠错空间 /* 函数声明 */ void INPUT();//输入车次信息 void PRINTF();//输出车次信息 void save();//保存车次信息 void read();//读取车次信息 void search();//查找车次信息 void dingpiao();//订票信息 void tuipiao();//退票信息 void WRONG();//纠错模块

///////////////////////////////////////////////////////////////////////////////////////主函数 void main(){

int j;do { system(“cls”);//清屏语句 printf(“ *************************************************************n”);printf(“ 欢迎进入火车票务管理系统 n”);printf(“ *************************************************************”);printf(“ n

请输入选项 nn”);printf(“ 1.添加列车信息 nn” “

2.查找 nn” “

3.订票 nn” “

4.退票 nn” “

5.退出 nn”);printf(“ *************************************************************nn”);printf(“请选择: ”);scanf(“%d”,&j);gets(l);

switch(j){ case 1: INPUT();//调用输入模块 break;case 2:search();//调用查找模块 break;case 3:dingpiao();//调用订票模块 break;case 4:tuipiao();//调用退票模块 break;case 5:;break;default:WRONG();break;} }while(j!=5);//判断结束

printf(“n

王志强

1241班 201210913124 n ”);printf(“n--------”);

printf(“n 正在退出,请按任意键退出”);

printf(“n--------n ”);}//主函数结束

//////////////////////////////////////////////////////////////////////////////////////////输入模块 void INPUT(){

int y;

system(“cls”);printf(“n ====================欢迎进入 录入火车时刻信息 界面====================nn”);for(i=0;i

printf(“请输入车次号: ”);scanf(“%s”,&s[i].code);//读取车次号 printf(“请输入站数: ”);scanf(“%s”,&s[i].data);//读取站数 printf(“请输入起始站: ”);scanf(“%s”,s[i].lp);//读取起始站 printf(“请输入终点站: ”);scanf(“%s”,s[i].ap);//读取终点站 printf(“请输入开车时间: ”);scanf(“%s”,s[i].lt);//读取开车时间 printf(“请输入到达时间: ”);scanf(“%s”,s[i].at);//读取到达时间 printf(“请输入车票数: ”);scanf(“%d”,&s[i].count);//读取票数 m++;

printf(“第%d个信息已经输完.按任意键继续,按 0 结束: ”,m);scanf(“%d”,&y);gets(l);if(y==0){ save();//将结构体信息存盘 PRINTF();//输出输入的列车信息

printf(“n 按任意键返回上级菜单: ”);gets(l);break;} }

} ////////////////////////////////////////////////////////////////////////保存模块程序 void save(){ FILE *fp,*fp1;//定义文件指针

if((fp=fopen(“chen.dat”,“wb”))==NULL)//打开文件并判断是否出错 { printf(“创建文件失败!nn”);//打印出错提示 getchar();return;} if((fp1=fopen(“hao.dat”,“wb”))==NULL)//打开文件并判断是否出错 { printf(“创建文件失败!nn”);//打印出错提示 getchar();return;}

for(i=0;i

printf(“向文件输入数据失败!nn”);fprintf(fp1,“%d”,m);fclose(fp);//关闭文件 fclose(fp1);//关闭文件 }

///////////////////////////////////////////////////////////////////////文件读取模块 void read(){ FILE *fp,*fp1;//定义文件指针

if((fp=fopen(“chen.dat”,“rb”))==NULL)//打开文件,并判断是否出错 { printf(“出错,请检查文件是否存在,按任意键返回住菜单”);//打印出错提示

getchar();} if((fp1=fopen(“hao.dat”,“rb”))==NULL)//打开文件并判断是否出错 { printf(“创建文件失败!nn”);//打印出错提示 getchar();return;} fscanf(fp1,“%d”,&m);fclose(fp1);//关闭文件 for(i=0;i

//////////////////////////////////////////////////////////////////////////////查询模块 void search(){ char name1[20];char name2[20];char ii[10];int nk;char no[10];do { system(“cls”);//清屏语句

printf(“nn ====================欢迎进入 查询火车时刻信息 界面====================n”);

printf(“n

++++++++++++++++++请选择查找方式++++++++++++++++++nn”);

printf(“

----1.显示所有列车信息

2.按车次查询 3.按始发站查询----n”);

printf(“

-----4.按终点站查询

5.返回主菜单----n”);

printf(“n 请选择: ”);scanf(“%d”,&nk);//读取查找方式 gets(l);if(nk==5)break;

switch(nk){ case 1:PRINTF();//调用打印模块 break;case 2: printf(“请输入车次号:n”);scanf(“%s”,&no);//车次号 break;case 3: printf(“请输入始发站名称:n”);scanf(“%s”,name1);//读取始发站 break;case 4: printf(“请输入终点站名称:n”);scanf(“%s”,name2);//终点站 break;default:

WRONG();

break;} read();//调用读取函数 for(i=0;i>是否继续查找?(y/n)<--------nntt”);scanf(“%s”,ii);}while(strcmp(ii,“y”)==0);//判断结束 } ///////////////////////////////////////////////////////////////////////////////////订票模块 void dingpiao(){ int n;char a[10];do { system(“cls”);

search();//调用查询模块

printf(“请输入您要订的车票数以回车键结束:”);scanf(“%d”,&n);//读取所订机票数 if(n<0){ system(“cls”);WRONG();//scanf(“%s”,l);//gets(l);

break;} if(s[i].count!=0&&s[i].count>=n)//判断是否出错 { s[i].count=s[i].count-n;//调用保存函数

system(“cls”);printf(“订票成功!nn”);printf(“ntt按任意键返回主菜单: ”);scanf(“%s”,l);

break;} if(s[i].count

break;} printf(“是否继续?(y/n):n”);//判断是否继续订票 scanf(“%s”,a);}while(!strcmp(a,“y”));//判断结束

} ///////////////////////////////////////////////////////////////////////////////退票模块 void tuipiao(){ int n;char a;do { search();//调用查询模块

printf(“请输入您要退的机票数目:n”);scanf(“%d”,&n);//输入所退票数

gets(l);if(n<0)//判断票数是否有效

{

WRONG();

break;} s[i].count=s[i].count+n;do

{

system(“cls”);//借鉴而来的清屏语句,好用!

printf(“nn-->退票成功<--”);printf(“nn-->继续 y,返回主菜单 n <--”);

a=getchar();

gets(l);

if(a!='y'&&a!='n')

WRONG();

}while(a!='y'&&a!='n');}while(a!='n');//判断并跳出循环 } ///////////////////////////////////////////////////////////////////////////////////////纠错模块 void WRONG(){ system(“cls”);//借鉴而来的清屏语句,好用!

printf(“nn--->!!输入错误,请按任意键返回!!<---”);gets(l);}

下载C语言编程---火车订票系统源代码(小编整理)word格式文档
下载C语言编程---火车订票系统源代码(小编整理).doc
将本文档下载到自己电脑,方便修改和收藏,请勿使用迅雷等下载。
点此处下载文档

文档为doc格式


声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:645879355@qq.com 进行举报,并提供相关证据,工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。

相关范文推荐

    火车订票系统部分 uml[推荐]

    全程一体化建模报告 ——火车订票系统 工商管理学院 信息1101 20110837 王若洲 1.火车订票系统描述..........................................................................

    火车订票管理系统主程序流程

    程序简介 此程序是采用多文件模块化形式编写;其中自定义头文件中包括了程序中所有调用的函数的声明,以及需要的所有系统头文件。 #include #include #include #include #i......

    C语言程序设计——飞机订票系统

    C语言程序设计——飞机订票系统 代码如下:” #include"stdio.h" #include"stdlib.h" #include"string.h" #defineLENsizeof (structplane) #defineMAX 10; structplane { ch......

    C语言课程设计火车票系统源代码

    #include #include #include //火车票结构体类型// typedef struct Node {int num; //编号// char name[20]; //起点和终点// char time[5]; //出发时间// int price; /......

    人事管理系统源代码

    #include #include #include #define N 100 struct member_info { char xm[7]; char xb[3]; char sr[15]; char whcd[13]; char zc[17]; char sfzh[19]; char lxdh[12];......

    c语言实现机票管理系统源代码

    /*1、用户和管理员及航班信息请以英文字母或数字输入*/ /*2、管理员账户为:boss,密码为:123。保存在txt文件中,需要修改请于程序中修改*/ /*3、部分文件读写为二进制读写,所以打......

    c语言课程设计-学籍管理系统(含源代码)

    课 程 设 计 课程设计名称: C语言程序设计 题 目:学籍管理系统 学 生 姓 名: 学生学号 : 学 院(系): 软件学院 专 业 班 级: 112021 指 导 教 师: 设计时间: 2012 年 9 月 日......

    嵌入式系统c语言编程该怎么学?

    雪中悍刀行 http://bmdqw.com/嵌入式系统c语言编程该怎么学?C语言博大精深,玩了很长时间了,一直徘徊在入门处。看了很多别人的编程经验,加上项目程序越做越大,直到这半年来突然有......