第一篇:火車訂票系統(tǒng)c++程序
/* 頭文件 */ #include
#include
#include
char lt[10];//開(kāi)車時(shí)間 char at[10];//到達(dá)時(shí)間 int count;//票數(shù) }s[N];/* 全局變量 */ int i;//輸入計(jì)數(shù)器 int m=0;//合計(jì)計(jì)數(shù)器 char l[20];//糾錯(cuò)空間 /* 函數(shù)聲明 */ void INPUT();//輸入車次信息 void PRINTF();//輸出車次信息 void save();//保存車次信息 void read();//讀取車次信息 void search();//查找車次信息 void dingpiao();//訂票信息 void tuipiao();//退票信息 void WRONG();//糾錯(cuò)模塊
///////////////////////////////////////////////////////////////////////////////////////主函數(shù) void main(){
int j;do { system(“cls”);//清屏語(yǔ)句 printf(“ *************************************************************n”);printf(“ 歡迎進(jìn)入火車票務(wù)管理系統(tǒng) n”);printf(“ *************************************************************”);printf(“ n
請(qǐng)輸入選項(xiàng) nn”);printf(“ 1.添加列車信息 nn” “
2.查找 nn” “
3.訂票 nn” “
4.退票 nn” “
5.退出 nn”);printf(“ *************************************************************nn”);printf(“請(qǐng)選擇: ”);scanf(“%d”,&j);gets(l);
switch(j){ case 1: INPUT();//調(diào)用輸入模塊 break;case 2:search();//調(diào)用查找模塊 break;case 3:dingpiao();//調(diào)用訂票模塊 break;case 4:tuipiao();//調(diào)用退票模塊 break;case 5:;break;default:WRONG();break;} }while(j!=5);//判斷結(jié)束
printf(“n
王志強(qiáng)
1241班 201210913124 n ”);printf(“n--------”);
printf(“n 正在退出,請(qǐng)按任意鍵退出”);
printf(“n--------n ”);}//主函數(shù)結(jié)束
//////////////////////////////////////////////////////////////////////////////////////////輸入模塊 void INPUT(){
int y;
system(“cls”);printf(“n ====================歡迎進(jìn)入 錄入火車時(shí)刻信息 界面====================nn”);for(i=0;i printf(“請(qǐng)輸入車次號(hào): ”);scanf(“%s”,&s[i].code);//讀取車次號(hào) printf(“請(qǐng)輸入站數(shù): ”);scanf(“%s”,&s[i].data);//讀取站數(shù) printf(“請(qǐng)輸入起始站: ”);scanf(“%s”,s[i].lp);//讀取起始站 printf(“請(qǐng)輸入終點(diǎn)站: ”);scanf(“%s”,s[i].ap);//讀取終點(diǎn)站 printf(“請(qǐng)輸入開(kāi)車時(shí)間: ”);scanf(“%s”,s[i].lt);//讀取開(kāi)車時(shí)間 printf(“請(qǐng)輸入到達(dá)時(shí)間: ”);scanf(“%s”,s[i].at);//讀取到達(dá)時(shí)間 printf(“請(qǐng)輸入車票數(shù): ”);scanf(“%d”,&s[i].count);//讀取票數(shù) m++; printf(“第%d個(gè)信息已經(jīng)輸完.按任意鍵繼續(xù),按 0 結(jié)束: ”,m);scanf(“%d”,&y);gets(l);if(y==0){ save();//將結(jié)構(gòu)體信息存盤(pán) PRINTF();//輸出輸入的列車信息 printf(“n 按任意鍵返回上級(jí)菜單: ”);gets(l);break;} } } ////////////////////////////////////////////////////////////////////////保存模塊程序 void save(){ FILE *fp,*fp1;//定義文件指針 if((fp=fopen(“chen.dat”,“wb”))==NULL)//打開(kāi)文件并判斷是否出錯(cuò) { printf(“創(chuàng)建文件失敗!nn”);//打印出錯(cuò)提示 getchar();return;} if((fp1=fopen(“hao.dat”,“wb”))==NULL)//打開(kāi)文件并判斷是否出錯(cuò) { printf(“創(chuàng)建文件失敗!nn”);//打印出錯(cuò)提示 getchar();return;} for(i=0;i printf(“向文件輸入數(shù)據(jù)失敗!nn”);fprintf(fp1,“%d”,m);fclose(fp);//關(guān)閉文件 fclose(fp1);//關(guān)閉文件 } ///////////////////////////////////////////////////////////////////////文件讀取模塊 void read(){ FILE *fp,*fp1;//定義文件指針 if((fp=fopen(“chen.dat”,“rb”))==NULL)//打開(kāi)文件,并判斷是否出錯(cuò) { printf(“出錯(cuò),請(qǐng)檢查文件是否存在,按任意鍵返回住菜單”);//打印出錯(cuò)提示 getchar();} if((fp1=fopen(“hao.dat”,“rb”))==NULL)//打開(kāi)文件并判斷是否出錯(cuò) { printf(“創(chuàng)建文件失敗!nn”);//打印出錯(cuò)提示 getchar();return;} fscanf(fp1,“%d”,&m);fclose(fp1);//關(guān)閉文件 for(i=0;i //////////////////////////////////////////////////////////////////////////////查詢模塊 void search(){ char name1[20];char name2[20];char ii[10];int nk;char no[10];do { system(“cls”);//清屏語(yǔ)句 printf(“nn ====================歡迎進(jìn)入 查詢火車時(shí)刻信息 界面====================n”); printf(“n ++++++++++++++++++請(qǐng)選擇查找方式++++++++++++++++++nn”); printf(“ ----1.顯示所有列車信息 2.按車次查詢 3.按始發(fā)站查詢----n”); printf(“ -----4.按終點(diǎn)站查詢 5.返回主菜單----n”); printf(“n 請(qǐng)選擇: ”);scanf(“%d”,&nk);//讀取查找方式 gets(l);if(nk==5)break; switch(nk){ case 1:PRINTF();//調(diào)用打印模塊 break;case 2: printf(“請(qǐng)輸入車次號(hào):n”);scanf(“%s”,&no);//車次號(hào) break;case 3: printf(“請(qǐng)輸入始發(fā)站名稱:n”);scanf(“%s”,name1);//讀取始發(fā)站 break;case 4: printf(“請(qǐng)輸入終點(diǎn)站名稱:n”);scanf(“%s”,name2);//終點(diǎn)站 break;default: WRONG(); break;} read();//調(diào)用讀取函數(shù) for(i=0;i search();//調(diào)用查詢模塊 printf(“請(qǐng)輸入您要訂的車票數(shù)以回車鍵結(jié)束:”);scanf(“%d”,&n);//讀取所訂機(jī)票數(shù) if(n<0){ system(“cls”);WRONG();//scanf(“%s”,l);//gets(l); break;} if(s[i].count!=0&&s[i].count>=n)//判斷是否出錯(cuò) { s[i].count=s[i].count-n;//調(diào)用保存函數(shù) system(“cls”);printf(“訂票成功!nn”);printf(“ntt按任意鍵返回主菜單: ”);scanf(“%s”,l); break;} if(s[i].count break;} printf(“是否繼續(xù)?(y/n):n”);//判斷是否繼續(xù)訂票 scanf(“%s”,a);}while(!strcmp(a,“y”));//判斷結(jié)束 } ///////////////////////////////////////////////////////////////////////////////退票模塊 void tuipiao(){ int n;char a;do { search();//調(diào)用查詢模塊 printf(“請(qǐng)輸入您要退的機(jī)票數(shù)目:n”);scanf(“%d”,&n);//輸入所退票數(shù) gets(l);if(n<0)//判斷票數(shù)是否有效 { WRONG(); break;} s[i].count=s[i].count+n;do { system(“cls”);//借鑒而來(lái)的清屏語(yǔ)句,好用! printf(“nn-->退票成功<--”);printf(“nn-->繼續(xù) y,返回主菜單 n <--”); a=getchar(); gets(l); if(a!='y'&&a!='n') WRONG(); }while(a!='y'&&a!='n');}while(a!='n');//判斷并跳出循環(huán) } ///////////////////////////////////////////////////////////////////////////////////////糾錯(cuò)模塊 void WRONG(){ system(“cls”);//借鑒而來(lái)的清屏語(yǔ)句,好用! printf(“nn--->!!輸入錯(cuò)誤,請(qǐng)按任意鍵返回!!<---”);gets(l);} 學(xué)號(hào)11~15 選題三:火車票訂票管理系統(tǒng) 1.基本要求:為方便管理火車票購(gòu)買信息,編寫(xiě)一個(gè)火車票訂票管理系統(tǒng)軟件。系統(tǒng)記錄必須包括訂票人姓名、訂票人身份證號(hào)、始發(fā)站、終到站、票價(jià)、席別、訂票時(shí)間等。2.基本管理功能: [1] [2] 添加:增加一條訂票人的記錄到管理系統(tǒng)中。 查詢:根據(jù)訂票人身份證查找訂票人的相關(guān)信息并顯示,若找不到也要給出相應(yīng)提示。[3] [4] 修改:在管理系統(tǒng)中修改訂票人的訂票記錄。 保存:將所有訂票信息保存在一個(gè)文件中(數(shù)據(jù)庫(kù)文件或普通的文本文件)。[5] [6] [7] [8] 讀取:從文件中讀取已保存了數(shù)據(jù)。刪除:從管理系統(tǒng)中刪除一條記錄。恢復(fù):能恢復(fù)被刪除的記錄。 統(tǒng)計(jì):(A)統(tǒng)計(jì)每天訂票張數(shù)和總車票金額;(B)統(tǒng)計(jì)單價(jià)在100元以下、100~400元之間和400元以上的票數(shù)總張數(shù)及總金額;(C)以表格形式打印所有訂票信息。 源代碼: #include int d;//用于選擇(按1繼續(xù),按2退出,按他其他報(bào)錯(cuò)待完善)int x=1;//用于脫出while循環(huán) string sfz;//身份證號(hào)碼,用戶輸入可用到 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<<“|”< ************歡迎使用 ************”< **請(qǐng)輸入選項(xiàng)前的編號(hào)**”< **************************************************************”< * 1.添加車票信息 *”< * 2.查詢車票信息 *”< * 3.修改車票信息 *”< * 4.刪除車票信息 *”< * 5.恢復(fù)車票信息 *”< * 6.顯示車票信息 *”< * 7.統(tǒng)計(jì)車票信息 *”< * 8.保存車票信息 *”< * 9.讀取車票信息 *”< * 0.離開(kāi) *”< **************************************************************”< ticket *head=NULL,*del=NULL,*p0,*p1,*p2,*p3,*p4;//head數(shù)據(jù)鏈表頭指針,p0,p1,p2添加函數(shù)專用,避免發(fā)生錯(cuò)誤 int check(string b)//身份證號(hào)碼作為功能基本辨別數(shù)據(jù),應(yīng)該有一個(gè)函數(shù)專門(mén)檢查其是否重復(fù),0 表示重復(fù),1 表示不重復(fù) {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()//將訂票數(shù)據(jù)保存在一個(gè)基礎(chǔ)鏈表中 {system(“cls”);float price;string name,ID,Sstation,Tstation,seat,time; if(head==NULL)//以下為鏈表為空的情況 { cout<<“=============開(kāi)始輸入訂票信息=============”< cout<<“請(qǐng)輸入訂票人身份證號(hào)碼:”;cin>>ID;cout<<“請(qǐng)輸入訂票人姓名:”;cin>>name;cout<<“請(qǐng)輸入始發(fā)站:”;cin>>Sstation; cout<<“請(qǐng)輸入終點(diǎn)站:”;cin>>Tstation; cout<<“請(qǐng)輸入票價(jià):”;cin>>price;cout<<“請(qǐng)輸入席別:”;cin>>seat;cout<<“請(qǐng)輸入訂票時(shí)間(年月日以“-”隔開(kāi)):”;cin>>time; head=p1=p2=new ticket(ID,name,Sstation,Tstation,price,seat,time);x=1;while(x){system(“cls”); cout<<“按1繼續(xù)輸入,按2退出-》”; cin>>d; if(d==1) {system(“cls”); p1->next=NULL; cout<<“=============開(kāi)始輸入訂票信息=============”< cout<<“請(qǐng)輸入訂票人身份證號(hào)碼:”; cin>>ID; if(check(ID)==0){cout<<“身份證號(hào)碼重復(fù)!”< system(“pause”); return 0;} cout<<“請(qǐng)輸入訂票人姓名:”; cin>>name; cout<<“請(qǐng)輸入始發(fā)站:”; cin>>Sstation; cout<<“請(qǐng)輸入終點(diǎn)站:”; cin>>Tstation; cout<<“請(qǐng)輸入票價(jià):”; cin>>price; cout<<“請(qǐng)輸入席別:”; cin>>seat; cout<<“請(qǐng)輸入訂票時(shí)間(年月日以“-”隔開(kāi)):”; 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 //以下為鏈表已有數(shù)據(jù),往末尾添加 {p3=head; while(p3->next!=NULL) {p3=p3->next;} x=1; while(x) {system(“cls”); cout<<“=============開(kāi)始輸入訂票信息=============”< cout<<“請(qǐng)輸入訂票人身份證號(hào)碼:”; cin>>ID; if(check(ID)==0){cout<<“身份證號(hào)碼重復(fù)!”< system(“pause”); return 0;} cout<<“請(qǐng)輸入訂票人姓名:”; cin>>name; cout<<“請(qǐng)輸入始發(fā)站:”; cin>>Sstation; cout<<“請(qǐng)輸入終點(diǎn)站:”; cin>>Tstation; cout<<“請(qǐng)輸入票價(jià):”; cin>>price; cout<<“請(qǐng)輸入席別:”; cin>>seat; cout<<“請(qǐng)輸入訂票時(shí)間(年月日以“-”隔開(kāi)):”; cin>>time; p0=new ticket(ID,name,Sstation,Tstation,price,seat,time); p3->next=p0; p3=p0; system(“cls”); cout<<“按1繼續(xù)輸入,按2退出-》”; cin>>d; if(d==1){x=1;p3->next=NULL;} else if(d==2){p3->next=NULL;x=0;} else {cout<<“非法輸入!”< } } //以上為鏈表已有數(shù)據(jù),往末尾添加 return 1;} ticket *search1(string a)//查詢函數(shù)1,用于輸入身份證號(hào)碼返回一個(gè)指針,可在其他部分被使用 {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)//查詢函數(shù)2,返回所要查詢結(jié)點(diǎn)的前一個(gè)結(jié)點(diǎn)的指針,在刪除部分使用 {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<<“請(qǐng)輸入身份證號(hào)碼:”;cin>>sfz;p3=search1(sfz);if(p3==NULL){cout<<“無(wú)相關(guān)信息!”< cout<<“|”< cout<<“----------”< p3->display();system(“pause”);} } void display1()// {system(“cls”);ticket *dis;cout< {dis->display(); dis=dis->next; } while(dis!=NULL);} void modify()//修改函數(shù),用于修改數(shù)據(jù)(目前只可以修改單個(gè)訂票信息,待完善){system(“cls”);display1();cout<<“請(qǐng)輸入要修改信息的身份證號(hào)碼:”;cin>>sfz;p3=search1(sfz);if(p3==NULL){cout<<“無(wú)相關(guān)信息!”< while(x) {system(“cls”); cout<<“1.身份證號(hào)碼 2.姓名 3.始發(fā)站 4.終點(diǎn)站 5.票價(jià) 6.席別 7.時(shí)間”< cout<<“請(qǐng)輸入要修改的選項(xiàng)前的編號(hào):”; cin>>d; if(d==1){hui2: cout<<“請(qǐng)輸入身份證號(hào)碼:”; cin>>sfz; if(check(sfz)==0){cout<<“身份證號(hào)碼重復(fù)!”< goto hui2;} p3->ID=sfz; } else if(d==2){cout<<“請(qǐng)輸入姓名:”;cin>>p3->name;} else if(d==3){cout<<“請(qǐng)輸入始發(fā)站:”;cin>>p3->Sstation;} else if(d==4){cout<<“請(qǐng)輸入終點(diǎn)站:”;cin>>p3->Tstation;} else if(d==5){cout<<“請(qǐng)輸入票價(jià):”;cin>>p3->price;} else if(d==6){cout<<“請(qǐng)輸入席別:”;cin>>p3->seat;} else if(d==7){cout<<“請(qǐng)輸入時(shí)間:”;cin>>p3->time;} else {cout<<“非法輸入!”< hui1: cout<<“按1繼續(xù)輸入,按2退出-》”; int d1; cin>>d1; if(d1==1){x=1;} else if(d1==2){x=0;} else {cout<<“非法輸入!”< } } } void Darea(ticket *c)//將刪除信息儲(chǔ)存在另一鏈表中 {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()//刪除函數(shù)將要?jiǎng)h除的訂票信息移出鏈表,并將所有刪除信息結(jié)成另一鏈表,供恢復(fù)使用 {system(“cls”);display1();cout<<“請(qǐng)輸入要?jiǎng)h除訂票信息的身份證號(hào)碼:”;cin>>sfz;p3=search1(sfz);p4=search2(sfz);if(p3==NULL){cout<<“無(wú)相關(guān)信息!”< void recover()//恢復(fù)函數(shù),用于將已經(jīng)刪除的訂票信息恢復(fù) {system(“cls”);ticket *r1,*r2,*r3;if(del==NULL){cout<<“無(wú)可恢復(fù)訂票信息!”< cout<<“|”< cout<<“----------”< r1=del; if(del!=0) do {r1->display(); r1=r1->next; } while(r1!=NULL);hui3: cout<<“請(qǐng)輸入要恢復(fù)的訂票信息的身份證號(hào)碼:”; 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<<“成功恢復(fù)!”< system(“pause”); } } void display()//顯示基礎(chǔ)鏈表中的所有訂票信息 {system(“cls”);ticket *dis;cout< {dis->display(); dis=dis->next; } while(dis!=NULL);system(“pause”);} void count()//統(tǒng)計(jì)部分 {system(“cls”);if(head==NULL){cout<<“無(wú)可統(tǒng)計(jì)信息!”< 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()//保存函數(shù) {system(“cls”);string filename,filename1;ofstream file;cout<<“請(qǐng)輸入文件名:”;cin>>filename1;filename1=filename1+“.txt”;filename=“C:Program Files(x86)Microsoft Visual StudioMyProjects火車票訂票管理系統(tǒng)savedata”+filename1;//此處路徑根據(jù)需要自行更改 /*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< 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< p3=p3->next;} else {x=0;} } file.close(); cout<<“保存成功”< } else {cout<<“非法輸入!”;goto hui;} //} } int load()//讀取函數(shù) {system(“cls”);int i=0,ii=0,j=0;ifstream infile;string filename,filename1;cout<<“請(qǐng)輸入文件名:”;cin>>filename1;filename1=filename1+“.txt”;filename=“C:Program Files(x86)Microsoft Visual StudioMyProjects火車票訂票管理系統(tǒng)savedata”+filename1;//此處路徑根據(jù)需要自行更改 infile.open(filename.c_str(),ios::in); if(!infile){cerr<<“讀取失敗!”< system(“pause”); return-1;} string a[1000];//能力有限,不會(huì)動(dòng)態(tài)大小,只能這樣了(+﹏+)~ 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<<“離開(kāi)!”< exit(0);} else {cout<<“錯(cuò)誤!”< int main(){head=NULL;select();return 0;} //較多bug,比如,如果先恢復(fù)第一個(gè)會(huì)導(dǎo)致后面的數(shù)據(jù)全部丟失,時(shí)間能力有限,實(shí)在抱歉->_<- 全程一體化建模報(bào)告 ——火車訂票系統(tǒng) 工商管理學(xué)院 信息1101 20110837 王若洲 1.火車訂票系統(tǒng)描述....................................................................3 2.用例圖和用例說(shuō)明....................................................................3 3.類圖 ........................................................................................11 4.對(duì)象圖......................................................................................13 5.順序圖和協(xié)作圖.....................................................................14 6.狀態(tài)圖....................................................................................28 7.組件圖.....................................................................................29 8.部署圖.....................................................................................30 9.總結(jié)............................................................................................301.火車訂票系統(tǒng)描述 線上預(yù)訂火車票系統(tǒng)是一款功能強(qiáng)大、操作簡(jiǎn)便、易維護(hù)的、具有良好人機(jī)交互界面的線上訂票系統(tǒng),用戶可以在注冊(cè)之后進(jìn)入系統(tǒng)。購(gòu)票用戶可以在系統(tǒng)中查詢車票信息,并進(jìn)行車票預(yù)定。同時(shí)購(gòu)票用戶的個(gè)人信息可以修改,已預(yù)定的車票也可以在取消訂單的窗口中取消,很方便用戶的使用。 對(duì)于管理員來(lái)說(shuō),可以對(duì)用戶的信息進(jìn)行統(tǒng)一的管理,具有實(shí)時(shí)性、便捷性等有點(diǎn)。同時(shí),系統(tǒng)的數(shù)據(jù)可以定期備份,以防止信息的丟失。 2.用例圖和用例描述 2.1 用例描述 用例編號(hào):001 用例名:注冊(cè)帳號(hào) 用例描述:購(gòu)票用戶在注冊(cè)帳號(hào)后成為該系統(tǒng)的用戶,使用該系統(tǒng)的功能 參與者:購(gòu)票用戶 前置條件:電子商城正常運(yùn)行 后置條件:如果用戶輸入的帳號(hào)在系統(tǒng)中未被注冊(cè)過(guò),該用戶會(huì)注冊(cè)成功;否則,顯示帳號(hào)已注冊(cè),提示用戶重新輸入。基本路徑: 1.用戶登錄火車訂票系統(tǒng) 2.購(gòu)票用戶輸入要注冊(cè)的帳號(hào)和密碼 3.購(gòu)票用戶提交信息 4.系統(tǒng)檢查用戶帳號(hào)是否已被注冊(cè) 5.系統(tǒng)添加帳號(hào),并顯示注冊(cè)成功 擴(kuò)展點(diǎn): 4a:系統(tǒng)檢測(cè)到帳號(hào)已被注冊(cè) 4a1.用戶重新輸入 4a2.用戶離開(kāi)系統(tǒng) 變異點(diǎn):無(wú) 用例編號(hào):002 用例名:登錄帳號(hào) 用例描述:購(gòu)票用戶在登錄帳號(hào)后進(jìn)入系統(tǒng),使用該系統(tǒng)的功能 參與者:購(gòu)票用戶 前置條件:電子商城正常運(yùn)行 后置條件:如果用戶輸入的帳號(hào)和密碼與系統(tǒng)數(shù)據(jù)庫(kù)中的數(shù)據(jù)一致,該用戶會(huì)登錄成功;否則,顯示輸入信息有誤,提示用戶重新輸入。基本路徑: 1.用戶登錄火車訂票系統(tǒng) 2.購(gòu)票用戶輸入自己的帳號(hào)和密碼 3.購(gòu)票用戶提交信息 4.系統(tǒng)檢查用戶帳號(hào)和密碼是否匹配 5.系統(tǒng)記錄并顯示當(dāng)前用戶 擴(kuò)展點(diǎn): 4a:系統(tǒng)檢測(cè)到帳號(hào)有誤 4a1.用戶重新輸入 4a2.用戶離開(kāi)系統(tǒng) 4b:購(gòu)票用戶密碼錯(cuò)誤 4b1:系統(tǒng)彈出密碼錯(cuò)誤警告信息 4b2:購(gòu)票用戶離開(kāi)或重新輸入密碼 變異點(diǎn):無(wú) 用例編號(hào):003 用例名:車票查詢 用例描述:在車票查詢頁(yè)面可以通過(guò)車次,始發(fā)地等信息查詢相關(guān)車次,獲得具體的車票信息 參與者:購(gòu)票用戶 前置條件:電子商城正常運(yùn)行,用戶已登錄該系統(tǒng) 后置條件:用戶輸入的車次信息是在實(shí)際的火車運(yùn)行系統(tǒng)中存在的則顯示相應(yīng)的車票信息,否則,提示用戶輸入的信息有誤。基本路徑: 1.用戶執(zhí)行登錄帳號(hào)進(jìn)入自己的頁(yè)面 2.用戶進(jìn)入車票查詢界面 3.購(gòu)票用戶輸入要查詢的車票、車次或時(shí)間等信息 4.系統(tǒng)檢測(cè)輸入的信息是否正確 5.系統(tǒng)返回給用戶車票的具體信息 擴(kuò)展點(diǎn): 4a:系統(tǒng)檢測(cè)到用戶輸入的信息有誤 4a1.用戶重新輸入 4a2.用戶離開(kāi)該功能界面 變異點(diǎn):無(wú) 用例編號(hào):004 用例名:訂單查詢 用例描述:用戶在提交訂單后可以通過(guò)該功能查詢自己的訂單情況以及歷史訂單 參與者:購(gòu)票用戶 前置條件:電子商城正常運(yùn)行,用戶已登錄該系統(tǒng)并在該系統(tǒng)已提交過(guò)訂單 后置條件:用戶提交信息后系統(tǒng)會(huì)查詢相關(guān)的數(shù)據(jù)庫(kù)信息,如果用戶提交過(guò)訂單,系統(tǒng)返回所有訂單(包括歷史訂單),否則提示用戶訂單列表為空 基本路徑: 1.用戶執(zhí)行登錄帳號(hào)進(jìn)入自己的頁(yè)面 2.用戶進(jìn)入訂單查詢界面 3.購(gòu)票用戶輸入要查詢的訂單的時(shí)間區(qū)間 4.系統(tǒng)調(diào)取用戶的訂單信息 5.系統(tǒng)返回給用戶想要的訂單信息(沒(méi)有訂單顯示空) 擴(kuò)展點(diǎn):無(wú) 變異點(diǎn):無(wú) 用例編號(hào):005 用例名:取消訂單 用例描述:該功能是訂單查詢的拓展功能,在訂單查詢之后可以選擇取消之前的訂單操作 參與者:購(gòu)票用戶 前置條件:用戶在執(zhí)行完查詢訂單功能,并至少有一份未完成的訂單 后置條件:系統(tǒng)根據(jù)用戶的操作在系統(tǒng)數(shù)據(jù)庫(kù)中找到相應(yīng)數(shù)據(jù),如果符合條件則刪除該條訂單信息,否則,提示用戶沒(méi)有未完成的訂單 基本路徑: 1.用戶執(zhí)行登錄帳號(hào)進(jìn)入自己的頁(yè)面 2.用戶進(jìn)入訂單查詢界面 3.用戶執(zhí)行取消訂單操作 4.系統(tǒng)檢測(cè)該操作是否符合取消訂單的條件 5.系統(tǒng)刪除用戶為完成的訂單 擴(kuò)展點(diǎn): 4a:用戶沒(méi)有未完成的訂單,用戶取消操作 變異點(diǎn):無(wú) 用例編號(hào):006 用例名:車票預(yù)定 用例描述:該功能是車票查詢的拓展功能,在查詢完車票信息后可以繼續(xù)執(zhí)行該功能,完成車票的最后預(yù)定 參與者:購(gòu)票用戶 前置條件:電子商城正常運(yùn)行,用戶已登錄該系統(tǒng)并查詢到自己需要的車票 后置條件:用戶提交信息后系統(tǒng)會(huì)查詢相關(guān)的數(shù)據(jù)庫(kù)信息,如果該車票有余票,則用戶預(yù)定成功,否則,提示用戶重新選擇車票或者放棄操作 基本路徑: 1.用戶執(zhí)行登錄帳號(hào)進(jìn)入自己的頁(yè)面 2.用戶執(zhí)行車票查詢功能 3.用戶預(yù)定車票 4.系統(tǒng)檢測(cè)車票是否有余票 5.系統(tǒng)返回用戶預(yù)定成功 擴(kuò)展點(diǎn): 4a:車票已被全部出售 4a1:用戶重新選擇車票 4a2:用戶放棄該操作 變異點(diǎn):無(wú) 用例編號(hào):007 用例名:信息查詢 用例描述:該功能可以讓用戶查詢自己的相關(guān)信息,包括帳號(hào)、密碼、姓名及郵箱等 參與者:購(gòu)票用戶 前置條件:電子商城正常運(yùn)行,用戶登錄系統(tǒng)進(jìn)入自己的頁(yè)面 后置條件:用戶提交請(qǐng)求后系統(tǒng)從數(shù)據(jù)庫(kù)中調(diào)用與該用戶有關(guān)的所有信息 基本路徑: 1.用戶執(zhí)行登錄帳號(hào)進(jìn)入自己的頁(yè)面 2.用戶提交信息查詢申請(qǐng) 3.系統(tǒng)調(diào)用數(shù)據(jù)庫(kù)中與該用戶有關(guān)的信息 4.系統(tǒng)把數(shù)據(jù)返回給用戶 擴(kuò)展點(diǎn):無(wú) 變異點(diǎn):無(wú) 用例編號(hào):008 用例名:修改信息 用例描述:該功能是信息查詢的拓展功能,主要指密碼、郵箱的修改 參與者:購(gòu)票用戶 前置條件:電子商城正常運(yùn)行,用戶已登錄系統(tǒng)并執(zhí)行了查詢功能 后置條件:用戶提交修改信息功能后,系統(tǒng)對(duì)比修改信息需要的條件,如果符合則把用戶在系統(tǒng)數(shù)據(jù)庫(kù)中的信息修改,否則,提示信息修改失敗 基本路徑: 1.用戶執(zhí)行登錄帳號(hào)進(jìn)入自己的頁(yè)面 2.用戶執(zhí)行信息查詢功能 3.用戶填寫(xiě)想要修改的信息 4.系統(tǒng)檢測(cè)相關(guān)條件 5.系統(tǒng)修改用戶的信息 擴(kuò)展點(diǎn):無(wú) 變異點(diǎn):無(wú) 用例編號(hào):009 用例名:添加用戶 用例描述:把新注冊(cè)的用戶添加到系統(tǒng)數(shù)據(jù)庫(kù)中 參與者:系統(tǒng)管理員 前置條件:有用戶條件注冊(cè)申請(qǐng),管理員執(zhí)行添加操作 后置條件:如果用戶輸入的帳號(hào)在系統(tǒng)中未被注冊(cè)過(guò),該用戶會(huì)注冊(cè)成功;否則,顯示帳號(hào)已注冊(cè),提示用戶重新輸入。基本路徑: 1.管理員登錄系統(tǒng) 2.管理員執(zhí)行添加用戶操作 3.系統(tǒng)檢測(cè)用戶是否注冊(cè) 4.管理員將用戶信息添加到數(shù)據(jù)庫(kù)中 擴(kuò)展點(diǎn):無(wú) 變異點(diǎn):無(wú) 用例編號(hào):010 用例名:修改用戶 用例描述:該功能可以修改用戶的信息及用戶權(quán)限 參與者:系統(tǒng)管理員 前置條件:系統(tǒng)正常運(yùn)行 后置條件:管理員選擇修改用戶信息,系統(tǒng)修改用戶在數(shù)據(jù)庫(kù)中的信息 基本路徑: 1.管理員登錄系統(tǒng) 2.管理員執(zhí)行修改用戶操作 3.系統(tǒng)修改用戶信息 擴(kuò)展點(diǎn):無(wú) 變異點(diǎn):無(wú) 用例編號(hào):011 用例名:刪除用戶 用例描述:該功能可以把用戶從系統(tǒng)中徹底刪除 參與者:系統(tǒng)管理員 前置條件:系統(tǒng)正常運(yùn)行 后置條件:管理員選擇刪除用戶,將用戶從系統(tǒng)中徹底刪除 基本路徑: 1.管理員登錄系統(tǒng) 2.管理員執(zhí)行刪除用戶操作 3.系統(tǒng)將用戶徹底刪除 擴(kuò)展點(diǎn):無(wú) 變異點(diǎn):無(wú) 用例編號(hào):012 用例名:修改票務(wù)信息 用例描述:在車票的價(jià)格及火車的發(fā)車時(shí)間等實(shí)際信息更改后要在系統(tǒng)中做出相應(yīng)修改 參與者:系統(tǒng)管理員 前置條件:系統(tǒng)正常運(yùn)行,實(shí)際運(yùn)行的票務(wù)信息有變化 后置條件:管理員根據(jù)實(shí)際的修改對(duì)系統(tǒng)中的票務(wù)信息做出相應(yīng)修改 基本路徑: 1.管理員登錄系統(tǒng) 2.管理員執(zhí)行修改票務(wù)信息操作 3.系統(tǒng)重新存儲(chǔ)修改后的信息 擴(kuò)展點(diǎn):無(wú) 變異點(diǎn):無(wú) 用例編號(hào):013 用例名:數(shù)據(jù)備份 用例描述:定期將重要數(shù)據(jù)進(jìn)行備份,防止數(shù)據(jù)丟失 參與者:系統(tǒng)管理員 前置條件:系統(tǒng)正常運(yùn)行 后置條件:管理員選擇數(shù)據(jù)備份,數(shù)據(jù)被備份存儲(chǔ) 基本路徑: 1.管理員登錄系統(tǒng) 2.管理員執(zhí)行數(shù)據(jù)備份操作 3.系統(tǒng)將重要數(shù)據(jù)進(jìn)行備份 擴(kuò)展點(diǎn):無(wú) 變異點(diǎn):無(wú) 2.2用例圖 3.類圖 3.1 實(shí)體類 3.2 邊界類 3.3控制類 4.對(duì)象圖 5.順序圖和協(xié)作圖 5.1用戶的順序圖和協(xié)作圖 (1)注冊(cè)帳號(hào) :購(gòu)票用戶:注冊(cè)界面:處理注冊(cè):系統(tǒng)數(shù)據(jù)庫(kù)1: c_register2: submit_info3: check_account4: return_account5: register6: succeed1: c_register:購(gòu)票用戶:注冊(cè)界面2: submit_info3: check_account5: register:處理注冊(cè)4: return_account6: succeed:系統(tǒng)數(shù)據(jù)庫(kù) (2)登錄帳號(hào) :購(gòu)票用戶:登錄界面:處理登錄:系統(tǒng)數(shù)據(jù)庫(kù)1: c_login2: submit_info3: check_account4: account5: return_ok 1: c_login:購(gòu)票用戶:登錄界面5: return_ok2: submit_info3: check_account:處理登錄4: account:系統(tǒng)數(shù)據(jù)庫(kù) (3)車票查詢 :購(gòu)票用戶:車票查詢界:查詢車票面1: c_query_ticket2: submit_ticket_info:車票數(shù)據(jù)3: request_info4: return_info1: c_query_ticket:購(gòu)票用戶:車票查詢界面2: submit_ticket_info3: request_info:查詢車票4: return_info:車票數(shù)據(jù) (4)車票預(yù)定 :購(gòu)票用戶:車票查詢界:查詢車票面1: c_query_ticket2: submit_ticket_info:車票數(shù)據(jù)庫(kù):預(yù)定車票:個(gè)人訂單3: request_info4: return_info5: c_reserve_ticket6: submit_order8: return_success7: create_order9: deliver_order 1: c_query_ticket5: c_reserve_ticket:購(gòu)票用戶:車票查詢界面4: return_info2: submit_ticket_info:查詢車票8: return_success:車票數(shù)據(jù)庫(kù)3: request_info6: submit_order:個(gè)人訂單7: create_order9: deliver_order:預(yù)定車票 (5)訂單查詢 :購(gòu)票用戶:訂單查詢界面:查詢訂單:個(gè)人信息:個(gè)人訂單1: query_order2: submit_info3: request_person_info4: return_info5: request_order6: return_order_info 1: query_order:購(gòu)票用戶:訂單查詢界面2: submit_info:查詢訂單4: return_info6: return_order_info5: request_order3: request_person_info:個(gè)人訂單:個(gè)人信息 (6)取消訂單 :購(gòu)票用戶:訂單查詢界面:查詢訂單:個(gè)人信息:個(gè)人訂單:取消訂單1: c_query_order2: submit_info3: request_person_info4: return_info5: request_order6: return_order_info7: c_cancel_order8: submit_cancel9: cancel_order10: return_success11: return_cancel_ok:購(gòu)票用戶1: c_query_order7: c_cancel_order:訂單查詢界面6: return_order_info2: submit_info:查詢訂單8: submit_cancel5: request_order11: return_cancel_ok10: return_success3: request_person_info4: return_info:個(gè)人訂單:取消訂單9: cancel_order:個(gè)人信息 (7)信息查詢 :購(gòu)票用戶:信息查詢界面:信息查詢:個(gè)人信息1: c_person_query2: submit_request3: query_info4: info5: return_person_info 1: c_person_query:購(gòu)票用戶5: return_person_info:信息查詢界面2: submit_request3: query_info:信息查詢4: info:個(gè)人信息 (8)修改個(gè)人信息 :購(gòu)票用戶:信息查詢界面:信息查詢:個(gè)人信息:修改信息1: c_person_query2: submit_request3: query_info4: info5: return_person_info6: c_edit_info7: request_edit8: edit_info9: true10: return_edit_ok1: c_person_query6: c_edit_info:購(gòu)票用戶:信息查詢界面2: submit_request:信息查詢5: return_person_info10: return_edit_ok4: info3: query_info7: request_edit8: edit_info:修改信息9: true:個(gè)人信息 5.2 系統(tǒng)管理員的順序圖和協(xié)作圖 (1)添加用戶 :系統(tǒng)管理員:添加用戶界面:添加用戶:系統(tǒng)數(shù)據(jù)庫(kù)1: a_add_account2: add_request3: check_account4: true5: add_account6: ok7: return_add_ok1: a_add_account:添加用戶界面:系統(tǒng)管理員7: return_add_ok2: add_request3: check_account5: add_account:系統(tǒng)數(shù)據(jù)庫(kù):添加用戶4: true6: ok (2)刪除用戶 :系統(tǒng)管理員:刪除用戶界面:刪除用戶:用戶信息1: a_delete_account2: delete_request3: check_account4: true5: delete_account6: true7: return_delete_ok :系統(tǒng)管理員1: a_delete_account7: return_delete_ok:刪除用戶界面:刪除用戶2: delete_request3: check_account5: delete_account4: true6: true:用戶信息 (3)修改用戶信息 :系統(tǒng)管理員:修改信息界面:修改用戶信息:用戶信息1: a_edit_account2: edit_request3: edit_info4: true5: return_edit_ok 1: a_edit_account:系統(tǒng)管理員:修改信息界面5: return_edit_ok2: edit_request3: edit_info:修改用戶信息4: true:用戶信息 (4)修改票務(wù)信息 :系統(tǒng)管理員:系統(tǒng)信息管理界面:票務(wù)信息修改:票務(wù)信息1: a_manage_info2: request_edit_ticket3: edit_info4: true5: get_info6: info7: return_new_info :系統(tǒng)信息管理界面1: a_manage_info:系統(tǒng)管理員7: return_new_info2: request_edit_ticket3: edit_info5: get_info:票務(wù)信息修改:票務(wù)信息4: true6: info (5)數(shù)據(jù)備份 :系統(tǒng)管理員:系統(tǒng)信息管理界面:數(shù)據(jù)備份:系統(tǒng)數(shù)據(jù):備份數(shù)據(jù)1: a_manage_info2: backup_request3: backup_data4: data5: restore_data6: success 1: a_manage_info:系統(tǒng)管理員:系統(tǒng)信息管理界面2: backup_request:數(shù)據(jù)備份4: data6: success3: backup_data5: restore_data:系統(tǒng)數(shù)據(jù):備份數(shù)據(jù) 6.狀態(tài)圖 6.1 車票狀態(tài)圖 添加車票車票可訂選定車票被選定提交訂單被預(yù)訂取消訂單完成支付已被取取票成功等待取票 6.2 用戶狀態(tài)圖 未注冊(cè)createAccountEvent已注冊(cè)關(guān)閉帳號(hào)帳號(hào)被注銷 7.組件圖 login.jspcustomer.javaregister.jspdata.java火車訂票系統(tǒng)java庫(kù)order_ticket.jsporder.javacancel_order.jspcancel.javaconsult_order.jspconsult.java 8.部署圖 路由器防火墻< 9.總結(jié) 通過(guò)這次對(duì)火車訂票系統(tǒng)的建模分析,讓我對(duì)全程城一體化建模的理解更深了。在做系統(tǒng)分析的時(shí)候,遇到了很多問(wèn)題。其中最大的問(wèn)題就是,系統(tǒng)在實(shí)際做的時(shí)候跟想的時(shí)候差距是很大的。做系統(tǒng)的時(shí)候要注意到所有的細(xì)節(jié),要把每一步都想的非常清楚,只有這樣才能搭建一個(gè)合理的系統(tǒng)。 程序簡(jiǎn)介 此程序是采用多文件模塊化形式編寫(xiě);其中自定義頭文件中包括了程序中所有調(diào)用的函數(shù)的聲明,以及需要的所有系統(tǒng)頭文件。 #include 編寫(xiě)時(shí)的分塊包括訂票塊、查詢塊、輸出塊,及已訂票修改部分等。 訂票塊則包含了定票流程的所有代碼。查詢塊中是通過(guò)車次號(hào)碼或是到達(dá)城市來(lái)查詢的。輸出部分包括了主界面的輸出,已定車票信息的輸出,所查車次信息輸出的頭部分。訂票修改即是改定過(guò)程的編程。 即此程序包括了查詢、訂票、改定的流程。 編程過(guò)程 在編寫(xiě)該程序時(shí),遇到了信息的保存問(wèn)題。訂票時(shí)與改定時(shí)的錄入信息的保存不知如何處理;之后將保存的部分分為鏈表暫存和文件的保存,在錄入信息時(shí)是暫存在鏈表中的,當(dāng)離開(kāi)此系統(tǒng)是會(huì)提示是否保存信息,若是則保存到文件中。此舉方便了票的改定,將數(shù)據(jù)分割開(kāi)了,也精簡(jiǎn)了程序,更便于閱讀。 編程模塊劃分后,編寫(xiě)程序之后的編譯時(shí),總是連分文件編譯時(shí)都無(wú)法通過(guò)。但是寫(xiě)入的代碼經(jīng)過(guò)檢查又沒(méi)有問(wèn)題,一直困擾著我。直到想起老師教的課本以外的知識(shí),并以一種玩玩試一試的心態(tài)用條件編譯得以解決此問(wèn)題。 同時(shí)在編程時(shí)多次用到“清屏”,保證了輸出界面的簡(jiǎn)潔。 在分出模塊后,未完成所有部分的編程時(shí)的試運(yùn)行時(shí)出現(xiàn)剛一進(jìn)入子程序時(shí)便會(huì)回到主界面,后發(fā)現(xiàn)時(shí)由于只有輸出部分沒(méi)有輸入部分,每當(dāng)運(yùn)行完子程序后回到主程序時(shí)都會(huì)被“清屏”,結(jié)果造成編譯時(shí)正常,到運(yùn)行時(shí)卻漏洞百出。 在編程時(shí),由于對(duì)文件的處理不熟悉,以及計(jì)算機(jī)的設(shè)置問(wèn)題沒(méi)考慮,使用了‘w+’的調(diào)用方式,使得在保存數(shù)據(jù)到文件時(shí)出現(xiàn)無(wú)法寫(xiě)入文件的現(xiàn)象。在百度,問(wèn)同學(xué)以及問(wèn)老師后才用‘wb+’和別的方式調(diào)用,并寫(xiě)入成功。 這個(gè)程序時(shí)我學(xué)習(xí)計(jì)算機(jī)c以來(lái)編寫(xiě)的最大型涵蓋面最廣的一個(gè)程序,沒(méi)有之一。但同時(shí)我也知道這在c語(yǔ)言編程中也只是很小的一個(gè)小程序而已,我在這編程中發(fā)現(xiàn):我要學(xué)的還有很多,大型程序也不是一個(gè)人能寫(xiě)出來(lái)的,會(huì)一些編程技巧是很有必要的,與人合作是 – 1 – 必須的,當(dāng)然了,我不是在寫(xiě)詩(shī),而是真的這么覺(jué)得。一個(gè)人會(huì)的有限,專精方向也不同,若能好好的合作肯定可以超過(guò)一個(gè)人單干。 部分源代碼 訂票程序 #ifndef TRAINHEAD_H #define TRAINHEAD_H #include“trainhead.h” #endif/*條件編譯,作用是防止頭文件被重復(fù)引用*/ int saveflag = 0;void Bookticket(link l,booklink k){ Node *p[10],*q;char c[2],tnum[10],str[10],str1[10];Book *r,*s;int i = 0,t = 0,flag = 0,dnum;r = k;while(r->next!=NULL) r = r->next;printf(“Input the city you want to go:”);scanf(“%s”,&str);q = l->next;while(q!=NULL) { if(strcmp(q->data.reachcity,str)==0) { p[i] = q; i++; } q = q->next; } printf(“nthe number of record have %dn”,i); printhead(); for(t=0;t printdata(p[t]); if(i==0) printf(“nSorry!Can't find the train for you!n”); else { printf(“ndo you want to book it? scanf(“%s”,c); if(strcmp(c,“Y”)==0||strcmp(c,“y”)==0)/*判斷是否訂票*/ { s =(Book*)malloc(sizeof(Book)); printf(“nInput your name: ”); scanf(“%s”,&s->data.name); printf(“nInput your ID: ”); scanf(“%s”,&str1); 相應(yīng)減少*/ strcpy(s->data.num,str1);printf(“nplease input the number of the train:”);scanf(“%s”,tnum);for(t=0;tdata.num,tnum)==0){ if(p[t]->data.ticketnum < 1)/*判斷剩余的供訂票的票數(shù)是否為0*/ { printf(“nsorry,no ticket!”); Sleep(2); return;} printf(“nremain %d ticketsn”,p[t]->data.ticketnum);flag = 1;break;} if(flag==0){ printf(“ninput error”);Sleep(2);return;} printf(“nInput your bookNum: ”);scanf(“%d”,&dnum);p[t]->data.ticketnum=p[t]->data.ticketnum-dnum;/*定票成功則可供訂的票數(shù)s->data.bookNum = dnum;s->next = NULL;r->next = s;r = s;printf(“nLucky!you have booked a ticket!”);getch(); – 3 – } } } saveflag = 1;使用說(shuō)明 運(yùn)行程序時(shí),首先進(jìn)入到菜單部分,菜單部分提供了菜單顯示和輸入功能部分。其運(yùn)行效果如圖19.1所示。在主界面上輸入數(shù)字0——6,實(shí)現(xiàn)相應(yīng)的功能。 圖19.1 火車訂票系統(tǒng)主界面 主界面輸入“1”,進(jìn)入添加火車信息界面,如圖19.2所示。根據(jù)屏幕上給出的提示輸入火車的車次,起點(diǎn),終點(diǎn),出發(fā)時(shí)間,到達(dá)時(shí)間,票價(jià)和可以訂購(gòu)的票數(shù)。 – 4 – 圖19.2 輸入效果圖 主界面輸入“2”,可以查詢火車信息,可以選擇查詢的方法有兩種,一種是按照車次查詢,一種是按照你想要到達(dá)的地方查詢,運(yùn)行效果如圖19.3所示。 – 5 – 圖19.3 查詢效果圖 當(dāng)在主界面輸入“3”時(shí),進(jìn)入訂票界面,按照提示輸入你想要到達(dá)的城市,會(huì)自動(dòng)顯示出你終點(diǎn)站為你輸入城市的信息,根據(jù)提示輸入你是否決定訂票以及你的個(gè)人信息,運(yùn)行效果如圖19.4所示。 圖19.4 訂票效果圖 當(dāng)在主界面輸入“4”時(shí),進(jìn)入修改界面,根據(jù)提示輸入你要修改的內(nèi)容,修改模塊的運(yùn)行效果如圖19.5所示。 – 6 – 圖19.5 修改效果圖 當(dāng)在主界面輸入“5”時(shí),可以顯示出所有的火車信息,顯示模塊效果如圖19.6所示。 – 7 – 圖19.6 顯示效果圖 當(dāng)在主界面輸入“6”時(shí),進(jìn)入到保存模塊,將錄入的火車信息進(jìn)行保存,并且將訂票人的信息也進(jìn)行保存,存儲(chǔ)在指定的磁盤(pán)文件中。運(yùn)行效果如圖19.7所示。 圖19.7 保存效果圖 – 8 – 火車訂票系統(tǒng)源碼 #include intshoudsave=0;int count1=0,count2=0,mark=0,mark1=0;/*定義存儲(chǔ)火車信息的結(jié)構(gòu)體*/ struct train { char num[10];/*列車號(hào)*/ char city[10];/*目的城市*/ char takeoffTime[10];/*發(fā)車時(shí)間*/ char receiveTime[10];/*到達(dá)時(shí)間*/ int price;/*票價(jià)*/ intbookNum;/*票數(shù)*/ };/*訂票人的信息*/ struct man { charnum[10];/*ID*/ char name[10];/*姓名*/ intbookNum;/*需求的票數(shù)*/ };/*定義火車信息鏈表的結(jié)點(diǎn)結(jié)構(gòu)*/ typedefstruct node { struct train data;struct node * next;}Node,*Link;/*定義訂票人鏈表的結(jié)點(diǎn)結(jié)構(gòu)*/ 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(“********************************************************”);} /*添加一個(gè)火車信息*/ 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; /*判斷是否已經(jīng)存在*/ 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; } } /*系統(tǒng)給用戶的提示信息*/ 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;}第二篇:火車訂票管理系統(tǒng)
第三篇:火車訂票系統(tǒng)部分 uml[推薦]
第四篇:火車訂票管理系統(tǒng)主程序流程
第五篇:C語(yǔ)言編程---火車訂票系統(tǒng)源代碼