c%2B%2B_車輛管理系統(tǒng)_第1頁
c%2B%2B_車輛管理系統(tǒng)_第2頁
c%2B%2B_車輛管理系統(tǒng)_第3頁
c%2B%2B_車輛管理系統(tǒng)_第4頁
c%2B%2B_車輛管理系統(tǒng)_第5頁
已閱讀5頁,還剩10頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、車輛管理系統(tǒng)主要負責各種車輛的常規(guī)信息管理工作。系統(tǒng)中的車輛主要有大客車、小轎車和卡車。每種車輛有車輛編號、車牌號、車輛制造公司、車輛購買時間、車輛型號(大客車、小轎車和卡車)、總公里數(shù)、耗油量/公里、基本維護費用、養(yǎng)路費、累計總費用等信息。大客車還有載客量(最大載客數(shù))信息,小轎車還有箱數(shù)(兩廂或三廂)信息,卡車還有載重量等信息。每臺車輛當月總費用=油價*耗油量/公里+基本維護費用?;揪S護費用:客車:2000 元/月,小轎車:1000 元/月,卡車:1500 元/月功能要求:(1)添加車輛:主要完成車輛信息的添加,要求編號唯一。當添加了重復的編號時,則提示數(shù)據(jù)添加重復并取消添加;當車輛信息

2、庫已滿,則提示不能再添加新的數(shù)據(jù)。(2)查詢車輛:可按照三種方式來查詢物品,分別為:按車輛制造公司查詢:輸入車輛制造公司,輸出所查詢的信息,若不存在該記錄,則提示“該車輛制造公司不存在!”;按編號查詢:輸入編號,輸出所查詢的信息,若不存在該記錄,則提示“該編號不存在!”;按類別查詢:輸入類別,輸出所查詢的信息,若不存在記錄,則提示“該類別沒有車輛!”;(3)顯示車輛信息庫:輸出當前車輛信息庫中所有車輛信息,每條記錄占據(jù)一行。(4)編輯功能:可根據(jù)查詢結果對相應的記錄進行修改,修改時注意編號的唯一性。(5)刪除車輛:主要完成車輛信息的刪除。如果當前車輛信息庫為空,則提示“車輛信息庫為空!”,并返

3、回操作;否則,輸入要刪除的編號,根據(jù)編號刪除該車輛的記錄,如果該編號不在車輛信息庫庫中,則提示“該編號不存在”。(6)統(tǒng)計信息輸出當前車輛信息庫中總物品數(shù),以及按車輛類別,統(tǒng)計出當前車輛信息庫中各類別的物品數(shù)并顯示。(7)車輛信息存盤:將當前程序中的車輛信息存入文件中。(8)讀出車輛信息:從文件中將車輛信息讀入程序。源代碼:#include #include #include #include using namespace std;int N=5;/*設置全局變量N=5,信息庫最多存儲5輛車輛信息*/int n1=0;/*全局變量,記錄大客車文件當前信息庫信息數(shù)量*/int n2=0;/*全

4、局變量,記錄小轎車文件當前信息庫信息數(shù)量*/int n3=0;/*全局變量,記錄卡車文件當前信息庫信息數(shù)量*/ofstream os1(file1.dat,ios:binary|ios:trunc);/*建立file1文件*/ofstream os2(file2.dat,ios:binary|ios:trunc);/*建立file2文件*/ofstream os3(file3.dat,ios:binary|ios:trunc);/*建立file3文件*/class car/*汽車類*/ public: string number; string license_plat;/*車牌號碼*/ st

5、ring company; double time_buying; string mode; double ODO;/*總公里數(shù)*/ double oil_consumption;/*油耗量/公里*/ double oil_price;/*油價*/ double road_tolt;/*養(yǎng)路費*/ double all_cost;/*累計費用*/ void getcar(); void show() coutnumbertlicense_plattcompanyttime_buyingt modetODO oil_consumption oil_pricet road_toltt;/*輸出所有

6、數(shù)據(jù)*/ car() ;/*/class truck:public car/*卡車類,公有繼承汽車類*/ public: double maintenance_charges;/*基本維護費用*/ double load_weight;/*卡車附加屬性載重量*/ void setall() maintenance_charges=1000;/*設置基本維護費用*/ all_cost=(ODO*oil_consumption*oil_price)+(time_buying*maintenance_charges);/*計算累計費用*/ void show() car:show(); cout a

7、ll_costtload_weightendl;/*輸出所有數(shù)據(jù)*/ truck() ;/*/class sedan:public car/*小轎車類,公有繼承汽車類*/ public: double maintenance_charges;/*基本維護費用*/ int CTNS;/*小轎車附加屬性箱數(shù)*/ void setall() maintenance_charges=1500;/*設置基本維護費用*/ all_cost=(ODO*oil_consumption*oil_price)+(time_buying*maintenance_charges);/*計算累計費用*/ void sh

8、ow() car:show(); cout all_costtCTNSendl;/*輸出所有數(shù)據(jù)*/ sedan() ;/*/class coach:public car/*客車類,公有繼承汽車類*/ public: double maintenance_charges;/*基本維護費用*/ int apacity;/*大客車附加屬性載客量*/ void setall() maintenance_charges=1000;/*設置基本維護費用*/ all_cost=(ODO*oil_consumption*oil_price)+(time_buying*maintenance_charges)

9、;/*計算累計費用*/ void show() car:show(); cout all_costtapacityendl;/*輸出所有數(shù)據(jù)*/ coach() ;/*/void car:getcar()/*getcar()函數(shù)實現(xiàn)*/ coutlicense_plat; coutcompany; couttime_buying; coutmode; coutODO; coutoil_consumption; coutoil_price; coutroad_tolt; /*/coach* getcoach()/*設置函數(shù)獲取客車庫中信息存儲于數(shù)組中,方便之后提取*/int i;coach* h

10、ead=new coachn1;ifstream is1(file1.dat,ios:in|ios:binary);for(i=0;iheadi.numberheadi.license_panyheadi.time_buyingheadi.modeheadi.ODO headi.oil_consumptionheadi.oil_priceheadi.road_toltheadi.all_costheadi.apacity; is1.close();return head;/*/sedan* getsedan()/*設置函數(shù)獲取小轎車庫中信息存儲于數(shù)組中,方便之后提取*

11、/int i;sedan* head=new sedann2;ifstream is2(file2.dat,ios:in|ios:binary);for(i=0;iheadi.numberheadi.license_panyheadi.time_buyingheadi.modeheadi.ODO headi.oil_consumptionheadi.oil_priceheadi.road_toltheadi.all_costheadi.CTNS; is2.close();return head;/*/truck* gettruck()/*設置函數(shù)獲取客車庫中信息存儲于

12、數(shù)組中,方便之后提取*/int i;truck* head=new truckn3;ifstream is3(file3.dat,ios:in|ios:binary);for(i=0;iheadi.numberheadi.license_panyheadi.time_buyingheadi.modeheadi.ODO headi.oil_consumptionheadi.oil_priceheadi.road_toltheadi.all_costheadi.load_weight; is3.close();return head;/*/int add()/*添加函數(shù)*

13、/ int i,j,k,x; string str; coach c; sedan s; truck t; coutx; for(i=0;ix;i+) int flag=0; cout請選擇第i+1輛添加車輛的類別(退出輸入0): endl; cout*endl; cout* 1 大客車 2 小轎車 3 卡車 *endl; cout*j; if(j=0) return(0);/*用戶輸入0則退出*/ cout請輸入數(shù)據(jù):endl; coutstr; /*編號不唯一提示錯誤*/ coach* h1=getcoach();/*調出大客車車庫中信息*/ for(k=0;kn1;k+) if(h1k.

14、number=str) cout該編號已經(jīng)存在.endl;i-;flag=1;break; /*i減1,保證添加的循環(huán)次數(shù)不會因無效輸入而少一次*/ free(h1);/*釋放空間*/ sedan* h2=getsedan();/*調出小轎車車庫中信息*/ if(flag=0) for(k=0;kn2;k+) if(h2k.number=str) cout該編號已經(jīng)存在.endl;i-;flag=1;break; /*i減1,保證添加的循環(huán)次數(shù)不會因無效輸入而少一次*/ free(h2);/*釋放空間*/ if(flag=0) truck* h3=gettruck();/*調出卡車車庫中信息*

15、/ for(k=0;kn3;k+) if(h3k.number=str) cout該編號已經(jīng)存在.N) n1-; cout車輛信息庫已滿!endl; break; c.number=str; c.getcar(); coutc.apacity; c.setall(); ofstream os1(file1.dat,ios:binary|ios_base:app); os1c.number c.license_plat pany c.time_buying c.mode c.ODO c.oil_consumption c.oil_price c.road_tolt c.all_cost c.ap

16、acity ; cout添加成功!N) cout車輛信息庫已滿!endl; break; s.number=str; s.getcar(); couts.CTNS; s.setall(); ofstream os2(file2.dat,ios:binary|ios_base:app); os2s.number s.license_plat pany s.time_buying s.mode s.ODO s.oil_consumption s.oil_price s.road_tolt s.all_cost s.CTNS ; cout添加成功!N) cout車輛信息庫已滿!endl; break

17、; cout請輸入數(shù)據(jù):endl; coutt.number; t.number=str; t.getcar(); coutt.load_weight; t.setall(); ofstream os3(file3.dat,ios:binary|ios_base:app); os3t.number t.license_plat pany t.time_buying t.mode t.ODO t.oil_consumption t.oil_price t.road_tolt t.all_cost t.load_weight ; cout添加成功!endl; os3.close(); return

18、(0);/*/void query()/*查詢函數(shù)*/ int x,flag=0; string str; cout請輸入查詢方式(退出輸入0): endl; cout*endl; cout* 1 公司查詢 2 編號查詢 3 類別查詢 *endl; cout*x; /*按公司查詢或按編號查詢*/ if(x=1)|(x=2) int i; if(x=1) cout請輸入公司: ; else coutstr; coach* c=getcoach();/*查找大客車文件*/ for(i=0;in1;i+) /*輸出符合的數(shù)據(jù)*/ if(ci.number=str) ci.show();flag=1;

19、break;/*編號查找,因為編號唯一,只有一個數(shù)據(jù)符合*/ if(pany=str) ci.show(); free(c);/*釋放空間*/ if(flag=0)/*如果編號數(shù)據(jù)已找到不進行下面操作*/ sedan* s=getsedan();/*查找小轎車文件*/ for(i=0;in2;i+) /*輸出符合的數(shù)據(jù)*/ if(si.number=str) si.show();flag=1;break;/*編號查找,因為編號唯一,只有一個數(shù)據(jù)符合*/ if(pany=str) si.show(); free(s);/*釋放空間*/ if(flag=0)/*如果編號數(shù)據(jù)

20、已找到不進行下面操作*/ truck* t=gettruck();/*查找卡車文件*/ for(i=0;in3;i+) /*輸出符合的數(shù)據(jù)*/ if(ti.number=str) ti.show();flag=1;break;/*編號查找,因為編號唯一,只有一個數(shù)據(jù)符合*/ if(pany=str) ti.show(); free(c);/*釋放空間*/ if(flag=0) cout未找到信息,輸入錯誤!endl;/*未找到符合的數(shù)據(jù)輸出錯誤*/ /*按類別查詢*/ if(x=3) int i,j; couti; switch(i) case 1: coach* c1=getco

21、ach(); for(j=0;jn1;j+) c1j.show(); free(c1);/*釋放空間*/ break; case 2: sedan* s1=getsedan(); for(j=0;jn2;j+) s1j.show(); free(s1);/*釋放空間*/ break; case 3: truck* t1=gettruck(); for(j=0;jn3;j+) t1j.show(); free(t1);/*釋放空間*/ break; default: coutERROR:input error!endl; /*/void show()/*顯示函數(shù)*/ int i=0; cout*

22、endl; cout編號 車牌號 制造公司 購買時間 型號 總公里數(shù) 油耗 油價 養(yǎng)路費 累計 特有屬性endl; cout*endl; coach* c=getcoach();/*查找大客車文件*/ for(i=0;in1;i+)/*輸出數(shù)據(jù)*/ ci.show(); free(c); sedan* s=getsedan();/*查找小轎車文件*/ for(i=0;in2;i+)/*輸出數(shù)據(jù)*/ si.show(); free(s); truck* t=gettruck();/*查找小轎車文件*/ for(i=0;in3;i+)/*輸出數(shù)據(jù)*/ ti.show(); free(s); /*/

23、void handle(int x)/*構建函數(shù),對車庫信息進行處理,包括修改和刪除*/ string str; int i,j,k=0,l;if(x=0) cout輸入要編輯車的編號:;if(x=1) coutstr;coach* c=getcoach();sedan* s=getsedan();truck* t=gettruck();if(x=0) int p=0; for(i=0;in1;i+)/*查找數(shù)據(jù)*/if(ci.number=str) j=i; k=1; /*輸入新數(shù)據(jù)*/ cout請輸入新的完整數(shù)據(jù):endl; coutci.number;ci.getcar(); coutc

24、i.apacity; ci.setall(); coach* h=getcoach(); for(l=0;l1) cout此編號已存在,重新輸入!;handle(0); if(p=1)/*編號唯一,新數(shù)據(jù)存入文件*/ ofstream os1(file1.dat,ios:binary|ios_base:trunc); for(l=0;ln1;l+) os1cl.number cl.license_plat pany cl.time_buying cl.mode cl.ODO cl.oil_consumption cl.oil_price cl.road_tolt cl.all_co

25、st cl.apacity ; os1.close(); if(k=0)/*如果數(shù)據(jù)已修改不進行下面的程序*/ for(i=0;in2;i+) if(si.number=str) /*查找數(shù)據(jù)*/ j=i; k=1; /*輸入新數(shù)據(jù)*/ cout請輸入新的完整數(shù)據(jù):endl; coutsi.number; si.getcar(); coutsi.CTNS; si.setall(); sedan* h=getsedan(); for(l=0;l1) cout此編號已存在,重新輸入!;handle(0); if(p=1)/*編號唯一,新數(shù)據(jù)存入文件*/ ofstream os2(file2.dat

26、,ios:binary|ios_base:trunc); for(l=0;ln2;l+) os2sl.number sl.license_plat pany sl.time_buying sl.mode sl.ODO sl.oil_consumption sl.oil_price sl.road_tolt sl.all_cost sl.CTNS ; os2.close(); if(k=0)/*如果數(shù)據(jù)已修改不進行下面的程序*/ for(i=0;in3;i+)if(ti.number=str) /*查找數(shù)據(jù)*/ j=i; k=1; /*輸入新數(shù)據(jù)*/ cout請輸入新的完整數(shù)據(jù):en

27、dl; coutti.number;ti.getcar(); coutti.load_weight; ti.setall(); truck* h=gettruck(); for(l=0;l1) cout此編號已存在,重新輸入!;handle(0); if(p=1)/*編號唯一,新數(shù)據(jù)存入文件*/ Ofstream os3(file3.dat,ios:binary|ios_base:trunc); for(l=0;ln3;l+) os3tl.number tl.license_plat pany tl.time_buying tl.mode tl.ODO tl.oil_consump

28、tion tl.oil_price tl.road_tolt tl.all_cost tl.load_weight ; os3.close(); if(k=0) coutERROR:編號錯誤.endl; if(x=1)for(i=0;in1;i+)/*查找大客車信息庫*/ if(ci.number=str) k=1,j=i;break;ofstream os1(file1.dat,ios:binary|ios:app);for(i=0;in1;i+)/*刪除數(shù)據(jù)*/ if(i!=j) os1ci.number ci.license_plat pany ci.time_buying

29、ci.mode ci.ODO ci.oil_consumption ci.oil_price ci.road_tolt ci.all_cost ci.apacity ; if(i=j) n1-;cout刪除成功!endl;/*刪除數(shù)據(jù)成功,信息庫信息數(shù)量減一*/ os1.close(); if(k=0)/*已刪除數(shù)據(jù)則不進行下面程序*/ for(i=0;in2;i+)/*查找小轎車信息庫*/ if(si.number=str) k=1,j=i;break;ofstream os2(file2.dat,ios:binary|ios:app);for(i=0;in2;i+)/*刪除數(shù)據(jù)*/ if(i!=j) os2si.number si.license_plat pany si.time_buying si.mode si.ODO si.oil_consumption si.oil_price si.road_tolt si.all_cost si.CTNS ; if(i=j) n2-;cout刪除成功!endl;/*刪除數(shù)據(jù)成功,信息庫信息數(shù)量減一*/ os2.close(); if(k=0)/*已刪除數(shù)據(jù)則不進行下面程序*/ for(i=0;in3;i+)/*查找小轎車信息庫*/ if(ti.number=str) k=1,j=i;break;ofstream os

溫馨提示

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

評論

0/150

提交評論