一个简单的火车票售票管理系统.docx

上传人:b****8 文档编号:10060281 上传时间:2023-02-08 格式:DOCX 页数:10 大小:17.38KB
下载 相关 举报
一个简单的火车票售票管理系统.docx_第1页
第1页 / 共10页
一个简单的火车票售票管理系统.docx_第2页
第2页 / 共10页
一个简单的火车票售票管理系统.docx_第3页
第3页 / 共10页
一个简单的火车票售票管理系统.docx_第4页
第4页 / 共10页
一个简单的火车票售票管理系统.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

一个简单的火车票售票管理系统.docx

《一个简单的火车票售票管理系统.docx》由会员分享,可在线阅读,更多相关《一个简单的火车票售票管理系统.docx(10页珍藏版)》请在冰豆网上搜索。

一个简单的火车票售票管理系统.docx

一个简单的火车票售票管理系统

1/18

()

#include#include#defineMAX100#defineN50

typedefstructtime//时间类型{intx,y,z;//分别对应年,月,日

}TIME;

intid;//购票人证件号

TIMEdate;//购票日期

}CNODE;

typedefstructtnode//车次信息类型{chardata;//车次编号

structtnode*lchild,*rchild;CNODE*head;}TNODE;

voidcreate();//按车次建立二叉排序树

voidinsert(int);//增加新的车次(二叉排序树的插入)

voiddel();//取消车次(二叉排序树节点删除)

voidinorder(TNODE*);//中序遍历车次二叉排序树(仅显示车次信息)voidinorder_all(TNODE*);//中序遍历车次二叉排序树(显示车次及售票信息)voidpreorder(TNODE*);//先序遍历车次二叉排序树(仅显示车次信息)TNODE*search();//按车次编号搜索

CNODE*insert_c(CNODE*);//插入新的售票信息(单张)

2/18

CNODE*insert_c_more(CNODE*);//插入新的售票信息(批量)CNODE*del_c(CNODE*,CNODE*);//退票处理(删除售票信息)CNODE*search_c(CNODE*,int);//按票号查询

voidsearch_c_id(CNODE*,int);//按购票人证件号搜索(限定某车次)voidsearch_c_id_all(TNODE*,int);//按购票人证件号搜索(所有车次)voidsearch_date(CNODE*,TIME);//按购票日期搜索(限定某车次)voidsearch_date_all(TNODE*,TIME);//按购票日期搜索(所有车次)voidprint_c(CNODE*);//输出售票纪录(单张)

voidprint_c_all(CNODE*);//输出售票纪录(批量)

TNODE*root=NULL;voidmain(){inti,func,no,ok;TNODE*t;CNODE*c;TIMEd;printf(\n\n\n);

for(i=0;i<15;i++)printf(=);printf(列车售票信息管理系统);for(i=0;i<15;i++)printf(=);printf(\n);printf(\t

1.车次信息管理\n);printf(\t

2.售票记录管理\n);

3/18

printf(\t

3.售票记录查询\n);printf(\t

4.售票记录一览\n);printf(\t5.退出系统\n);

for(i=0;i

);

fflush(stdin);scanf(%d,&func);switch(func){case1:

printf(\n\n车次信息管理>>>>\n);for(i=0;i

3.返回上级菜单\n);

4/18

for(i=0;i

);

fflush(stdin);scanf(%d,&func);switch(func){case1:

create();

printf(\n售票信息更新成功!

\n\n);break;

case2:

del();break;case3:

main();break;default:

printf(\n[错误]功能号输入有误!

请重新输入!

);}break;case2:

printf(\n\n售票记录管理>>>>\n);for(i=0;i

1.增加新的售票记录);printf(\n\t2.退票);

5/18

printf(\n\t

3.返回上级菜单\n);for(i=0;i

);

fflush(stdin);scanf(%d,&func);switch(func){case1:

t=search();

if(t!

=NULL)t->head=insert_c_more(t->head);break;case2:

t=search();

printf(需要退票的票号:

);

scanf(%d,&no);

t->head=del_c(t->head,search_c(t->head,no));break;

case3:

main();break;default:

6/18

printf(\n[错误]功能号输入有误!

请重新输入!

);}break;case3:

printf(\n\n售票记录查询>>>>\n);for(i=0;i

2.按购票者证件号搜索);printf(\n\t

3.按购票日期搜索);printf(\n\t

4.返回上级菜单\n);for(i=0;i

);

fflush(stdin);scanf(%d,&func);switch(func){case1:

t=search();if(t!

=NULL){

7/18

printf(\n请输入您所要查询的票号:

);

scanf(%d,&no);c=search_c(t->head,no);

if(c==NULL)printf([错误]没有该票号的纪录!

该票还未售出或为废票!

自动返回上级菜单\n...);}

break;case2:

printf(\n请输入您所要查询的购票者证件号:

);

scanf(%d,&no);search_c_id_all(root,no);

printf(搜索完毕!

自动返回上级菜单\n...);break;case3:

do{

printf(\n请输入您所要查询的日期(格式:

yy-mm-dd):

);

scanf(%d-%d-%d,&d.x,&d.y,&d.z);if(d.y<13&&d.y>0){

8/18

if(d.y==1||d.y==3||d.y==5||d.y==7||d.y==8||d.y==10||d.y==12)if(d.z<32&&d.z>0)ok=1;

elseif(d.z==2)

if(d.z<30&&d.z>0)ok=1;else

if(d.z<31&&d.z>0)ok=1;}elseok=0;

if(!

ok)printf(\n[错误]日期输入有误!

请重新输入!

);}while(!

ok);

printf(\n指定车次吗?

(1->是,0->否):

);

scanf(%d,&ok);

if(ok)search_date(search()->head,d);elsesearch_date_all(root,d);break;

case4:

main();break;default:

printf(\n[错误]功能号输入有误!

自动返回上级菜单\n...);}break;case4:

printf(\n\n售票记录一览>>>>\n);for(i=0;i

9/18

2.指定车次已售票记录);printf(\n\t

3.所有车次已售票记录);printf(\n\t4.测试:

先序遍历车次);printf(\n\t

5.返回上级菜单\n);for(i=0;i

);

fflush(stdin);scanf(%d,&func);switch(func){case1:

printf(\n+++仅浏览车次\n);

if(root==NULL)printf([错误]无车次纪录!

);else{inorder(root);printf(\n);}break;case2:

printf(\n+++指定车次已售票记录\n);

10/18

t=search();if(t!

=NULL){print_c_all(t->head);printf(\n);}break;case3:

printf(\n+++所有车次已售票记录\n);if(root==NULL)printf([错误]无车次纪录!

);else{inorder_all(root);printf(\n);}break;case4:

printf(\n+++测试:

先序遍历车次\n);

if(root==NULL)printf([错误]无车次纪录!

);else{preorder(root);printf(\n);}break;

case5:

main();break;default:

printf(\n[错误]功能号输入有误!

自动返回上级菜单\n...);}break;case5:

exit(0);default:

printf(\n[错误]功能号输入有误!

请重新输入!

);}main();}void

11/18

inorder_all(TNODE*ptr){if(ptr!

=NULL){inorder_all(ptr->lchild);printf(%d:

\n,ptr->data);print_c_all(ptr->head);printf(\n);

inorder_all(ptr->rchild);}}

voidinorder(TNODE*ptr){if(ptr!

=NULL){inorder(ptr->lchild);printf(%d\t,ptr->data);inorder(ptr->rchild);}}

voidpreorder(TNODE*ptr){if(ptr!

=NULL){printf(%d\t,ptr->data);preorder(ptr->lchild);

preorder(ptr->rchild);}}voidprint_c(CNODE*tkt){if(tkt!

=NULL)

printf(\t%d\t%d\t%d-%d-%d\n,tkt->no,tkt->id,tkt->date.x,tkt->date.y,tkt->date.z);}voidprint_c_all(CNODE*head){

inti=0,j=0;

if(head==NULL){printf(\n记录为空!

\n);return;}for(i=0;i

printf(\nNO\t票号\t购票者证件号\t购票日期(年-月-日)\n);for(i=0;i

=NULL;j++){

12/18

printf(\n%d,j);print_c(head);

head=head->next;}printf(\n);for(i=0;i

printf(\n您所希望增加车次的数量:

);

scanf(%d,&n);for(i=0;i

printf(新增第%d列车次:

i+1);

scanf(%d,&k[i]);}for(i=0;i

insert(k[i]);}voidinsert(intm){TNODE*p1,*p2;if(root==NULL){root=(TNODE*)malloc(sizeof(TNODE));root->data=m;

root->lchild=root->rchild=NULL;root->head=NULL;}else{p1=root;

while(m!

=p1->data){if((mdata)&&(p1->lchild!

=NULL))p1=p1->lchild;elseif((m>p1->data)&&(p1->rchild!

=NULL))p1=p1->rchild;

13/18

elseif((mdata)&&(p1->lchild==NULL)){p2=(TNODE*)malloc(sizeof(TNODE));p2->data=m;

p2->lchild=p2->rchild=NULL;p2->head=NULL;p1->lchild=p2;

return;}elseif((m>p1->data)&&(p1->rchild==NULL)){p2=(TNODE*)malloc(sizeof(TNODE));p2->data=m;

p2->lchild=p2->rchild=NULL;p2->head=NULL;p1->rchild=p2;return;}}

printf(\n[错误]未能成功增加车次%d,车次号%d已存在!

m,m);}}TNODE*search(){

intkey;TNODE*p;p=root;

printf(\n输入您所要查找的车次编号:

);

scanf(%d,&key);

while(p!

=NULL&&p->data!

=key){

14/18

if(keydata){p=p->lchild;}

elseif(key>p->data){p=p->rchild;}}if(p==NULL)printf(\n该车次不存在!

);return(p);}voiddel(){

intkey;

TNODE*p1,*p2,*p3,*temp;p1=p2=root;p3=temp=NULL;

printf(\n请输入您想要取消的车次编号:

);

scanf(%d,&key);

while(p2!

=NULL&&p2->data!

=key){if(keydata){p1=p2;p2=p2->lchild;}

elseif(key>p2->data){p1=p2;p2=p1->rchild;}}if(p2==NULL){printf(\n[错误]该车次不存在!

返回上级菜单\n...);return;}

elseif(p2->lchild==NULL&&p2->rchild==NULL){if(p1->lchild==p2)p1->lchild=NULL;

if(p1->rchild==p2)p1->rchild=NULL;temp=p2;

if(root==p2){temp=root;root=NULL;}}else{if(p2->rchild==NULL){temp=p2->lchild;p2->data=temp->data;

15/18

p2->lchild=temp->lchild;

p2->rchild=temp->rchild;}elseif(p2->lchild==NULL){temp=p2->rchild;p2->data=temp->data;p2->lchild=temp->lchild;p2->rchild=temp->rchild;}else{p3=p2;

temp=p2->lchild;

while(temp->rchild!

=NULL){p3=temp;temp=temp->rchild;}p2->data=temp->data;

if(p3==p2)p3->lchild=temp->lchild;elsep3->rchild=temp->lchild;}}free(temp);

printf(车次%d已取消!

\n\n,key);}CNODE*insert_c(CNODE*head){CNODE*k,*p;

k=(CNODE*)malloc(sizeof(CNODE));do{

printf(\n车票编号:

);

scanf(%d,&k->no);p=search_c(head,k->no);

if(p!

=NULL)printf(\n[错误]该票已被购买!

请重新选择!

\n);

16/18

}while(p!

=NULL);printf(购票者证件号:

);

scanf(%d,&k->id);printf(购票日期(格式:

yy-mm-dd):

);

scanf(%d-%d-%d,&k->date.x,&k->date.y,&k->date.z);k->next=head;head=k;

return(head);}CNODE*insert_c_more(CNODE*head){intn,i;

printf(\n请输入批量新增售票记录数:

);

fflush(stdin);scanf(%d,&n);

for(i=0;i

\n);

return(head);}CNODE*search_c(CNODE*head,intid){CNODE*temp,*s;s=temp=head;

17/18

while(temp!

=NULL&&temp->id!

=id){s=temp;temp=temp->next;}print_c(temp);

if(temp!

=NULL)return(s);

elsereturnNULL;}voidsearch_c_id(CNODE*head,intid){CNODE*s,*head_s;s=head_s=NULL;

if(head==NULL)printf(无该证件号纪录!

\n);while(head!

=NULL){if(head->id==id){

s=(CNODE*)malloc(sizeof(CNODE));

s->no=head->no;s->id=head->id;s->date=head->date;

s->next=head_s;head_s=s;}head=head->next;}print_c_all(head_s);printf(\n);}voidsearch_c_id_all(TNODE*ptr,intid){

if(ptr!

=NULL){

search_c_id_all(ptr->lchild,id);printf(\n车次:

%d\n,ptr->data);search_c_id(ptr->head,id);search_c_id_all(ptr->rchild,id);}}voidsearch_date(CNODE*head,TIMEt){CNODE*s,*head_s;s=head_s=NULL;

18/18

while(head!

=NULL){if(t.x==head->date.x)if(t.y==head->date.y)

if(t.z==head->date.z){s=(CNODE*)malloc(sizeof(CNODE));s->no=head->no;s->id=head->id;s->date=head->date;

s->next=head_s;head_s=s;}head=head->next;}print_c_all(head_s);printf(\n);}voidsearch_date_all(TNODE*ptr,TIMEt){

if(ptr!

=NULL){

search_date_all(ptr->lchild,t);printf(\n车次:

%d\n,ptr->data);search_date(ptr->head,t);search_date_all(ptr->rchild,t);}}

CNODE*del_c(CNODE*head,CNODE*p){CNODE*temp;

if(p==NULL)printf([错误]该票未售出或为废票!

返回上级菜单\n...);elseif(p==head){head=NULL;free(p);}

else{

temp=p->next;p->next=temp->next;free(temp);}return(head);}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1