1、 采用文件的重新写入来实现存取款。四、程序的一些设计的技巧以及注意情况:为了使程序模块化,我们要采用多文件的开发。也就是说,为了使程序简练,把一些需要重复利用的代码写到.h 的文件里面。五、代码实现:#include stdafx.h#include mapstacksstreamstdio.hwindows.hstdlib.hfstreamvectoralgorithmWelcome_UI.hRegister_UI.hSign_UI.hSecondary_UI.husing namespace std;class Bank_Managementprivate: string new_name
2、; string pre_name; int password; double extra_money;public: void creat_user(string name, int pass); int sign_user(string name, int pass); double account_balance(); void withdraw_money(); void query_account(); void change_password();Bank_Management operation1024;ofstream Rec_history(Historical record
3、s.txt, ios:in | ios:out | ios:app);int main_ui() printf(nn);tt %cWelcome to use Bank Management System!%cn, 3, 3);ttt %cCopyright by SunYu_peng!, 4, 4);ttt%c+ + + + + + + + + + + + + + + +%cnttt+ Here is the system menu! +nttt+ +nttt+ 1.Deposit money +nttt+ 2.Withdraw money +nttt+ 3.Query balance +n
4、ttt+ 4.Historical records +nttt+ 5.Change password +nttt+ 6.Save and exit +ntt Please enter the order that you want: int order; cin order; if (order = 1) system(cls operation0.account_balance(); else if (order = 2) operation0.withdraw_money(); else if (order = 3) operation0.query_account(); else if
5、(order = 4) printf(nnnn Secondary_ui();tAll dates have been saved in the file(Historical records.txt) Sleep(5000); else if (order = 5) operation0.change_password(); else if (order = 6) Rec_history The user decided to exit the system!n; return 0; elseThe user has done a wrong operation!The system exi
6、ted!void Bank_Management:creat_user(string name, int pass) new_name = name; password = pass;int Bank_Management:sign_user(string name, int pass) ifstream OpenFile(User name and password.txt string get_name; int get_pass; stack sign; stringstream n; string pass_str; n pass_str; while (OpenFile get_na
7、me get_pass) stringstream temp; string temp_str; temp temp_str; string all_str = get_name + + temp_str; sign.push(all_str); while (sign.size() != 0) if (name + + pass_str = sign.top() pre_name = name; Rec_history The user : name has landed in the System. return true; else sign.pop(); OpenFile.close(
8、);double Bank_Management:account_balance() Secondary_ui();tt Please enter the money that you want ot deposit: double _money; _money; ifstream Deposit_money(Account balance.txt map Deposit_Money; :iterator it; string temp; while (Deposit_money temp extra_money) if (temp = pre_name) extra_money = extr
9、a_money + _money; temp has deposited _money Yuann Deposit_Money.insert(pair(temp, extra_money); Deposit_money.close(); ofstream DepositMoney( for (it = Deposit_Money.begin(); it != Deposit_Money.end(); it+) DepositMoney first tsecond extra_money = extra_money - _money;Rec_history User :has withdrawe
10、d Withdraw_Money.insert(pair Withdraw_money.close(); ofstream WithdrawMoney( for (it = Withdraw_Money.begin();= Withdraw_Money.end(); WithdrawMoney WithdrawMoney.close();query_account() ifstream Read_only( double extra; cout extra) cout extra endl; Read_only.close(); Rec_history change_password;ttPl
11、ease enter the new password you want: double new_pass; new_pass; pass) pass = new_pass; change_password.insert(pair(temp, pass); ofstream res_pass( for (it = change_password.begin();= change_password.end(); res_pass The user pre_name if (order = 1) printf(tt Please enter the previous users name: cin
12、 name;tt Please enter previous users password: password; if (operation0.sign_user(name, password) = 1) system( main_ui( ); else printf(tSorry,you have done a wrong operation!Please restart the system again! an Rec_history The user whose name is has failed to enter the system.n Sleep(1000); else if (
13、order = 2) system( register_ui(); ofstream Cre_user; Cre_user.open( ofstream Ini_account; Ini_account.open(tt Please enter the users quantity you want : creat_num; for (int i = 0; itt Please enter the %d-user Cre_user password Ini_account 0 The system has created a user whose name is The system has initialized s accountn Cre_user.close(); Ini_account.close();tWe have saved all operations! Sleep(1000); else if (order = 3) return 0;
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2