一个简单的火车票售票管理系统_第1页
一个简单的火车票售票管理系统_第2页
一个简单的火车票售票管理系统_第3页
一个简单的火车票售票管理系统_第4页
一个简单的火车票售票管理系统_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、()#include#include#define MAX 100#define N 50typedef struct time / 时间类型 int x,y,z;/ 分别对应年,月,日TIME;int id;/ 购票人证件号TIME date;购票日期CNODE;typedef struct tnode / 车次信息类型 char data;/ 车次编号struct tnode *lchild,*rchild;CNODE *head;TNODE;void create();/ 按车次建立二叉排序树void insert(int );/ 增加新的车次(二叉排序树的插入)void del();/

2、 取消车次(二叉排序树节点删除)void inorder(TNODE *);/ 中序遍历车次二叉排序树(仅显示车次信息)voidinorder_all(TNODE *);/中序遍历车次二叉排序树(显示车次及售票信息)voidpreorder(TNODE *);/先序遍历车次二叉排序树(仅显示车次信息) TNODE *search();/ 按车次编号搜索CNODE *insert_c(CNODE *);/插入新的售票信息(单张)/CNODE *insert_c_more(CNODE *);/插入新的售票信息(批量)/CNODE *del_c(CNODE *,CNODE *);退票处理(删除售票信

3、息)/CNODE *search_c(CNODE *,int);股票号查询void search_c_id(CNODE *,int);/股购票人证件号搜索(限定某车次)void search_c_id_all(TNODE *,int);/般购票人证件号搜索(所有车次)void search_date(CNODE *,TIME);侬购票日期搜索(限定某车次)void search_date_all(TNODE *,TIME);/按购票日期搜索(所有车次)void print_c(CNODE *);/输出售票纪录(单张)void print_c_all(CNODE *);/输出售票纪录(批量)TN

4、ODE *root=NULL;void main()int i,func,no,ok;TNODE *t;CNODE *c;TIME d;printf(nnn);for(i=0;i15;i+) printf(=);printf( 列车售票信息管理系统);for(i=0;i15;i+) printf(=);printf(n);printf(t TOC o 1-5 h z . 车次信息管理n);printf(t.售票记录管理n);printf(t.售票记录查询n);printf(t.售票记录一览n);printf(t.退出系统n);for(i=0;in);for(i=0;iN;i+) printf(

5、=);printf(nt. 增加新的车次);printf(nt.取消车次 );printf(nt.返回上级菜单n);for(i=0;in);for(i=0;iN;i+) printf(=);printf(nt. 增加新的售票记录 );printf(nt.退票 );printf(nt.返回上级菜单n);for(i=0;ihead=insert_c_more(t-head);break;t=search();printf( 需要退票的票号:);scanf(%d,&no);t-head=del_c(t-head,search_c(t-head,no);break;case 3:main();brea

6、k;default:printf(n 错误 功能号输入有误!请重新输入!);break;printf(nn 售票记录查询n);for(i=0;iN;i+) printf(=);printf(nt TOC o 1-5 h z . 按票号搜索);printf(nt.按购票者证件号搜索);printf(nt.按购票日期搜索);printf(nt.返回上级菜单n);for(i=0;ihead,no);if(c=NULL)printf(错误没有该票号的纪录!该票还未售出或为废票!自动返n.);break;printf(n 请输入您所要查询的购票者证件号:);scanf(%d,&no);search_c_

7、id_all(root,no);printf( 搜索完毕 ! 自动返回上级菜单n.);break;doprintf(n 请输入您所要查询的日期(格式:yy-mm-dd):);scanf(%d-%d-%d,&d.x,&d.y,&d.z);if(d.y0)if(d.y=1|d.y=3|d.y=5|d.y=7|d.y=8|d.y=10|d.y=12)if(d.z0) ok=1;else if(d.z=2)if(d.z0) ok=1;elseif(d.z0) ok=1;else ok=0;if(!ok) printf(n 错误 日期输入有误!请重新输入!);while(!ok);printf(n 指定

8、车次吗?(1-是,0-否):);scanf(%d,&ok);if(ok) search_date(search()-head,d);else search_date_all(root,d);break;case 4:main();break;default:printf(n 错误 功能号输入有误! 自动返回上级菜单n.);break;printf(nn 售票记录一览n);for(i=0;iN;i+) printf(=);printf(nt TOC o 1-5 h z . 仅浏览车次);printf(nt.指定车次已售票记录);printf(nt.所有车次已售票记录);printf(nt.测试:

9、先序遍历车次);printf(nt.返回上级菜单n);for(i=0;ihead);printf(n);break;printf(n+ 所有车次已售票记录 n);if(root=NULL) printf(错误无车次纪录!”);elseinorder_all(root);printf(n);break;printf(n+ 测试:先序遍历车次n);if(root=NULL) printf(错误无车次纪录!);elsepreorder(root);printf(n);break;case 5:main();break;default:printf(n 错误功能号输入有误! 自动返回上级菜单n.);b

10、reak;case 5:exit(0);default:printf(n 错误 功能号输入有误! 请重新输入 !);main();voidinorder_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);void inorder(TNODE *ptr)if(ptr!=NULL)inorder(ptr-lchild);printf(%dt,ptr-data);inorder(ptr-rch

11、ild);void preorder(TNODE *ptr)if(ptr!=NULL)printf(%dt ,ptr-data);preorder(ptr-lchild);preorder(ptr-rchild);void print_c(CNODE *tkt)if(tkt!=NULL)printf(t%dt%dt%d-%d-%dn,tkt-no,tkt-id,tkt-date.x,tkt-date.y,tkt-dat e.z);void print_c_all(CNODE *head)int i=0,j=0;if(head=NULL)printf(n 记录为空 !n);return;for(

12、i=0;iN;i+) printf(=);printf(nNOt票号t购票者证件号t购票日期 件-月-日)n);for(i=0;inext;printf(n);for(i=0;iN;i+) printf(-);printf(n 总计 %d 条记录 n,j);for(i=0;iN;i+) printf(=);printf(n);void create()int n,i;int kMAX;printf(n 您所希望增加车次的数量:);scanf(%d,&n);for(i=0;in;i+)printf( 新增第 %d 列车次 :,i+1);scanf(%d,&ki);for(i=0;idata=m;

13、root-lchild=root-rchild=NULL;root-head=NULL;else p1=root;while(m!=p1-data)if(mdata)&(p1-lchild!=NULL)p1=p1-lchild;else if(mp1-data)&(p1-rchild!=NULL)p1=p1-rchild;else if(mdata)&(p1-lchild=NULL)p2=(TNODE*)malloc(sizeof(TNODE);p2-data=m;p2-lchild=p2-rchild=NULL;p2-head=NULL;p1-lchild=p2;return;else if

14、(mp1-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()int key;TNODE *p;p=root;printf(n 输入您所要查找的车次编号:);scanf(%d,&key);while(p!=NULL&p-data!=key)if(keydata)p=p-lchild;else if(keyp

15、-data)p=p-rchild;if(p=NULL) printf(n 该车次不存在!);return(p);void del()int key;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;else if(keyp2-data)p1=p2;p2=p1-rchild;if(p2=NULL)printf(n住昔误该车 次不存在 !返回上级菜单n.);r

16、eturn;else if(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;elseif(p2-rchild=NULL)temp=p2-lchild;p2-data=temp-data;p2-lchild=temp-lchild;p2-rchild=temp-rchild;else if(p2-lchild=NULL)temp=p2-rchild;p2-data=temp-da

17、ta;p2-lchild=temp-lchild;p2-rchild=temp-rchild;elsep3=p2;temp=p2-lchild;while(temp-rchild!=NULL)p3=temp;temp=temp-rchild;p2-data=temp-data;if(p3=p2) p3-lchild=temp-lchild;else p3-rchild=temp-lchild;free(temp);printf( 车次 %d 已取消 !nn,key);CNODE *insert_c(CNODE *head) CNODE *k,*p;k=(CNODE *)malloc(sizeo

18、f(CNODE);doprintf(n 车票编号 :);scanf(%d,&k-no);p=search_c(head,k-no);if(p!=NULL) printf(n 错误 该票已被购买!请重新选择!n);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)int n

19、,i;printf(n 请输入批量新增售票记录数:);fflush(stdin);scanf(%d,&n);for(i=0;iid!=id)s=temp;temp=temp-next;print_c(temp);if(temp!=NULL) return(s);else return NULL;void search_c_id(CNODE *head,int id)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);void search_c_id_all(TNODE *ptr,int id)if(ptr!=NULL)search_c_id_all(ptr-lchild,id);printf(n 车次 :%dn,ptr-data);search_c_id(ptr-he

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论