c++課程設(shè)計(jì)-車票管理系統(tǒng)_第1頁(yè)
c++課程設(shè)計(jì)-車票管理系統(tǒng)_第2頁(yè)
c++課程設(shè)計(jì)-車票管理系統(tǒng)_第3頁(yè)
c++課程設(shè)計(jì)-車票管理系統(tǒng)_第4頁(yè)
c++課程設(shè)計(jì)-車票管理系統(tǒng)_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、void Bus_link::input()Bus_infor p,p2=NULL;p=head;int n;while(p->next)p=p>next;while(n)p2=new Bus_infor;p2input();p->next=p2;p2next=NULL;p=p>next;Bus_link:setkey(1);cout”ttt按1繼續(xù),按0返回:"cin>>n;#include<iostream /數(shù)據(jù)流輸入輸出#includefstream>/文件輸入輸出#includestring/字符串操作include<i

2、omanip/參數(shù)化輸入輸出#include<time.h/時(shí)間庫(kù)函數(shù)using namespace std;/命名空間class Bus_inforprivate: static int Bus_No;/靜態(tài)數(shù)據(jù)成員,統(tǒng)計(jì)當(dāng)前所有的Bus_infor對(duì)象的數(shù)目char start20;/起點(diǎn)站char end20;/終點(diǎn)站int Bus_order;/班次號(hào) int all_tickted;/額定載量int tickted;/已定票人數(shù)int Hour_start,Minute_start;/發(fā)車時(shí)間float GoHour;/行車時(shí)間public:Bus_infor();Bus_in

3、for();Bus_infor next;void input();/錄入函數(shù) void input(ifstream is);/讀取函數(shù) void output();/輸出函數(shù)void output(ofstream os);/寫入函數(shù)void Order_tickt(int n);/定票函數(shù)void Unorder_tickt(int n);/退票函數(shù)void GetTime_start();/獲取發(fā)車時(shí)間函數(shù)bool GetTime();/判斷當(dāng)前班次狀況函數(shù)int Get_all_tickted() return all_tickted; /內(nèi)聯(lián)函數(shù),返回額定載量 int Get_ti

4、ckted() return tickted; /返回已定票人數(shù)int Get_bus_order() return Bus_order; /返回班次號(hào)string Get_end()const;/返回終點(diǎn)站的字符串;int Bus_infor::Bus_No=1;Bus_infor::Bus_infor() Bus_No+; tickted=0;Bus_infor:Bus_infor() Bus_No-;void Bus_infor::input()cout<”ttt按提示輸入:”<<endl;cout<”輸入班次: ”;while(1)cinBus_order;if

5、 (cin.fail())/判斷輸入的數(shù)據(jù)類型是否有錯(cuò)cout < "n班次輸入錯(cuò)誤,請(qǐng)重新輸入:";cin.clear();cin。get();else break;cout"請(qǐng)輸入車的額定座位數(shù): "while(1)cin>all_tickted;if (cin.fail())/判斷輸入的數(shù)據(jù)類型是否有錯(cuò)cout ”n座位數(shù)輸入錯(cuò)誤,請(qǐng)重新輸入:"cin.clear();cin。get();else break;GetTime_start();cout<"請(qǐng)輸入行車時(shí)間:"while(1)cin>

6、>GoHour;if (cin。fail()/判斷輸入的數(shù)據(jù)類型是否有錯(cuò)cout < ”n行車時(shí)間輸入錯(cuò)誤,請(qǐng)重新輸入:";cin。clear();cin。get();else break;cout"請(qǐng)輸入起始站與終點(diǎn)站:”; cin>start;cinend;cout<"是否清空售票(y/n)?"char a;cin>a;if(a='y|a=Y) tickted=0;void Bus_infor::input(ifstream is) is>Bus_order>>Hour_start>Min

7、ute_start>>start>end>GoHourall_tickted>>tickted;is.get(); void Bus_infor::output()cout<” "<<Bus_order<"t"if(Minute_start=0)/判斷發(fā)車時(shí)的分鐘時(shí)刻,若為分則在后面多顯示個(gè),以符合時(shí)間格式cout<Hour_start<<”:”<< Minute_start"0t”;elsecout<Hour_start”:"< Minute

8、_start”t”;cout<start<"t”<<end< "t”<GoHour<”t ”<all_tickted<<”t "<tickted; if(!GetTime())cout”t 此班已出發(fā)”<endl;elsecout<”t 此班未出發(fā)”endl;void Bus_infor:output(ofstream os) os<setw(6)<Bus_order/setw()設(shè)置輸出寬度setw(15)<Hour_start<setw(15)<Minu

9、te_start<setw(15)<startsetw(6)<<endsetw(15)GoHour<setw(15)<<all_ticktedsetw(15)<tickted<<endl;void Bus_infor::GetTime_start()cout<”請(qǐng)輸入始發(fā)時(shí)間(時(shí)分):";while(1)cin>Hour_start>>Minute_start;if (cin.fail()/判斷輸入的數(shù)據(jù)類型是否有錯(cuò)cout < ”n時(shí)間輸入錯(cuò)誤,請(qǐng)重新輸入:”;cin。clear();cin.

10、get();else if(Hour_start<0|Hour_start>24|Minute_start<0|Minute_start60)cout<”n時(shí)間格式出錯(cuò),請(qǐng)重新輸入:”;/判斷時(shí)間格式是否出錯(cuò),小時(shí)不能小于大于,分鐘不能小于大于elsebreak;bool Bus_infor:GetTime()struct tm local; time_t t; t=time(NULL); local=localtime(t);/獲取當(dāng)前系統(tǒng)時(shí)間if(local-tm_hourHour_start|(local>tm_hour=Hour_start & l

11、ocaltm_min=Minute_start))return 1; /比較當(dāng)前時(shí)間與發(fā)車時(shí)間,獲得班次的當(dāng)前狀況,返回表示班次未出發(fā)elsereturn 0;/返回表示班次已出發(fā)void Bus_infor:Order_tickt(int n)tickted=tickted+n;void Bus_infor:Unorder_tickt(int n)tickted=ticktedn;string Bus_infor:Get_end()conststring s=end;return s;class Bus_linkpublic:Bus_link()head=new Bus_infor;head

12、>next=NULL;key=0;/帶參數(shù)的構(gòu)造函數(shù)Bus_link()delete head;/析構(gòu)函數(shù)void input();/錄入車票信息void mend();/修改車票信息void del();/刪除車票信息int find(Bus_infor *p,int num,char *pn);/查找函數(shù) void found();/查詢車票信息void show();/顯示車票信息 void Order();/定購(gòu)車票信息 void Unorder();/退還車票信息 void save();/保存車票信息 void begin();/初始化車票信息 void clear();/清

13、除函數(shù)void about();/關(guān)于車票信息 char mainmenu();/主菜單函數(shù) void setkey(int k) key=k; /設(shè)置系統(tǒng)修改標(biāo)志 int getkey() return key;/返回系統(tǒng)修改標(biāo)志private: Bus_infor *head; /鏈表指針 int key;/系統(tǒng)修改標(biāo)志int password;/管理員登陸標(biāo)志;void Bus_link:input()if(password=1)Bus_infor p,p2=NULL;p=head; int n=1; /int n;while(p-next)p=p->next;while(n)p2

14、=new Bus_infor;p2>input();pnext=p2;p2->next=NULL;p=p-next; Bus_link:setkey(1);cout<<"ttt按繼續(xù),按返回: ”;cinn;if(!cin)throw string(”數(shù)據(jù)輸入錯(cuò)誤");elsecout<”ntt對(duì)不起,游客不能錄入車票信息”<endl;void Bus_link:show()cout<"客車基本信息如下:”<endl "班次發(fā)車時(shí)間 起點(diǎn)站 終點(diǎn)站 行車時(shí)間額定載量已定票人數(shù)當(dāng)前狀況”endl;Bus_in

15、for p;p=head;while(p>next)(p->next)->output();p=p>next;void Bus_link::found()Bus_infor *p;int num,n;char name20;docout"tt1:按班次查找,2:按終點(diǎn)站查找: ”;cin>>n;if(!cin)throw string("數(shù)據(jù)輸入錯(cuò)誤”);while(n1|n2);if(n=1)cout<<"ttt輸入班次: ";cin>num;if(!cin)throw string(”數(shù)據(jù)輸入錯(cuò)誤

16、");if(n=2)cout”ttt輸入終點(diǎn)站: ";cinname;if(!find(p,num,name)cout<"tt找不到你要查找的內(nèi)容!”<endl;return;int Bus_link:find(Bus_infor *p1,int num,char *pn)Bus_infor p;p=head;int t=0;while(p->next)(p1)=p;if( (pnext)-Get_bus_order()=num| (pnext)-Get_end()=pn )cout<”客車基本信息如下:"<<endl

17、 <"班次發(fā)車時(shí)間 起點(diǎn)站 終點(diǎn)站 行車時(shí)間額定載量已定票人數(shù)當(dāng)前狀況"<endl; (p>next)->output(); t=1;p=p-next;return t;void Bus_link::del()if(password=1)Bus_infor *p,p2;int num;char name20;cout<”ttt輸入班次號(hào): ”;cin>num;if(!cin)throw string(”數(shù)據(jù)輸入錯(cuò)誤”);if( !find(&p,num,name) )cout<"tt找不到你要?jiǎng)h除的內(nèi)容!"

18、;<endl;return;cout<<"nttt確定刪除(y/n)?”;char a;cin>a;if(a='ya='Y) p2=pnext;p>next=p2>next;delete p2;Bus_link:setkey(1);elsecout<"ntt對(duì)不起,游客不能刪除車票信息"<endl;void Bus_link::mend()if(password=1)Bus_infor p;int num;char name20;cout<”ttt輸入班次號(hào): ”;cin>num;if(!

19、cin)throw string(”數(shù)據(jù)輸入錯(cuò)誤");if( !find(p,num,name) )cout<”tt找不到你要修改的內(nèi)容!"<endl;return;(p>next)-input();Bus_link::setkey(1);elsecout<"ntt對(duì)不起,游客不能修改車票信息”<endl;void Bus_link:Order()if(password=1)Bus_infor *p;cout”nttt確定購(gòu)票(y/n)?”;char X;cin>>X;if(X=y|X=Y)int num;cout<

20、<"nttt輸入班次號(hào): ”;cin>num;if(!cin)throw string("數(shù)據(jù)輸入錯(cuò)誤”);if( !find(p,num,”") )cout<<"ntt找不到你要定票的車輛的內(nèi)容!"endl;return;p=p->next;if(!(p->GetTime())/判斷要定票的車輛是否已經(jīng)出發(fā),若已經(jīng)出發(fā)則不允許定票cout<<”ntt你要訂票的車輛已出發(fā)!"<<endl;return;cout”nttt輸入要定的票數(shù)”;int n;cin>n;if(!

21、cin)throw string(”數(shù)據(jù)輸入錯(cuò)誤");if(p-Get_tickted()+n)=p>Get_all_tickted())p-Order_tickt(n);else cout<”ntt對(duì)不起,沒(méi)有足夠的票數(shù)?!?lt;<endl;else if(X='n'|X=N) cout"謝謝使用"<endl;else cout<<”nttt輸入字符不確定"<<endl;Bus_link:setkey(1);elsecout<"ntt對(duì)不起,訂購(gòu)車票請(qǐng)?jiān)诠芾韱T處購(gòu)買”&l

22、t;endl;void Bus_link::Unorder()if(password=1)Bus_infor *p;cout<"nttt確定退票(y/n)?"char X;cin>>X;if(X='y'|X='Y)int num;cout"nttt輸入班次號(hào): ”;cin>>num;if(!cin)throw string(”數(shù)據(jù)輸入錯(cuò)誤");if( !find(&p,num,”) )cout”ntt找不到你要退票的車輛的內(nèi)容!”endl;return;if(!(pGetTime())/判斷要

23、定票的車輛是否已經(jīng)出發(fā),若已經(jīng)出發(fā)則不允許定票cout<"ntt你要退票的車輛已出發(fā)!”<endl;return;cout<<”nttt輸入要退的票數(shù)”;int n;cin>>n;if(!cin)throw string(”數(shù)據(jù)輸入錯(cuò)誤”);p=pnext;if(p-Get_tickted()n)>=0)pUnorder_tickt(n);else cout<<"nttt對(duì)不起,數(shù)據(jù)出錯(cuò)!?!?lt;<endl;else if(X=nX='N) cout<”謝謝使用”<endl;else cou

24、t<<”nttt輸入字符不確定”<endl;Bus_link:setkey(1);elsecout<”ntt對(duì)不起,退還車票請(qǐng)?jiān)诠芾韱T處退還”<<endl;void Bus_link:save()if(password=1)Bus_infor p;p=head;ofstream os("bus。txt”,ios:out);/文件以輸出方式打開(kāi)if (Bus_link::getkey()=1)while(p>next)(p>next)output(os);p=p-next;cout<”ttt文件已保存! ”<endl;Bus_

25、link::setkey(0);elsecout<"ntt對(duì)不起,游客無(wú)法保存車票信息”<endl;void Bus_link::about()cout<endl<”關(guān)于車票管理系統(tǒng)"endl<<”"<endl;cout”使用說(shuō)明:"<endl"t1。請(qǐng)按照操作提示輸入正確的格式,以保證系統(tǒng)正常運(yùn)行;”<endl<"t2.當(dāng)使用管理員登陸時(shí),需輸入密碼,可進(jìn)行對(duì)系統(tǒng)的所有操作;”<endl"t3.當(dāng)使用游客身份登陸時(shí),無(wú)需輸入密碼,但只能瀏覽和查詢車票信息;”

26、<<endl”t4.車票信息用文本文檔格式,保存在本程序文件夾目錄下,可以直接打開(kāi)查看.”<endl<endl<<"系統(tǒng)說(shuō)明:”endl<"t本系統(tǒng)為課程設(shè)計(jì)作品,可以簡(jiǎn)易的進(jìn)行車票管理,歡迎提出意見(jiàn)和建議"<<endl <"t漳州師范學(xué)院計(jì)算機(jī)科學(xué)與工程系09非師四班t ”<endl<endl;void Bus_link:begin()password=0;Bus_infor *p,p2;p=head;clear();long t;ifstream is("bus.txt

27、”,ios::in);/文件以輸入方式打開(kāi)if(!is)ofstream os("bus。txt”,ios::out);/文件以輸出方式打開(kāi)os。close();/關(guān)閉文件return ;int num=1;while(1) num=-1;t=is.tellg();/記錄下當(dāng)前位置is>num;is.seekg(t);/移動(dòng)到原來(lái)位置if(num<0) is.close();return;p2=new Bus_infor;p2input(is);/輸入is對(duì)象內(nèi)容p-next=p2;p2->next=NULL;p=p-next;void Bus_link::clea

28、r()Bus_infor *p,*p2;p=head>next;while( p )p2=p;p=p>next;delete p2;char Bus_link:mainmenu()struct tm *local; char s1128;time_t t;t=time(NULL);local=localtime(t);strftime(s1,128,"%Ymd H:%M ”,local);/按照指定的格式,把時(shí)間保存在s1字符串里面string s;/定義字符串s,來(lái)判斷功能選擇是否輸入錯(cuò)誤cout<"nn 歡迎使用車票管理系統(tǒng)"<endl

29、<<endl;cout<" "<endl" "<<endl<" 1. 錄入車票信息 2。 瀏覽車票信息 ”endl<<” 3。 查詢車票信息 4. 刪除車票信息 ”<endl" 5。 修改車票信息 6。 定購(gòu)車票信息 "<<endl<" 7。 退還車票信息 8. 保存車票信息 "endl<” 9。 關(guān)于車票系統(tǒng) 0. 退出系統(tǒng) ”<<endl" ”endl” ”<<endl<"tttt "<<s1<endl<endl;while(password=0)cout"tt請(qǐng)選擇用戶名(1.管理員;2。游客): ”;int n;cin>n;if(!cin)throw string(”數(shù)據(jù)輸入錯(cuò)誤");if(n=1)cout"ntt請(qǐng)輸入管理員密碼: "int m;cin>m;if(m=123456)password=1;cout<endl;break;elsecout<"ntt密碼輸入不正確n”<endl;elsepas

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論