1、/*银行账户管理问题描述设计一个银行账户管理程序,账户的信息有账号(唯一) 、姓名、余额、身份证号码、单位、电话号码、地址等,允许用户进行如下操作:开户、销户、存款、取款、转账、查询,一个用户可以有多个户头,账户的数值没有上限。*/#include#include #includeusing namespace std;class consumer;class YH /银行类public:void set_account();/银行开户功能void del_account(); /注销账户功能void transfer(int); /转账功能void enter_account(); /进入用
2、户个人信息功能void addmoney(int,float);/存款功能void exitYH();/ 退出系统void functionshow();void save();void load();/ 功能界面protected:consumer *account20;static int acnum;/账户数;class consumer:public YH/用户类,继承银行类的属性public:friend class YH;consumer(int id,string Name,string PassWord,float m)ID=id;name=Name;money=m;passw
3、d=PassWord;consumer()ID=0;name=0;money=0;passwd=0;int get_id()return ID;void savemoney();/ 取钱string get_passwd()return passwd;/ 取得密码void display(); void fetchmoney(); /取钱void change_passwd(); void add_money(float);void dec_money(float);float get_money();/卡卡转帐private:int ID; /开户帐号string passwd; / 用户密
4、码string name; / 用户姓名 float money; /开户金额;void YH:save()ofstream ofile(“bankdat.dat“,ios:out);ofstream outfile(“bankdat.dat“,ios:out);int n=0;outfileIDmoneynamepasswdacnum;for(n=0;nid;infilem;infilenam;infilepassw;accountn-passwd;consumer * acc = new consumer(id,nam,passw,m); accountn = acc; infile.cl
5、ose();coutid; int flag = 1; int i = 0; while(iget_id() flag = 0; else i+; if(flag) coutb;while(bb;if(accountx-get_money()dec_money(b);accounti-add_money(b);return;/*账户金额计算*/void consumer:add_money(float x)money=x+money;void consumer:dec_money(float x)money=money-x;void YH:addmoney(int x,float y)acco
6、untx-money=accountx-money-y;float consumer:get_money()return money;void main()YH yh;yh.functionshow();/*主界面显示*/void YH:functionshow()int n;dosystem(“cls“); load();coutn;while(n4) coutn;switch(n)case 1: set_account();/开户break;case 2:enter_account();/登录break;case 3: del_account();/注销break;case 4: exit
7、YH();/退出break;cin.get();while(true);void YH:enter_account()int id; coutid; int flag = 1; int i = 0; /_page_break_while(iget_id() flag = 0; else i+; if(flag) coutpassw;if(passw!=accounti-get_passwd() return;accounti-display();cin.get();cin.get();int n;dosystem(“cls“); coutn;switch(n)case 1: accounti-
8、display();break;case 2: accounti-fetchmoney();save();break;case 3:accounti-savemoney();save();break;case 4:accounti-change_passwd();save();break;case 5:transfer(i);save();break;case 6:return;cin.get();cin.get();while(1);void YH:set_account()int id;string nam;string passw;float m;coutid;coutnam;coutp
9、assw;coutm;while(mm;consumer * acc = new consumer(id,nam,passw,m); accountacnum = acc; coutid;int flag = 1; int i = 0; while(iget_id() flag = 0; else i+; if(flag) coutpwd;coutrepwd;if(pwd!=repwd)cout“m;while(mm;if(moneych;while(ch!=nwhile(ch=y|ch=Y);void consumer:savemoney()/存钱函数功能实现float c;char ch;
10、docout“c;while(cc;money=money+c;coutch;while(ch!=nwhile(ch=y|ch=Y);int YH:acnum=0;void consumer:display()/用户信息界面system(“cls“); cout“#“endl;cout“#“endl;cout“# 用户姓名:“nameendl;cout“#“endl;cout“# 帐号: “IDendl;cout“#“endl;cout“# 余额: “moneyendl;cout“#“endl;cout“# 按输入键回到上一菜单“endl;cout“#“endl;cout“#“endl;cout“;void YH:exitYH()/退出系统coutendl“感谢您对本银行的支持 ,欢迎下次光临!“endl;exit(0);