




已閱讀5頁,還剩20頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
算 法 與 數(shù) 據(jù) 結(jié) 構(gòu)課 程 設(shè) 計 報 告請尊重我的勞動成果不要復(fù)制! 題 目: 汽車租借公司的管理 班 級: 學(xué) 號: 姓 名: 成 績:2014年 1月 1日一、題目汽車租借公司的管理(1)問題描述設(shè)計數(shù)據(jù)結(jié)構(gòu)及算法完成某個汽車租借公司日常工作的組織與管理。該管理系統(tǒng)的基本管理對象為汽車,每臺汽車用一個license number進(jìn)行唯一標(biāo)識。每個汽車存在三種可能狀態(tài): 可以租借(available for rent) 已借(rented) 修理中(in repair) 其中在available隊列中汽車應(yīng)該依據(jù)汽車行駛過的路程進(jìn)行排序,行駛路程最少的汽車排在最前面。在rented隊列中的汽車應(yīng)依據(jù)其預(yù)期返回時間進(jìn)行排序,排在最前的應(yīng)是預(yù)期最早返回的汽車。(2)課程設(shè)計目的應(yīng)用線性數(shù)據(jù)結(jié)構(gòu)存儲信息,并能夠應(yīng)用上面的基本操作實現(xiàn)事務(wù)管理。(3)基本要求 用三個鏈表組織三種狀態(tài)的汽車。 能夠?qū)崿F(xiàn)租借的日常事務(wù):引入新車,租借,收費,修理等。 租借收費應(yīng)根據(jù)汽車行駛的路程及借去的時間綜合計算得出,路程收費標(biāo)準(zhǔn)如下: 低于100km收費20.00元 100km以外的路程每km收費0.15元 汽車根據(jù)行駛的路程定期進(jìn)行維護(hù)。 還需實現(xiàn)輔助操作:汽車查詢,打印全部信息,計算并打印收入、成本及收益。 管理系統(tǒng)應(yīng)有完整地界面(最好是圖形化界面)。(4) 實現(xiàn)提示主要集中在鏈表的基本操作上。二、設(shè)計思想1、問題分析該公司的所有車輛只有以下三種狀態(tài): 可以租借(available for rent) 已借(rented) 修理中(repairing) 一.每種狀態(tài)的都有要能夠?qū)崿F(xiàn)車輛的添加、刪除、顯示的最最基本的功能,他們里面又都有多輛車需要統(tǒng)一管理,而這些車輛無疑都是屬性相同的車輛,所以可以建立一個cars結(jié)構(gòu)體,包含他們共同的屬性。公司日常業(yè)務(wù)有添加新車,租借汽車,歸還收費、修理汽車,修理完畢,配置信息,汽車查詢,打印全部信息,計算收益。其所有功能如下: 1.添加新車,2.租借汽車,3.歸還收費、4.修理汽車,5.修理完畢,6.配置信息,7.汽車查詢,8.打印信息,9.計算收益,10.退出二.基本實現(xiàn):采用的鏈?zhǔn)浇Y(jié)構(gòu),即對鏈表的操作。另外有兩個配置文件:1.data.dat:儲存的信息有汽車編號、汽車狀態(tài)(0表示未借出,1表示借出,2表示維修中)、已行駛的路程、預(yù)期歸還的時間、借出的次數(shù)、該車的獲得的收益。2.data.ini:每輛車的成本、每次修理費、油費/km、租費(100km以下)、租費(超過100km)。三.結(jié)構(gòu)關(guān)系struct cars包含了一輛車的的基本信息: 1.汽車編號license_number(int); 2.汽車狀態(tài)0-可以租借,1-已借出,2-修理中stutes(int); 3.汽車行駛過的路程car_runned(float); 4.汽車預(yù)期返回的時間return_time(int); 5.汽車修理的次數(shù)repaired_time(int); 6.汽車收入income(float); 7.next指針struct cars *next; 四.相關(guān)函數(shù) 1.讀取data.ini配置信息的數(shù)據(jù):void ReadDataIni(); 2.設(shè)置data.ini配置信息的數(shù)據(jù):void setDataIni(); 3.將數(shù)據(jù)存檔到data.dat中:void save_data(struct cars *carData);4.追加數(shù)據(jù)存檔到data.dat中:void add_data(struct cars *carData);5.根據(jù)汽車所行駛的距離排序:struct cars *rank_Distance(struct cars *carDistance);6.根據(jù)預(yù)期返回時間排序:struct cars *rank_Time(struct cars *carTime);7.建立可以租借的鏈表:struct cars *create_available(void);8.建立已借出的鏈表:struct cars *create_rented(void);9.建立修理中的鏈表:struct cars *create_repairing(void);10.打印汽車的信息:void printThreeOfCars(struct cars *ThreeOfCar);11.計算鏈表數(shù)據(jù)個數(shù):int calculateCars(struct cars *ThreeOfCar);12.刪除鏈表中的汽車:void deleteThreeOfCar(struct cars *ThreeOfCar, int xuhao);13.插入到可以租借的車鏈表中:struct insertThreeOfCars(struct cars *ThreeOfCar,int LicenseNumber,int Stu,float CarRunned,int ReturnTime,int RepairedTime,float Ico);14.增加新車:void AddNewCar(struct cars *available,struct cars *rented,struct cars *repairing);15.出租汽車:void RentCar(struct cars *available,struct cars *rented, struct cars *repairing);16.歸還收費:void ReturnCar(struct cars *available,struct cars *rented,struct cars *repairing);17.修理汽車:void RepairCar(struct cars *available,struct cars *rented,struct cars *repairing);18.查看修理狀況:void BackCar(struct cars *available,struct cars *rented,struct cars *repairing);19.汽車查詢:void research(struct cars *ThreeOfCar, int id);20.汽車查詢結(jié)果:void ReasearchCar(struct cars *available,struct cars *rented,struct cars *repairing);21.打印所有車的信息:void PrintAllCar();22.計算收益:void Calculation(struct cars *ThreeOfCar);23.計算收益:void CalculateProfit();24.配置信息:void displaySeting();25.設(shè)置配置信息:void setInformation();三、軟件結(jié)構(gòu)圖及流程圖軟件結(jié)構(gòu)圖即函數(shù)調(diào)用圖(圖中用五號宋體)如下圖添加新車AddNewCar()創(chuàng)建3個鏈表主函數(shù)出租汽車RentCar()void RentCar歸還收費ReutrnCar()修理汽車RepairCar()修理完畢BackCar()操作選擇配置信息SetInformation()汽車查詢ReasearchCar()打印全部PrintAllCar()計算收益CalculateProfit()退出開始建立三張鏈表(可借汽車、已借汽車、修理汽車)主菜單(選擇操作)添加新車操作1租借汽車操作2歸還收費操作3修理汽車操作4操作5修理完畢操作6配置信息操作7汽車查詢打印全部操作8計算收益操作9退出操作0結(jié)束四、測試使用Visual C+ 6.0。其中,程序使用到的信息在data.dat和data.ini文件中。本程序運行后的界面如下圖所示:主界面:1.添加新車2.租借汽車3.歸還收費4.修理汽車5.修理完畢6.配置信息7.汽車查詢8.打印全部9.計算收益10.退出五、源程序#includeusing namespace std;#include#include#include#define LEN sizeof(struct cars)struct carsint license_number;/汽車編號int stutes;/汽車狀態(tài)0-可以租借,1-已借出,2-修理中float car_runned;/汽車行駛過的路程int return_time;/汽車預(yù)期返回的時間int repaired_time;/汽車修理的次數(shù)float income;/汽車收入struct cars *next;/next指針;struct cars *p1,*p2,*available,*rented,*repairing,*p,*g,*f;FILE *fp1, *fp2;/文件指針int n1 = 0, n2 = 0, n3 = 0, n4, n5;/將data.ini中的配置信息讀出來儲存在四個變量中float car_cost,repair_cost,oil_cost,rent_cost,rentkm_cost;struct cars *rank_Time(struct cars *carTime);struct cars *rank_Distance(struct cars *carDistance);/讀取data.ini配置信息的數(shù)據(jù)void ReadDataIni() fp2 = fopen(data.ini,r);fscanf(fp2,%f %f %f %f %f,&car_cost,&repair_cost,&oil_cost,&rent_cost,&rentkm_cost);fclose(fp2);/設(shè)置data.ini配置信息的數(shù)據(jù)void setDataIni()fp2 = fopen(data.ini,w); /以寫的模式打開文件fprintf(fp2,%.2f %.2f %.2f %.2f %.2f %.2f,car_cost,repair_cost,oil_cost,rent_cost,rentkm_cost);fclose(fp2);cout設(shè)置成功!license_number,p-stutes,p-car_runned,p-return_time,p-repaired_time,p-income);p = p-next;fclose(fp1);/追加數(shù)據(jù)存檔到data.datvoid add_data(struct cars *carData)p = carData;fp1 = fopen(data.dat,a); /以追加寫入的模式打開文件while(p!=NULL)fprintf(fp1,%d %d %.2f %d %d %.2fn,p-license_number,p-stutes,p-car_runned,p-return_time,p-repaired_time,p-income);p = p-next;fclose(fp1);/根據(jù)汽車所行駛的距離排序struct cars *rank_Distance(struct cars *carDistance)p=carDistance;vector sc(n1);struct cars t;int i = -1,j;while(p!=NULL)i+;sci.license_number = p-license_number;sci.stutes = p-stutes;sci.car_runned = p-car_runned;sci.income = p-income;sci.repaired_time = p-repaired_time;sci.return_time = p-return_time;p = p-next;for(i=0;in1;i+)for(j=0;jscj+1.car_runned)t = scj;scj = scj+1;scj+1 = t;p = carDistance;i = -1;while(p!=NULL)i+;p-license_number = sci.license_number;p-stutes = sci.stutes;p-car_runned = sci.car_runned;p-income = sci.income;p-repaired_time = sci.repaired_time;p-return_time = sci.return_time;p = p-next;return(carDistance);/根據(jù)預(yù)期返回時間排序struct cars *rank_Time(struct cars *carTime)p = carTime;vector sc(n2);struct cars t;int i=-1;while (p!=NULL)i+;sci.license_number = p-license_number;sci.stutes = p-stutes;sci.car_runned = p-car_runned;sci.income = p-income;sci.repaired_time = p-repaired_time;sci.return_time = p-return_time;p = p-next;for (i=0;in2;i+)for (int j=0;jscj+1.return_time)t = scj;scj = scj+1;scj+1 = t;p = carTime;i = -1;while (p!=NULL)i+;p-license_number = sci.license_number;p-stutes = sci.stutes;p-car_runned = sci.car_runned;p-income = sci.income;p-repaired_time = sci.repaired_time;p-return_time = sci.return_time;p = p-next;return (carTime);/1.建立可以租借的鏈表struct cars *create_available(void)fp1 = fopen(data.dat,r);p1 = p2 = (struct cars *)malloc(LEN);available = NULL;while(!feof(fp1)n1 = n1 + 1;fscanf(fp1,%d %d %f %d %d %f,&p1-license_number,&p1-stutes,&p1-car_runned,&p1-return_time,&p1-repaired_time,&p1-income);if(p1-stutes = 0)if(n1 = 1)available = p1;elsep2-next = p1;p2 = p1;p1 = (struct cars *)malloc(LEN);elsen1-;p2-next = NULL;fclose(fp1);/根據(jù)行駛過的路程進(jìn)行排序rank_Distance(available);return(available);/2.建立已借出的鏈表struct cars *create_rented(void)fp1 = fopen(data.dat,r);p1 = p2 = (struct cars *)malloc(LEN);rented = NULL;while(!feof(fp1)n2 = n2 + 1;fscanf(fp1,%d %d %f %d %d %f,&p1-license_number,&p1-stutes,&p1-car_runned,&p1-return_time,&p1-repaired_time,&p1-income);if(p1-stutes = 1)if(n2 = 1)rented = p1;elsep2-next = p1;p2 = p1;p1 = (struct cars *)malloc(LEN);elsen2-;p2-next = NULL;fclose(fp1);/根據(jù)行駛過的路程進(jìn)行排序rank_Time(rented);return(rented);/3.建立修理中的鏈表struct cars *create_repairing(void)fp1 = fopen(data.dat,r);p1 = p2 = (struct cars *)malloc(LEN);repairing = NULL;while(!feof(fp1)n3 = n3 + 1;fscanf(fp1,%d %d %f %d %d %f,&p1-license_number,&p1-stutes,&p1-car_runned,&p1-return_time,&p1-repaired_time,&p1-income);if(p1-stutes = 2)if(n3 = 1)repairing = p1;elsep2-next = p1;p2 = p1;p1 = (struct cars *)malloc(LEN);elsen3-;p2-next = NULL;fclose(fp1);return (repairing);/打印汽車的信息void printThreeOfCars(struct cars *ThreeOfCar)p = ThreeOfCar;cout編號t狀態(tài)t行駛路程t借出天數(shù)t維修次數(shù)t收益n;while(p != NULL)coutlicense_numbertstutestcar_runnedtreturn_timetrepaired_timetincomenext;/計算鏈表數(shù)據(jù)個數(shù)int calculateCars(struct cars *ThreeOfCar)int k = 0;p = ThreeOfCar;while(p != NULL)k+;p = p-next;return (k);/刪除汽車void deleteThreeOfCar(struct cars *ThreeOfCar, int xuhao)p = ThreeOfCar;if(xuhao = p-next-license_number)g = p-next;p-next = p-next-next;g-next = NULL;free (g);elsecout錯誤deleteThreeOfCar()!next != NULL)p = p-next;p-next=(struct cars *)malloc(LEN);p-next-license_number = LicenseNumber;p-next-stutes = Stu;p-next-car_runned = CarRunned;p-next-return_time = ReturnTime;p-next-repaired_time = RepairedTime;p-next-income = Ico;p-next-next = NULL;cout添加完成!endl;cout添加的信息是:endl;cout編號t汽車狀態(tài)t行駛路程t預(yù)期歸還時間t借出天數(shù)t收益endl;coutLicenseNumbertStutCarRunnedtReturnTimetReturnTimetIcoendl;return 0;/增加新車void AddNewCar(struct cars *available,struct cars *rented,struct cars *repairing)int ava,ren,rep,l;ava = calculateCars(available);ren = calculateCars(rented);rep = calculateCars(repairing);l = ava + ren + rep;insertThreeOfCars(available,l,0,0,0,0,0);/插入到未借出的鏈表中save_data(available);add_data(rented);add_data(repairing);/出租汽車void RentCar(struct cars *available,struct cars *rented, struct cars *repairing)int score,day = 1,i = 0;printThreeOfCars(available);cout請選擇所要租的序號!score;cout請選擇所租汽車的天數(shù)!day;p = f = available;cout可以借的汽車的信息license_number)insertThreeOfCars(rented,p-license_number,1,p-car_runned,day,p-repaired_time,p-income);deleteThreeOfCar(f, score);save_data(available); add_data(rented); add_data(repairing);break;f = p;p = p-next;while(p != NULL);coutn租借完成!endl;/歸還收費void ReturnCar(struct cars *available,struct cars *rented,struct cars *repairing)int score,i = 0;float run,money;printThreeOfCars(rented);cout請選擇所要歸還的車的序號!score;cout請輸入汽車在租借時所跑的路程!run;p = f = rented;cout要歸還的車的信息license_number)insertThreeOfCars(available,p-license_number,0,run + p-car_runned,0,p-repaired_time,p-income);deleteThreeOfCar(f, score);save_data(available); add_data(rented); add_data(repairing);break;f = p;p = p-next;while(p != NULL);coutn已歸還!endl;/修理汽車void RepairCar(struct cars *available,struct cars *rented,struct cars *repairing)int score,i = 0;printThreeOfCars(available);cout請選擇所要修理的車的序號!score;p = f = available;cout要修理的汽車的信息license_number)insertThreeOfCars(repairing,p-license_number,2,p-car_runned,0,p-repaired_time,p-income);deleteThreeOfCar(f, score);save_data(available); add_data(rented); add_data(repairing);break;f = p;p = p-next;while(p != NULL);coutn已送去修理!endl;/查看修理狀況void BackCar(struct cars *available,struct cars *rented,struct cars *repairing)int score,i = 0;printThreeOfCars(repairing);cout請選擇可以出租的修理中的汽車的序號!score;p = f = repairing;doif(score = p-license_number)insertThreeOfCars(available,p-license_number,0,p-car_runned,0,p-repaired_time + 1,p-income);deleteThreeOfCar(f, score);save_data(available); add_data(rented); add_data(repairing);break;f = p;p = p-next;while(p != NULL);coutn可以租借了!license_number)i =1;break;p = p-next;while(p != NULL);if(i = 1)cout序號為t狀態(tài)為t已行駛的路程t預(yù)期歸還時間t借出的次數(shù)t收益n;coutlicense_numbertstutestcar_runnedtreturn_timetrepaired_timetincomeendl;/汽車查詢結(jié)果void ReasearchCar(struct cars *available,struct cars *rented,struct cars *repairing)int id;cout請輸入查詢汽車的編碼:id;research(available,id);research(rented,id);research(repairing,id);/打印所有車的信息void PrintAllCar()cout可以租借的汽車:endl;printThreeOfCars(available);cout租借出去的汽車:endl;printThreeOfCars(rented);cout正在維修的車:income;if(p-car_runned car_runned =0)AllCost =AllCost + car_cost + repair_cost*p-repaired_time + oil_cost*p-car_runned + rent_cost*p-car_runned;if(p-car_runned 100)AllCost =AllCost + car_cost + repair_cost*p-repaired_time + oil_cost*p-car_runned + rent_cost*100 + rentkm_cost*(p-car_runned - 100);p = p-next;while(p != NULL);GetFree = GetMoney - AllCost;cout總收入t成本t收益endl;coutGetMoneytAllCosttGetFreeendl;/計算收益void CalculateProfit()cout可以租借的汽車收入:endl;Calculation(available);cout租借出去的汽車收入:endl;Calculation(rented);cout正在維修的車收入:endl;Calculation(repairing);/配置信息void displaySeting()cout每輛車的的成本:car_costendl;cout每次的修理費用:repair_costendl;cout每公里的油費:oil_costendl;cout100公里以內(nèi)的租用費用:rent_costendl;cout100公里以外的租用費用:rentkm_costendl;/設(shè)置配置信息void SetInformation()int i;ReadDataIni();displaySeting();cout請選擇相應(yīng)的操作!endl;cout1-修改配置信息t2-取消i
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 營銷部操作指南
- 英語重點詞匯詳解caveat
- 英語小學(xué)五年級上冊期末試題
- 出租車公司夜間運營安全保障雇傭合同
- 餐飲企業(yè)員工勞動合同與工作環(huán)境改善
- 企業(yè)歷史債務(wù)排查方案
- 高級專業(yè)技術(shù)人才標(biāo)準(zhǔn)勞動合同書
- 倉儲物流園區(qū)廠房股權(quán)轉(zhuǎn)讓及倉儲服務(wù)合作協(xié)議
- 煙囪拆除工程設(shè)計與施工質(zhì)量保證合同
- 智能辦公環(huán)境租賃與智慧城市建設(shè)合同
- 個人生意入股合同范本
- 宅基地行政執(zhí)法培訓(xùn)課件
- 靜脈的導(dǎo)管維護(hù)新進(jìn)展課件
- 工程設(shè)計與施工項目管理與質(zhì)量控制指導(dǎo)手冊
- 對房產(chǎn)評估異議申請書
- 2025年度光伏充電樁項目合作合同范本4篇
- 2025年度水利工程代建合同模板
- 云南經(jīng)濟(jì)管理學(xué)院就業(yè)協(xié)議書
- 2025年全球及中國智能艾灸服務(wù)機(jī)器人行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 九年級全一冊英語單詞默寫表(人教版)
- DB50T 990-2020 地質(zhì)災(zāi)害治理工程施工質(zhì)量驗收規(guī)范
評論
0/150
提交評論