版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、1.1要求程序運(yùn)行時(shí),可以由用戶選擇進(jìn)行何種操作,用戶銷戶后賬號被回收,并且該賬 號可以繼續(xù)分配給其它賬戶,不允許用戶透支.開戶操作要求輸入用戶信息后自動(dòng)獲 取賬號.根據(jù)姓名或賬號可以進(jìn)行用戶的信息查詢, 所有的賬戶信息應(yīng)存放到一個(gè)文 件中,可以隨時(shí)的訪問和更新.1.2任務(wù)設(shè)計(jì)一個(gè)銀行賬戶治理程序,賬戶的信息有賬號唯一、姓名、余額、身份證 號、單位、 號、地址等,允許用戶進(jìn)行如下操作:開戶、銷戶、存款、取款、 轉(zhuǎn)賬、查詢,一個(gè)用戶可以有多個(gè)戶頭,賬戶的數(shù)值沒有上限.2分析和設(shè)計(jì)2.1系統(tǒng)分析及設(shè)計(jì)思路2.1.1類與對象類是一種復(fù)雜的數(shù)據(jù)類型,它是將不同類型的數(shù)據(jù)和與這些數(shù)據(jù)相關(guān)的操作封裝 在一
2、起的集合體.類的一般形式為:class類名protect:保護(hù)的數(shù)據(jù)和成員函數(shù) public:公用的數(shù)據(jù)和成員函數(shù)private:私有的數(shù)據(jù)和成員函數(shù) ;對象是運(yùn)行期的根本實(shí)體,它是一個(gè)封裝了數(shù)據(jù)和操作這些數(shù)據(jù)的代碼的邏輯實(shí) 體.對象的一般格式為:類名 對象名表;2.1.2成員函數(shù)的實(shí)現(xiàn)成員函數(shù)的實(shí)現(xiàn),可以放在類體內(nèi),也可以放在類體外,但必須在類體內(nèi)給出原 型說明.放在類體內(nèi)定義的函數(shù)被默認(rèn)為內(nèi)聯(lián)函數(shù), 而放在類體外定義的函數(shù)是一般 函數(shù),如果要定義為內(nèi)聯(lián)函數(shù)那么需要在前面加上關(guān)鍵字 inline.與普通函數(shù)不同的是,成員函數(shù)是屆于某個(gè)類的,在類體外定義成員函數(shù)的一半 形式為:返回類型 類名
3、:成員函數(shù) 參數(shù)說明函數(shù)體2.1.3本程序涉及的類一usersclass users根據(jù)類的定義:類是一種復(fù)雜的數(shù)據(jù)類型,它是將不同類型的數(shù)據(jù)和與這些數(shù)據(jù) 相關(guān)的操作封裝在一起的集合體.本設(shè)計(jì)的賬戶信息姓名、余額、身份證號、單 位、 號、地址等恰好可以定義成一個(gè)類一 users,偽代碼如下:賬戶類private :char id5;賬號char name9;char id_card19;char company40;char company_phone12;char moble_phone12;char address31;long balance;users *next;public :us
4、ers(ifstream &file_in);char password11;密碼賬戶名身份證號單位單位 地址余額指向下一個(gè)賬戶構(gòu)造函數(shù),同時(shí)從文件讀取賬戶數(shù)據(jù)void new_user();新建賬戶信息void put_id(int id_new);獲取賬號char *get_id();返回賬號耿款void saving();存款void saving(long money);轉(zhuǎn)入帳long virement();轉(zhuǎn)出賬;2.1.4 main函數(shù)的實(shí)現(xiàn)一個(gè)程序中main是最簡單但是最重要的函數(shù),他負(fù)責(zé)著整個(gè)程序的調(diào)用運(yùn)行, 我們設(shè)計(jì)的這個(gè)main函數(shù)思路很簡單,但是實(shí)現(xiàn)起來稍微復(fù)雜一
5、些,本想簡化一下, 可是始終沒有解決,本程序 main函數(shù)基于一個(gè)switch ()語句來實(shí)現(xiàn)各個(gè)操作的選 擇,在case后面再調(diào)用具體操作函數(shù)來實(shí)現(xiàn)操作,由于要選擇的操作比較多,所以 才顯得復(fù)雜些,具體偽代碼如下:int main()int choice;do zi_title();cin>>choice;bool blag=0;switch(choice)case 1 :cout<<-開戶-n;user = new users;user->put_id(n_id(head);user->new_user();case 2 : cout<<&q
6、uot;-銷戶-n"if(head=0)( cout<<"還沒有賬戶!建議開戶!"<<endl; break; case 3 :cout<<"存寂 n"user = u_search(head,2,0);case 4 :cout<<"-取款-n"user=u_search(head,2,0);user->take_money();break;case 5 :cout<<"-轉(zhuǎn)賬-n"case 6 :cout<<"-查詢
7、-n"cout<<"選擇查詢條件:n 1-賬戶名2-賬號3-身份證號選項(xiàng):"case 0 :f_out.open("banksystem.txt");if(f_out.fail()(cout<<"文件翻開錯(cuò)誤!"<<endl;exit(1);default :cout<<"沒有該選項(xiàng)! "<<endl;break;while(choice);cout<<"謝謝使用! "<<endl;return 0;2
8、.2主要類圖users-id5-password11-password11-name9-company40-company_phone12-moble_phone12-address31-balance+new_user()+put_id()+get_balance()+take_money()+saving()+saving()+virement()圖3.1 users類圖2.3函數(shù)流程圖開戶new_user函數(shù)流程圖如下charnew_pw11,ok_.blag=0;*i!='0'*i<='!'|*i>=''for(char *i
9、=new_pwblag=1;break;i+strcmp(new.blagcout<<"確認(rèn)密碼:"blag=1;blag=0;strcpy(password,new_pw);圖3.2開戶new_user流程圖存款users:saving函數(shù)流程圖如下:圖3.3存款users:saving流程圖轉(zhuǎn)賬users:virement函數(shù)流程圖如下:圖3.4轉(zhuǎn)賬users:virement流程圖3具體代碼實(shí)現(xiàn)#include <iostream>#include <fstream>/輸入/輸出文件流#include <iomanip>
10、/O流限制頭文件,就像C里面的格式化輸出一樣#include <cctype>#include <cstring>#include <cmath>#include <cstdlib>/ 各函數(shù)集合using namespace std;活空該行,輸入abcde回車symbol由a變成被b覆蓋,又被c覆蓋知道最后symbol只存了一個(gè)'n'void new_line()char symbol;docin.get(symbol);/輸入字符,cin 吃回車while(symbol != 'n');數(shù)字轉(zhuǎn)換到字符申voi
11、d int2str(int n, char *str)char buf10=""int i = 0;int len = 0;int temp = n < 0 ? -n: n; / temp 為 n 的絕對值if (str = NULL)return;while(temp)bufi+ = (temp % 10) + '0' /把 temp 的每一位上的數(shù)存入 buf temp = temp / 10;len = n < 0 ? +i: i; 如果n是負(fù)數(shù),那么多需要一位來存儲負(fù)號stri = 0;末尾是結(jié)束符023while(1)i-;if(buf
12、len-i-1 = 0)break;stri = buflen-i-1; 把buf數(shù)組里的字符拷到字符申如果是負(fù)數(shù),添加一個(gè)負(fù)號if (i = 0 ) ( stri='-' /該用于治理開啟程序的賬戶和密碼void safe_conduct()( int input_num=0;char un11,pw11;cout<<"請先登陸:(用戶名為:9021315密碼為:0000) "<<endl;bool blag;標(biāo)志錯(cuò)誤doblag=0;cout<<"用戶名:"cin>>un;cout<
13、;<"密碼:"cin>>pw;if(strcmp(un,"9021315")!=0)blag=1;cout<<"用戶名輸入錯(cuò)誤! "<<endl;if(!blag)if(strcmp(pw,"0000)!=0)blag=1;cout<<"用戶密碼輸入錯(cuò)誤! "<<endl;if(blag)input_num+;switch(input_num)case 1: cout<<'您還可以輸入兩次!"<<e
14、ndl; break;case 2: cout<<'您還可以輸入一次!"<<endl; break;case 3: cout<<'您沒有權(quán)限繼續(xù)輸入,程序?qū)⒁P(guān)閉!"<<endl; exit(0);while(blag);/直到正確才跳出用于治理賬戶信息class users賬戶類private :賬號密碼賬戶名身份證號單位單位 地址余額指向下一個(gè)賬戶char id5;char password11;char name9;char id_card19;char company40;char company_ph
15、one12;char moble_phone12;char address31;long balance;users *next;public :構(gòu)造函數(shù),同時(shí)從文件讀取賬戶數(shù)據(jù)重載構(gòu)造函數(shù),使之用于開戶新建賬戶信息獲取賬號users(ifstream &file_in);users() balance=0; next=NULL;void new_user();void put_id(int id_new);char *get_id(); 返回賬號char *get_password();返回賬戶名/返回身份證號返回 號返回余額取款存款轉(zhuǎn)入帳轉(zhuǎn)出賬寫入文件輸出到屏幕char *get_
16、name();char *get_id_card();char *get_mob_ph();long get_balance();void take_money();void saving();void saving(long money);long virement();void out_to_file(ofstream &file_out);void out_to_screen();得到指針返回指針void put_next(users *n);users *back_next();users:users(ifstream &file_in)file_in>>i
17、d>>name>>id_card>>company>>company_phone>>moble_phone>>addres s>>balance;next = NULL;void users:new_user() char new_pw11,ok_new_pw11;cout<<"請您輸入賬戶名:"cin>>name;bool blag;doblag=0; cout<<"請您輸入密碼:"cin>>new_pw;for(char
18、 *i=new_pw;*i!='0'i+)/ 檢查密碼是否合法(if(*i<='!'|*i>='')( blag=1;cout<<"密碼不符合標(biāo)準(zhǔn)! !請重新輸入! ! "<<endl;break;cout<<"確認(rèn)密碼:"cin>>ok_new_pw;if(strcmp(new_pw,ok_new_pw)!=0)(blag=1;cout<<"密碼不同!"<<endl;else blag=0;while(
19、blag);strcpy(password,new_pw);cout<<"請輸入您身份證號:"cin>>id_card;cout<<"請輸入您的單位:"cin>>company;cout<<"情輸入您的單位 :"cin>>company_phone;cout<<"請輸入您的 號:"cin>>moble_phone;cout<<"請輸入您的地址:"cin>>address;cou
20、t<<endl;cout<<"您申請的賬戶信息為:賬號:"<<id<<"賬戶名:"<<name<<" 身份證號:"<<id_card<<" 單位:"<<company<<" 單位 :"<<company_phone<<" 號:"<<moble_phone<<" 地址:"<<add
21、ress <<" 賬戶余額:"<<balance<<endl<<endl<<endl;void users:put_id(int id_new)(一 一char new_id5;int num;for(int i=3;i>=0;i-)數(shù)字轉(zhuǎn)換成字符申( num = id_new % 10;new_idi = num + '0'id_new /= 10;new_id4 = '0' strcpy(id,new_id);char *users:get_id()return id;ch
22、ar *users:get_password()return password; char *users:get_name() return name ; char *users:get_id_card()return id_card; char *users:get_mob_ph()return moble_phone;long users:get_balance()return balance;void users:take_money()if(balance<=0) cout<<您的余額已經(jīng)為空!無法取款!n存款后可以再??!"<<endl;retu
23、rn ;long m;/輸入取款金額bool blag;doblag=0;cout<<請輸入取款金額:"cin>>m;if(m>=balance) blag=1;cout<<"您輸入的金額大于余額,無法取出! !請重新輸入! ! "<<endl;while(blag);balance = balance - m;void users:saving()long m;bool blag;do blag=0;cout<<請輸入存款金額:"cin>>m;if(m<0)cout&l
24、t;<請正確輸入金額!"blag=1;while(blag);balance = balance + m;void users:saving(long money)(balance = balance + money;long users:virement()( long money;bool blag;do(blag=0;cout<<"請輸入要轉(zhuǎn)賬的金額 cin>>money;if(money>=balance)(cout<<"余額缺乏!請重新輸入! "<<endl;blag=1; while
25、(blag);balance = balance - money;return money; void users:out_to_file(ofstream &file_out)(file_out<<'n'<<id<<""<<name<<""<<id_card<<" "<<company<<"<<company_phone<<" "<<mo
26、ble_phone<<" "<<address<<" "<<balance; void users:out_to_screen()(cout.setf(ios:left);/ 數(shù)值從左讀起cout<<setw(6)<<"賬號:"<<id/set(6)表示設(shè)置6個(gè)空格來輸出數(shù)據(jù)<<setw(8)<<"<<setw(10)<<"<<setw(13)<<"&
27、lt;<setw(12)<<"<<setw(12)<<"<<setw(13)<<" <<setw (9) <<" <<endl;用戶名:"<<name身份證號:"<<id_card公司:"<<company公司 :"<<company_phone 號:"<<moble_phone 地址:"<<address余額:"
28、<<balancecout.setf(ios:right);void users:put_next(users *n)( next = n; users *users:back_next()(return next; 查詢:選擇查詢條件:1-賬戶名;2-賬號;3-身份證號;users *u_search(users *head,int choice,bool b=1)(users *p;bool blag=1;switch(choice)(case 0 :break;case 1 :char name9;cout<<"輸入賬戶名:"cin>&g
29、t;name;for(p=head;p!=NULL;p=p->back_next()if(strcmp(p->get_name(),name)=0)p->out_to_screen();blag=0;break;case 2 :char id5;cout<<"輸入賬號:"cin>>id;for(p=head;p!=NULL;p=p->back_next()if(strcmp(p->get_id(),id)=0)if(b) p->out_to_screen();blag=0;elsereturn p;break;ca
30、se 3 :char id_card19;cout<<"輸入身份證號:"cin>>id_card;for(p=head;p!=NULL;p=p->back_next() if(strcmp(p->get_id_card(),id_card)=0)p->out_to_screen();blag=0;break;default :cout<<"選項(xiàng)錯(cuò)誤! "<<endl; return NULL;if(blag)( cout<<"沒有該賬戶!"<<e
31、ndl; return NULL; int n_id(users *head)( int id;int now_id=0,num;users *p;char ne_id5;bool blag;for(id=0;id<=9999;id+)(blag=1;now_id = id;int2str(now_id,ne_id);數(shù)字轉(zhuǎn)換成字符申for(int i=3;i>=0;i-)數(shù)字轉(zhuǎn)換成字符申( num = now_id % 10; ne_idi = num + '0' now_id /= 10;ne_id4 = '0'遍歷,找到鏈表中不存在的賬號for
32、(p=head;p!=NULL;p=p->back_next() _if(strcmp(p->get_id(),ne_id)=0) blag = 0; break; if(blag) return id;void zi_title()cout<<""<<endl< <endl;cout<<" 1-開戶2-銷戶3-存款 4-取款5-轉(zhuǎn)賬6-查詢0-退出 <<endl<<endl; cout<<""<<endl;void title()(co
33、ut<<"歡迎使用銀行賬戶治理程序"<<endl;cout<<""<<e ndl;int main()( ifstream f_in;ofstream f_out;f_in.open("banksystem.txt");safe_conduct();users *p;users *head,整個(gè)鏈表的頭結(jié)點(diǎn)指針*user,新建賬戶指針*later,整個(gè)鏈表的尾結(jié)點(diǎn)指針*next;下一個(gè)結(jié)點(diǎn)if(f_in.peek()!=EOF)( head = new users(f_in);user
34、= later = head;for(;f_in.peek()!=EOF;)(next = new users(f_in);user->put_next(next);later = next; elsehead=NULL;f_in.close();int choice;do( zi_title();cin>>choice;bool blag=0;switch(choice)(case 1 :cout<<"-開戶-n"user = new users;user->put_id(n_id(head);user->new_user();i
35、f(head=NULL)head = user;elselater->put_next(user);later = user;break;case 2 :cout<<"-銷戶-n"if(head=0) cout<<"還沒有賬戶!建議開戶! "<<endl; break; char id_5;cout<<"請輸入要銷戶的賬號:;cin>>id_; 刪除鏈表中的結(jié)點(diǎn)next = head;if(strcmp(head->get_id(),id_)=0)head = head-&
36、gt;back_next();delete next;blag=1;elsefor(user=head;user!=NULL;user=user->back_next()if(strcmp(user->get_id(),id_)=0) next->put_next(user->back_next();blag=1;delete user;break;next=user;if(blag)cout<<"刪除成功! "<<endl;elsecout<<"沒有該賬戶! "<<endl;bre
37、ak;case 3 :cout<<"寂n"user = u_search(head,2,0);user->saving();break;case 4 :cout<<"-取款-n"user=u_search(head,2,0); user->take_money();break;case 5 :cout<<"-轉(zhuǎn)賬-n"cout<<"轉(zhuǎn)出:n<<*;user = u_search(head,2,0);cout<<"W入:n"<<*;next = u_search(head,2,0);next->
溫馨提示
- 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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 山西省山大附中高三9月月考語文試題(含答案)
- 智研咨詢發(fā)布-2024年中國可降解塑料行業(yè)產(chǎn)業(yè)鏈全景分析及發(fā)展趨勢預(yù)測報(bào)告
- 二零二五年度綠色能源項(xiàng)目委托投標(biāo)合作協(xié)議3篇
- 項(xiàng)目式學(xué)習(xí)在初中英語閱讀教學(xué)中的應(yīng)用研究
- 2025版物業(yè)管理企業(yè)清潔服務(wù)外包委托合同3篇
- 建筑市政工程質(zhì)量安全第三方巡查方案
- 高端餐飲銷售工作總結(jié)
- 二零二五年度個(gè)人信息保密與數(shù)據(jù)安全保障合同3篇
- 二零二五年度汽車制造廠行車維修保障協(xié)議2篇
- 物流行業(yè)運(yùn)輸安全管理總結(jié)
- 2024版全文:中國2型糖尿病預(yù)防及治療指南
- 社會主義發(fā)展史(齊魯師范學(xué)院)知到智慧樹章節(jié)答案
- 課程思政融入高職院校應(yīng)用文寫作課程教學(xué)路徑探析
- 2024全新鋼結(jié)構(gòu)安全培訓(xùn)
- 2025屆高三數(shù)學(xué)一輪復(fù)習(xí)-分段函數(shù)專項(xiàng)訓(xùn)練【含答案】
- 《工程力學(xué)》課程教學(xué)大綱
- 7.1.2 直觀圖的畫法-【中職專用】高一數(shù)學(xué)教材配套課件(高教版2021·基礎(chǔ)模塊下冊)
- 皮膚癬菌病的分子診斷工具
- SL+575-2012水利水電工程水土保持技術(shù)規(guī)范
- 人美版初中美術(shù)知識點(diǎn)匯總八年級全冊
- 迅雷網(wǎng)盤最最最全影視資源-持續(xù)更新7.26
評論
0/150
提交評論