火车订票管理系统_火车订票系统

2020-02-28 其他范文 下载本文

火车订票管理系统由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“火车订票系统”。

学号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;//身份证号码,用户输入可用到

cla 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>ID;cout>name;cout>Sstation;

cout>Tstation;

cout>price;cout>seat;cout>time;

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

cout

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

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>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>sfz;p3=search1(sfz);if(p3==NULL){cout

while(x)

{system(“cls”);

cout

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>p3->name;}

else if(d==3){cout>p3->Sstation;}

else if(d==4){cout>p3->Tstation;}

else if(d==5){cout>p3->price;}

else if(d==6){cout>p3->seat;}

else if(d==7){cout>p3->time;}

else {cout

hui1: cout

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>sfz;p3=search1(sfz);p4=search2(sfz);if(p3==NULL){coutnext;Darea(p3);coutnext==NULL){p4->next=NULL;Darea(p3);coutnext=p3->next;Darea(p3);coutnext;} 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

if(i>=100&&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>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)

{fileIDnameSstationTstationpriceseattime

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)

{fileIDnameSstationTstationpriceseattime

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)

{fileIDnameSstationTstationpriceseattime

p3=p3->next;}

else {x=0;}

}

file.close();

cout

} else {cout

int load()//读取函数 {system(“cls”);int i=0,ii=0,j=0;ifstream infile;string filename,filename1;cout>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,比如,如果先恢复第一个会导致后面的数据全部丢失,时间能力有限,实在抱歉->_

《火车订票管理系统.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
火车订票管理系统
点击下载文档
相关专题 火车订票系统 管理系统 订票 火车 火车订票系统 管理系统 订票 火车
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文