C++實現(xiàn)地鐵自動售票系統(tǒng)程序設計_第1頁
C++實現(xiàn)地鐵自動售票系統(tǒng)程序設計_第2頁
C++實現(xiàn)地鐵自動售票系統(tǒng)程序設計_第3頁
C++實現(xiàn)地鐵自動售票系統(tǒng)程序設計_第4頁
C++實現(xiàn)地鐵自動售票系統(tǒng)程序設計_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

第C++實現(xiàn)地鐵自動售票系統(tǒng)程序設計本文實例為大家分享了C++實現(xiàn)地鐵自動售票系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

題目描述:

地鐵是當今城市較為流行的一種鐵路運輸?shù)男问?,地鐵能避免城市地面擁擠,充分利用空間,具有運量大、準時、正點率較其他公交高、速度快等優(yōu)點。請設計一個簡易的、帶菜單的地鐵自動售票機系統(tǒng)。

功能需求:

(1)設計一個地鐵路線類Router,包含路線編號,途中的各個站點。

(2)設計一個地圖類Map,可以顯示所有可以乘坐的地鐵站名,以及線路信息。

(3)根據(jù)用戶輸入的起點和終點和人次信息,可以自動計算應付金額;根據(jù)用戶輸入的金額,計算找零信息。

程序設計:

#includeiostream

#includevector

usingnamespacestd;

classRouter{

private:

stringport[100];//經(jīng)過站點

intid;//路線編號

intcount=0;//站點數(shù)目

public:

voidsetId(inti){

id=i;

}

voidaddPort(stringname){

port[count]=name;

count++;

}

voidgetPort(){

inti=0;

for(i=0;icount;i++){

cout"第"i+1"站:";

coutport[i];

coutendl;

}

}

intcheck(stringu,stringv){

intd=0;

for(inti=0;icount;i++){

if(port[i]==u){

for(intj=0;jcount;j++){

if(port[j]==v){

//uv

return((i-j)=0)

(i-j):(j-i);

}

}

}

}

return0;

}

classMap{

private:

vectorRouter//路線圖

public:

doublecharge=2;//每站價格

voidsetCharge(doublech){

charge=ch;

}

voidinit(){

Routertemp1;

temp1.setId(1);

temp1.addPort("west");

temp1.addPort("mid1");

temp1.addPort("south");

r.push_back(temp1);

Routertemp2;

temp2.setId(2);

temp2.addPort("south");

temp2.addPort("mid2");

temp2.addPort("east");

r.push_back(temp2);

Routertemp3;

temp3.setId(3);

temp3.addPort("east");

temp3.addPort("mid3");

temp3.addPort("north");

r.push_back(temp3);

Routertemp4;

temp4.setId(4);

temp4.addPort("north");

temp4.addPort("mid4");

temp4.addPort("west");

r.push_back(temp4);

}

intbuy(stringstart,stringend){

intcount=r.size();

intd=0;

for(inti=0;icount;i++){

Routertemp=r[i];

d=temp.check(start,end);

if(d0){

cout"您需要乘坐"i+1"號線"endl;

returnd;

}

}

return0;

}

voidshow(){

intcount=r.size();

cout"本市地鐵線路圖如下:"endl;

for(inti=0;icount;i++){

couti+1"號線:"endlendl;

Routertemp=r[i];

temp.getPort();

coutendlendl;

}

}

voidmenu(){

intm;

Mapmap;

map.init();

while(1){

coutendlendlendl;

cout"----------歡迎來到地鐵售票系統(tǒng)-----------"endl;

cout"----------1、路線查詢-----------"endl;

cout"----------2、購票-----------"endl;

cinm;

if(m==1){

map.show();

}elseif(m==2){

cout"請輸入起點:"endl;

strings;

cins;

cout"請輸入終點:"endl;

stringe;

cine;

cout"請輸入人數(shù):"endl;

intc;

cinc;

intd=map.buy(s,e);

if(d0){

doublers=(double)c*(double)d*map.charge;

cout"您需要支付的費用為:";

coutrsendl;

cout"請輸入您支付的金額:";

doublein=0;

cinin;

if(in=rs){

cout"購票成功!"endl;

cout"找零:"in-rs"元"endl;

}else{

cout"金額不足,購票失敗!"

溫馨提示

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

評論

0/150

提交評論