一个简单的火车票售票管理系统_火车票订票管理系统
一个简单的火车票售票管理系统由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“火车票订票管理系统”。
一个简单的火车票售票管理系统(原创)#include #include #define MAX 100 #define N 50
typedef struct time
//时间类型 {
int x,y,z;
//分别对应年,月,日 }TIME;
typedef struct cnode
//票信息类型 {
int no;
//票号
int id;
//购票人证件号
TIME date;
//购票日期
struct cnode *next;}CNODE;
typedef struct tnode
//车次信息类型 {
char data;
//车次编号
struct tnode *lchild,*rchild;
CNODE *head;}TNODE;
void create();
//按车次建立二叉排序树
void insert(int);
//增加新的车次(二叉排序树的插入)void del();
//取消车次(二叉排序树节点删除)
void inorder(TNODE *);
//中序遍历车次二叉排序树(仅显示车次信息)void inorder_all(TNODE *);
//中序遍历车次二叉排序树(显示车次及售票信息)void preorder(TNODE *);
//先序遍历车次二叉排序树(仅显示车次信息)TNODE *search();
//按车次编号搜索
CNODE *insert_c(CNODE *);
//插入新的售票信息(单张)CNODE *insert_c_more(CNODE *);
//插入新的售票信息(批量)CNODE *del_c(CNODE *,CNODE *);
//退票处理(删除售票信息)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 *);
//输出售票纪录(批量)
TNODE *root=NULL;
void main(){
int i,func,no,ok;
TNODE *t;
CNODE *c;
TIME d;
printf(“nnn”);
for(i=0;i
printf(“列车售票信息管理系统”);
for(i=0;i
printf(“n”);
printf(“t1.车次信息管理n”);
printf(“t2.售票记录管理n”);
printf(“t3.售票记录查询n”);
printf(“t4.售票记录一览n”);
printf(“t5.退出系统n”);
for(i=0;i
printf(“n请选择您所需要的功能:”);
fflush(stdin);
scanf(“%d”,&func);
switch(func){
case 1:
printf(“nn车次信息管理>>>>n”);
for(i=0;i
printf(“nt1.增加新的车次”);
printf(“nt2.取消车次”);
printf(“nt3.返回上级菜单n”);
for(i=0;i
printf(“n请选择您所需要的功能:”);
fflush(stdin);
scanf(“%d”,&func);
switch(func){
case 1:
create();
printf(“n售票信息更新成功!nn”);
break;
case 2:del();break;
case 3:main();break;
default:printf(“n[错误]功能号输入有误!请重新输入!”);
}
break;
case 2:
printf(“nn售票记录管理>>>>n”);
for(i=0;i
printf(“nt1.增加新的售票记录”);
printf(“nt2.退票”);
printf(“nt3.返回上级菜单n”);
for(i=0;i
printf(“n请选择您所需要的功能:”);
fflush(stdin);
scanf(“%d”,&func);
switch(func){
case 1:
t=search();
if(t!=NULL)t->head=insert_c_more(t->head);
break;
case 2:
t=search();
printf(“需要退票的票号:”);
scanf(“%d”,&no);
t->head=del_c(t->head,search_c(t->head,no));
break;
case 3:main();break;
default:printf(“n[错误]功能号输入有误!请重新输入!”);
}
break;
case 3:
printf(“nn售票记录查询>>>>n”);
for(i=0;i
printf(“nt1.按票号搜索”);
printf(“nt2.按购票者证件号搜索”);
printf(“nt3.按购票日期搜索”);
printf(“nt4.返回上级菜单n”);
for(i=0;i
printf(“n请选择您所需要的功能:”);
fflush(stdin);
scanf(“%d”,&func);
switch(func){
case 1:
t=search();
if(t!=NULL){
printf(“n请输入您所要查询的票号:”);
scanf(“%d”,&no);
c=search_c(t->head,no);
if(c==NULL)printf(“[错误]没有该票号的纪录!该票还未售出或为废票!自动返回上级菜单n...”);}
break;
case 2:
printf(“n请输入您所要查询的购票者证件号:”);
scanf(“%d”,&no);
search_c_id_all(root,no);
printf(“搜索完毕!自动返回上级菜单n...”);
break;
case 3:
do{
printf(“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;
else
if(d.z0)ok=1;
}
else ok=0;
if(!ok)printf(“n[错误]日期输入有误!请重新输入!”);
}while(!ok);
printf(“n指定车次吗?(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;
case 4:
printf(“nn售票记录一览>>>>n”);
for(i=0;i
printf(“nt1.仅浏览车次”);
printf(“nt2.指定车次已售票记录”);
printf(“nt3.所有车次已售票记录”);
printf(“nt4.测试:先序遍历车次”);
printf(“nt5.返回上级菜单n”);
for(i=0;i
printf(“n请选择您所需要的功能:”);
fflush(stdin);
scanf(“%d”,&func);
switch(func){
case 1:
printf(“n+++仅浏览车次n”);
if(root==NULL)printf(“[错误]无车次纪录!”);
else{inorder(root);printf(“n”);}
break;
case 2:
printf(“n+++指定车次已售票记录n”);
t=search();
if(t!=NULL){
print_c_all(t->head);
printf(“n”);
}
break;
case 3:
printf(“n+++所有车次已售票记录n”);
if(root==NULL)printf(“[错误]无车次纪录!”);
else{inorder_all(root);printf(“n”);}
break;
case 4:
printf(“n+++测试:先序遍历车次n”);
if(root==NULL)printf(“[错误]无车次纪录!”);
else{preorder(root);printf(“n”);}
break;
case 5:main();break;
default:printf(“n[错误]功能号输入有误!自动返回上级菜单n...”);
}
break;
case 5:exit(0);
default:printf(“n[错误]功能号输入有误!请重新输入!”);
}
main();}
void 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);
} }
void inorder(TNODE *ptr){ if(ptr!=NULL)
{
inorder(ptr->lchild);
printf(“%dt”,ptr->data);
inorder(ptr->rchild);
} }
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->date.z);}
void print_c_all(CNODE *head){
int i=0,j=0;
if(head==NULL){printf(“n记录为空!n”);return;}
for(i=0;i
printf(“nNOt票号t购票者证件号t购票日期(年-月-日)n”);
for(i=0;i
for(j=0;head!=NULL;j++){
printf(“n%d”,j);
print_c(head);
head=head->next;
}
printf(“n”);
for(i=0;i
printf(“n总计 %d 条记录n”,j);
for(i=0;i
printf(“n”);} void create(){ int n,i;int k[MAX];printf(“n您所希望增加车次的数量:”);scanf(“%d”,&n);for(i=0;i
printf(“新增第%d列车次:”,i+1);
scanf(“%d”,&k[i]);} for(i=0;i
insert(k[i]);}
void insert(int m){ 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((m
data)&&(p1->lchild!=NULL))p1=p1->lchild;
else if((m>p1->data)&&(p1->rchild!=NULL))p1=p1->rchild;
else if((m
data)&&(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((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(){
int key;
TNODE *p;
p=root;
printf(“n输入您所要查找的车次编号:”);
scanf(“%d”,&key);
while(p!=NULL&&p->data!=key){
if(key
data){p=p->lchild;}
else if(key>p->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(key
data){p1=p2;p2=p2->lchild;}
else if(key>p2->data){p1=p2;p2=p1->rchild;}
}
if(p2==NULL){printf(“n[错误]该车次不存在!返回上级菜单n...”);return;}
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;}
}
else{
if(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->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;
else p3->rchild=temp->lchild;
}
}
free(temp);
printf(“车次 %d 已取消!nn”,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”);
}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,i;
printf(“n请输入批量新增售票记录数:”);
fflush(stdin);
scanf(“%d”,&n);
for(i=0;i
printf(“n售票记录更新成功!n”);
return(head);}
CNODE *search_c(CNODE *head,int id){
CNODE *temp,*s;
s=temp=head;
while(temp!=NULL&&temp->id!=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->head,id);
search_c_id_all(ptr->rchild,id);
} }
void search_date(CNODE *head,TIME t){
CNODE *s,*head_s;
s=head_s=NULL;
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”);}
void search_date_all(TNODE *ptr,TIME t){
if(ptr!=NULL){
search_date_all(ptr->lchild,t);
printf(“n车次:%dn”,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...”);
else if(p==head){head=NULL;free(p);}
else{
temp=p->next;
p->next=temp->next;
free(temp);
}
return(head);}
火车票售票系统班级:S3SN131班姓名:王宁如今科技发展突飞猛进,交通发达迅速。而我要做的是让远在千里之外的你轻松购得回家的一票。火车站市场的管理和规范问题,是困扰我们多年......
三、需求规格说明书三、需求规格说明书 1.引言 ...........................................................................................................................
关于2012年春运多渠道售票方式的通知一、车票实名制:自2012年1月8日起对旅客列车实行车票实名制,旅客须凭本人有效身份证件购买车票,并持车票及购票时所使用的乘车人本人有效身......
火车票售票系统的设计与实现目录 引言„„„„„„„„„„„„„„„„„„„„„1 第1章 绪论..„„„„„„„„„„„„„„„„„2 1.1学术背景与现实意义..„„„„„......
二.需求分析经过对程序设计题目的分析可知,整个程序的设计实现大致分为八个模块,每一个模块对应一个函数。在这些函数当中,添加车次数据函数、售票函数、查询总额函数的实现严格......
