




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、南京理工大學(xué)C+課程設(shè)計報告姓名:謝記超課程設(shè)計題目:個人財政支由管理( A級)程序功能簡介:將個人財物的目標(biāo)及當(dāng)前存款、支出保存下來,可隨時更新查看,比 較盈余與目標(biāo)的差距。設(shè)計要求:(1)將收支的數(shù)據(jù)與相應(yīng)的函數(shù)封裝到類中,并改寫主程序,使程序結(jié)構(gòu)化。(2)增加保存每筆收支的記錄,并對每筆記錄增加日期錄入,按日期順序保存查 看記錄。將所有記錄放入一個文件中,每次運(yùn)行程序時首先打開這個文件, 程序運(yùn)行完畢時將更新的記錄放回文件中。(3)完善程序,補(bǔ)充類中數(shù)據(jù)成員(dlbalance)的計算和輸出,要求每筆收入和支出 都要重新統(tǒng)計當(dāng)前情況下的盈余數(shù)目。(4)增加程序監(jiān)控功能,當(dāng)輸入時間發(fā)生錯誤
2、(如月份超過十二),要求重新輸入 正 確的時間;當(dāng)結(jié)余數(shù)目為負(fù)數(shù)時輸出信息,警告已超支。對題目的分析,以及功能的實(shí)現(xiàn)關(guān)鍵的四個類l.class CFince 數(shù)據(jù)類 2.class CNode 結(jié)點(diǎn)類3.class CList 鏈表類 4.class CRecord 處理類兩個函數(shù)1 .判斷日期是否正確的函數(shù) 2. main ()函數(shù)實(shí)現(xiàn)如下功能2 .程序的結(jié)構(gòu)化,將各函數(shù)封裝到類中。3 .數(shù)據(jù)的保存與讀取。4 .數(shù)據(jù)的處理,用相應(yīng)函數(shù)實(shí)現(xiàn)5 .優(yōu)化處理,界面美觀,人性化提示,數(shù)據(jù)輸入的監(jiān)控3、 程序設(shè)計過程中遇到的問題與解決方法1. 開始做出的程序添加收入與支出記錄是未進(jìn)行日期檢查,導(dǎo)致不實(shí)
3、際的日期也被錄入。對于日期的檢查用了函數(shù)IsDateRight 來實(shí)現(xiàn),其中應(yīng)用了if 語旬,switch語句幫助實(shí)現(xiàn)該功能。2. 數(shù)據(jù)的保存與讀取開始實(shí)現(xiàn)不了,保存下來的數(shù)據(jù)格式不正確,打不開,再次運(yùn)行時上次的數(shù)據(jù)也未能讀取。最終在class CRecord 處理類中添加voidReadFromFile(刖void SaveToFile()實(shí)現(xiàn)了這個功能,里面用到了輸入輸出流 ifstream和ofstream,實(shí)現(xiàn)數(shù)據(jù)的保存與再次讀取是很高興的,最令人興奮的 是關(guān)閉程序后可以在文本文件中看到收支記錄!3. 數(shù)據(jù)類 結(jié)點(diǎn)類 鏈表類 數(shù)據(jù)處理類的編寫是很復(fù)雜的,環(huán)環(huán)相扣,數(shù)據(jù)類、節(jié)點(diǎn)類是基礎(chǔ),
4、鏈表類將數(shù)據(jù)串起來,然后再用數(shù)據(jù)處理類中的函數(shù)處理鏈表中的數(shù)據(jù)!這四大類真是讓人費(fèi)勁心思!當(dāng)時實(shí)現(xiàn)這個生產(chǎn)鏈時,那是相當(dāng)有成就感的!4. 如何區(qū)分開收入與支出記錄輸出,當(dāng)時困擾了我很久,實(shí)在不希望不能實(shí)現(xiàn)收入記錄與支出記錄的分開顯示,后來發(fā)覺可以通過判斷函數(shù)的值來判斷該筆記錄是收入還是支出,最終實(shí)現(xiàn)了查看收入記錄則只顯示收入記錄,查看支出記錄只顯示支出記錄。5. 累計計算余額,實(shí)現(xiàn)超支預(yù)警,void CRecord:ViewBalance()list.ShowList();if(list.GetLastNode()-GetData()-GetBalance()0)cout您的財政已超支!abC
5、; ; 獲取時間,在Dos 屏幕中輸入2012 8 5 100而入的的100會被下一次cind;獲得(即被當(dāng)做收入獲得)如何在取得相應(yīng)數(shù)據(jù)后清空為取得的數(shù)據(jù)?cin.ignore cin.sync cin.ignore 都不行。3 .入 與支出的用途在Dos 屏幕中只能輸入英文,不能輸入漢語,如果這個程序用MFC 編程來編寫效果會更好!4 .操 作未實(shí)現(xiàn),有時候運(yùn)行次數(shù)過多就會在評上留下很多東西,DOS 屏幕會顯亂。5、 程序演示截圖gj/ig囂ar目標(biāo)dLPuirpuse 一記事本文件的編定格式查看的幫助包?100E收支記錄finance記事本文件偏輯心格式查看9幫助QD2012 8 1 6
6、0 0 jiangxuejin2012 8 2 0 20 meal2012 8 3 100 6 price2012 8405。 bookcostc C:Docwnervts and Settingsnlg桌面912104210329 謝記超Debugd 9 2 2序12程20上n:以收 擇霸選:金: 霸入源? 日收來功 入入入成 H 請請請?zhí)怼O典涗涗浂?迎歡請選擇以上程序,2請輸入日期:(例如,2012 2 292012 8 2請掩入支山金就20請輸入支出用連;meal添加成功? 2012 8 3:2012 8 3收入:100支出0用途:price目標(biāo):100 歡迎使用個人財政胃理系統(tǒng)畜選理
7、以下朝葡G 1:崎入 加 入汩錄y2P12 2 292M2 8 6L 0支出9。用途tC假支記錄f irtaiwu -記事本文件 編輯 格式)查看。幫助的2012 9 1 60 Q jiangxuejin2012 8202。 nedl2612 8 3 1&。 B price2012 8 4 G h(mkcQ5t#include#include#include#include/函數(shù)原形說明bool IsDateRight(int,int,int);/全局靜態(tài)變量,目標(biāo)/數(shù)據(jù)類/缺省構(gòu)造函數(shù)/為日期賦值的構(gòu)造函數(shù)/比較日期大小的函數(shù)/展示該筆收支情況,包括盈余狀static double dlPu
8、rpose=0.0; class CFinanceint nYear,nMonth,nDay; double dlIncome,dlOutput; double dlBalance;char szPurpose20;double dlGap;public:CFinance();CFinance(int,int,int);int Compare(CFinance &);void Show();況void SetFinance(int,int,int,double,double,char *);/為所有成員變量賦初值的函數(shù)void Calculate(double dlBal);/累計計算總收入的
9、函數(shù)double GetBalance();void ModifyData();/修改數(shù)據(jù)的函數(shù)void SetVal(int &,int &,int &,double &,double &,char *);/獲得各成員值的函數(shù)bool IsDateEqual(int,int,int);/判斷日期是否存在void ShowWithoutBalance();/展示該筆收支情況,不包括盈余情況;CFinance:CFinance()/缺省構(gòu)造函數(shù)dlIncome=0.0;dlOutput=0.0;dlBalance=0.0;CFinance:CFinance(int year,int month,
10、int day) /為日期賦值的構(gòu)造函數(shù)nYear=year;nMonth=month;nDay=day;dlIncome=dlOutput=0.0;dlOutput=0.0;dlBalance=0.0;int CFinance:Compare(CFinance &finance)/比較日期的大小(大于取1 ,小于取-1 ,相等取0)if(nYearfinance.nYear)return 1;if(nYearfinance.nMonth)return 1;if(nMonthfinance.nDay)return 1; if(nDayfinance.nDay)return -1; if(nDa
11、y=finance.nDay)return 0;void CFinance:Show()/展示該筆收支情況,包括盈余狀況cout 日期: nYear nMonth nDay 收入: dlIncome 支 出 : dlOutput 用 途 : szPurpose 余 額 : dlBalance 目 標(biāo) : dlPurpose0)/若dlIncome0 ,修改收入數(shù)據(jù);否則修改支出數(shù)據(jù)couttemp;if(temp0)cout“修改成功!endl;dlIncome=temp;else cout 輸入有誤,修改失??!endl;elsecouttemp;if(temp0)cout“修改成功!endl
12、;dlOutput=temp;else cout 輸入有誤,修改失敗!endl;voidCFinance:SetVal(int &year,int &month,int &day,double&income,double&output,char *purpose)/獲得各成員值的函數(shù)year=nYear;month=nMonth;day=nDay;income=dlIncome;output=dlOutput;strcpy(purpose,szPurpose);bool CFinance:IsDateEqual(int year,int month,int day)/判斷日期是否存在if(nY
13、ear=year&nMonth=month&nDay=day)return true;else return false;void CFinance:ShowWithoutBalance()/展示該筆收支情況,不包括盈余情況cout 日期: nYear nMonth nDay 收入: dlIncome 支 出 dlOutput 用途: szPurpose 目標(biāo): dlPurposeShow();CFinance *CNode:GetData()return pData;class CListprotected:CNode *pHead;public:CList();CList();void A
14、ddNode(CNode *pnode);void DeleteNode(CNode *);CNode *LookUp(CFinance&);所在結(jié)點(diǎn)指針void ShowList();void DeleteList();CNode *GetListHead();CNode *GetListNextNode(CNode *);void Insert(CNode *);CNode *GetLastNode();void CalBalance();CList:CList() /構(gòu)造函數(shù)pHead=0;CList:CList()/析構(gòu)函數(shù)DeleteList();void CList:AddNode
15、(CNode *pnode)if(pHead=0)/頭指針為空/輸出本節(jié)點(diǎn)所指向的數(shù)據(jù)/獲得該節(jié)點(diǎn)所指向的數(shù)據(jù)的地址/鏈表類/定義一個CNode 的頭指針/構(gòu)造函數(shù)/析構(gòu)函數(shù)/增加結(jié)點(diǎn)/刪除制定結(jié)點(diǎn)/根據(jù)日期查找指定數(shù)據(jù),并返回該數(shù)據(jù)/輸出鏈表中的數(shù)據(jù)/刪除鏈表中的數(shù)據(jù)/獲得鏈表頭指針/返回指定結(jié)點(diǎn)的下一結(jié)點(diǎn)指針/據(jù)日期升序插入結(jié)點(diǎn)/返回尾部的頭指針/逐個結(jié)點(diǎn)計算盈余/增加結(jié)點(diǎn)pHead=pnode;pHead-pNext=0;elseGetLastNode()-pNext=pnode; pnode-pNext=0;void CList:DeleteNode(CNode *pnode)/刪除制
16、定結(jié)點(diǎn)if(!pHead)/頭指針為空,即還未建立鏈表cout“刪除結(jié)點(diǎn)錯誤:鏈表不存在!“pNext=0)/只有一個節(jié)點(diǎn)時刪除節(jié)點(diǎn)delete pHead-pData;delete pHead;pHead=0;else if(pnode=pHead)/鏈表中有多個結(jié)點(diǎn),要刪除的結(jié)點(diǎn)是頭結(jié)點(diǎn)CNode *p=pnode-pNext;delete pHead-pData;delete pHead;pHead=p;else/鏈表中有多個結(jié)點(diǎn),要刪除的結(jié)點(diǎn)是其他節(jié)點(diǎn)CNode *p=pHead;while(p&p-pNext!=pnode)p=p-pNext;if(!p)coutpNext;dele
17、te pnode-pData;delete pnode; p-pNext=q;CNode *CList:LookUp(CFinance& finance) /根據(jù)日期查找指定數(shù)據(jù),并返回該數(shù)據(jù)所在結(jié)點(diǎn)指針if(pHead=0)return 0;CNode *pn=pHead;while(pn)if(pn-pData-Compare(finance)=0)return pn; pn=pn-pNext;return 0;void CList:ShowList()/輸出鏈表中的數(shù)據(jù)if(!pHead)cout“鏈表為空ShowNode();p=p-pNext;void CList:DeleteLis
18、t()/刪除鏈表中的數(shù)據(jù)if(pHead=0)return;CNode *p,*q;p=pHead;while(p)delete p-pData;q=p;p=p-pNext;delete q;pHead=0;CNode *CList:GetListHead()/獲得鏈表頭指針return pHead;CNode *CList:GetListNextNode(CNode *pnode)/9return pnode-pNext;void CList:Insert(CNode *pnode)/按日期的升序插入結(jié)點(diǎn)CNode *p,*q;if(pHead=0)pHead=pnode;pHead-pNe
19、xt=0;return;if(pHead-pData-Compare(*(pnode-pData)=1)pnode-pNext=pHead;pHead=pnode;return;p=pHead;while(p&p-pData-Compare(*(pnode-pData)=-1)q=p;p=p-pNext;q-pNext=pnode;pnode-pNext=p;CNode *CList:GetLastNode()/返回尾部結(jié)點(diǎn)的指針(該程序未用到,用于擴(kuò)展功能)if(!pHead)return 0;CNode *p=pHead;while(p-pNext)p=p-pNext;return p;v
20、oid CList:CalBalance()/逐個結(jié)點(diǎn)計算盈余if(!pHead)return;double temp=0;CNode *p=pHead; while(p)p-pData-Calculate(temp); temp=p-pData-GetBalance(); p=p-pNext;class CRecordCList list; public:/處理記錄類/把CList 的對象 list 作為 CRecord 的子對象void ReadFromFile();void SaveToFile();void InputIncomeRecord();void InputOutputRec
21、ord();void ViewIncomeRecord();void ViewOutputRecord();void ViewBalance();超支預(yù)警/從文本文檔讀取數(shù)據(jù)/把數(shù)據(jù)寫進(jìn)文本文檔/增加收入數(shù)據(jù)/增加支出數(shù)據(jù)/展示全部收入記錄/展示全部支出記錄/展示全部收入與支出記錄,顯示盈余情況,實(shí)現(xiàn)void LookUpRecord();void EditRecord();void DeleteRecord();void setgoal(double);/根據(jù)日期尋找記錄/根據(jù)日期修改記錄/根據(jù)日期刪除記錄/設(shè)置存儲目標(biāo);void CRecord:setgoal(double goal) /
22、設(shè)置存儲目標(biāo) dlPurpose=goal;void CRecord:ReadFromFile()/從文本文檔讀取數(shù)據(jù) ifstream infile1( 目標(biāo) dlPurpose.txt);if(!infile1)cout 文件讀取失敗!dlPurpose;ifstream infile( 收支記錄finance.txt);if(!infile)cout“文件讀取失敗!yearmonthdayincomeoutputpurpose)CFinance *pfinance=new CFinance;pfinance-SetFinance(year,month,day,income,output,
23、purpose);CNode *pnode=new CNode;pnode-InputData(pfinance);list.AddNode(pnode);list.CalBalance();void CRecord:SaveToFile()/把數(shù)據(jù)寫進(jìn)文本文檔 ofstream outfile1( 目標(biāo) dlPurpose.txt);if(!outfile1)cout“文件寫入失敗!endl;exit(1);outfile1dlPurpose;ofstream outfile( 收支記錄finance.txt);if(!outfile)cout“文件寫入失敗!GetData()-SetVal
24、(year,month,day,income,output,purpose);outfileyear monthday income outputpurposeendl;p=list.GetListNextNode(p);void CRecord:InputIncomeRecord()/增加收入數(shù)據(jù)int year,month,day;double income;char purpose20;coutyearmonthday;while(!IsDateRight(year,month,day)coutyearmonthday;coutincome;coutpurpose;CFinance *p
25、finance=new CFinance;pfinance-SetFinance(year,month,day,income,0,purpose);CNode *pnode=new CNode;pnode-InputData(pfinance);list.Insert(pnode);cout 添加成功!endl;list.CalBalance();void CRecord:InputOutputRecord()/增加支出數(shù)據(jù)int year,month,day;double output;char purpose20;coutyearmonthday;while(!IsDateRight(ye
26、ar,month,day)coutyearmonthday;coutoutput;coutpurpose;CFinance *pfinance=new CFinance;pfinance-SetFinance(year,month,day,0,output,purpose);CNode *pnode=new CNode;pnode-InputData(pfinance);list.Insert(pnode);cout 添加成功!GetData()-SetVal(year,month,day,income,output,purpose); if(income0)cout 日期: year mon
27、th day 收入: income 用途: purposeGetData()-SetVal(year,month,day,income,output,purpose);if(output0)cout 日期 year month day 支出: output 用 途: purposeGetData()-GetBalance()0)cout 您的財政已超支!endl;void CRecord:LookUpRecord()/根據(jù)日期尋找記錄if(!list.GetListHead()cout“當(dāng)前沒有記錄!endl;return;int year,month,day;short mark=0;cou
28、tyearmonthday;while(!IsDateRight(year,month,day)coutyearmonthday;CNode *p=list.GetListHead();while(p)if(p-GetData()-IsDateEqual(year,month,day)p-GetData()-ShowWithoutBalance();mark=1;p=list.GetListNextNode(p); if(!mark) cout 無當(dāng)天記錄!endl;void CRecord:EditRecord()/根據(jù)日期編輯記錄if(!list.GetListHead() cout“當(dāng)前
29、沒有記錄!endl;return;int year,month,day;short mark=0,edited=0;coutyearmonthday;while(!IsDateRight(year,month,day)coutyearmonthday;CNode *p=list.GetListHead();while(p)if(p-GetData()-IsDateEqual(year,month,day)mark=1;char edit; dop-GetData()-ShowWithoutBalance();coutedit;if(edit=N|edit=n)break;elsep-GetDa
30、ta()-ModifyData();edited=1;break;while(edit!=Y&edit!=y&edit!=N&edit!=n);p=list.GetListNextNode(p);if(!mark)cout 無當(dāng)天記錄!endl;if(edited)list.CalBalance();void CRecord:DeleteRecord()/根據(jù)日期尋找記錄if(!list.GetListHead()cout“當(dāng)前沒有記錄!endl;return;int year,month,day;short mark=0,deleted=0;coutyearmonthday;while(!I
31、sDateRight(year,month,day)coutyearmonthday;CNode *p=list.GetListHead();while(p)if(p-GetData()-IsDateEqual(year,month,day)mark=1;char del;dop-GetData()-ShowWithoutBalance();coutdel;if(del=N|del=n)break; elsedeleted=1;cout“刪除成功!“endl;break;while(del!=Y&del!=y&del!=N&del!=n);CNode *q=p;p=list.GetListNextNode(p);if(deleted)list.DeleteNode(q);deleted=0;if(!mark)cout 無當(dāng)天記錄!endl; else list.CalBalance(); bool IsDateRight(int year,int month,int day)/判斷日期是否正確的函數(shù)if(year3000)return false;if(month12)return false;
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 事務(wù)處理流程優(yōu)化方案設(shè)計
- 學(xué)習(xí)實(shí)驗(yàn)室體系文件通訊稿
- 垃圾填埋場液體排放控制
- 大規(guī)模并發(fā)時的網(wǎng)絡(luò)帶寬管理
- 2025年西藏貨運(yùn)從業(yè)資格證模擬考試題庫下載
- 采石場生產(chǎn)管理合同
- 2025年武漢貨運(yùn)從業(yè)資格考試題庫答案
- 2025年南寧貨運(yùn)從業(yè)資格考試題庫答案
- 電信網(wǎng)絡(luò)優(yōu)化與升級實(shí)施方案
- 三農(nóng)村道路建設(shè)作業(yè)指導(dǎo)書
- 企業(yè)安全文化建設(shè)導(dǎo)則
- 八年級語文上冊第六單元作業(yè)設(shè)計 品格與志趣
- 鐵道游擊隊(duì)測試題6.1總1文檔資料
- 電機(jī)與電氣控制技術(shù)(第2版)全套完整教學(xué)課件
- 掘進(jìn)機(jī)液壓培訓(xùn)課件
- 農(nóng)產(chǎn)品質(zhì)量安全風(fēng)險防范措施
- 麻醉科臨床技術(shù)操作規(guī)范2022版
- 奉賢東部分區(qū)單元(FX3)地質(zhì)災(zāi)害危險性評估報告
- 現(xiàn)代企業(yè)管理專業(yè)實(shí)踐考核試題
- 支氣管鏡吸痰操作考核評分標(biāo)準(zhǔn)
- 2023年病歷書寫基本規(guī)范文
評論
0/150
提交評論