个人银行账户管理的C++程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include
#include
#include
#include
using namespace std;
class consumer;
class YH
{
public:
YH();
void set_account();
//银行开户
void del_account();
void transfer(int); //转账
void enter_account();
void addmoney(int,float);
void exitYH();// 退出系统
void functionshow();

void save();
void load();// 功能界面
protected:
consumer *account[20];
static int acnum;
//账户数

};
int YH::acnum=0;
YH::YH()
{
//for(int i=0;i<20;i++)
//{
//account[i] = NULL;
//}
}

class consumer:public YH
{
public:
friend class YH;
consumer(int id,string Name,string PassWord,float m)
{
ID=id;name=Name;money=m;passwd=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; // 用户密码
string name; // 用户姓名
float money;

};

void YH::save()
{ofstream ofile("bankdat.dat",ios::out);
ofstream outfile("bankdat.dat",ios::out);
int n=0;
outfile<for(;n{outfile<ID<<" ";
outfile<money<<" ";
outfile<name<<" ";
outfile<passwd<<" ";
}
outfile.close(); //__page_break__
}

void YH::load()
{ifstream infile("bankdat.dat",ios::in);
if(!infile)
{cerr<<"读取错误,无资料中!"<return;
}
int n=0;
int id,m;
string nam,passw;
infile>>acnum;
for(;n{infile>>id;
infile>>m;
infile>>nam;
infile>>passw;account[n]->passwd;
consumer * acc = new consumer(id,nam,passw,m);
account[n] = acc;
}
infile.close();
cout<<"读取资料正常!"<}

void YH::transfer(int x)
{int id;
cout<<"请输入帐号:";
cin>>id;
int flag = 1;
int i = 0;
while((i{
if(id==account[i]->get_id()) flag = 0; else i++;
}
if(flag)
{
cout<<"帐号不存在!"<return ;
}
float b;

cout<cin>>b;
while(b<=0)
{
cout<<"请输入正确的数字!"<cout<<"$>";
cin>>b;
}
if(account[x]->get_money()else {account[x]->dec_money(b);account[i]->add_money(b);
cout<<"转帐成功!";}



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)
{account[x]->money=account[x

]->money-y;
}
float consumer::get_money()
{return money;}


void main()
{YH yh;
yh.functionshow();
}


void YH::functionshow()
{
int n;
do
{system("cls"); load();
cout<cout<<"1) 用户开户"<cout<<"$>";
cin>>n;
while(n<1||n>4)
{
cout<<"请输入正确的操作序号!"<cout<<"$ >";
cin>>n;
}
switch(n)
{
case 1: set_account();
break;
case 2:enter_account();break;
case 3: del_account();
break;
case 4: exitYH();
break;
}
cin.get();
}
while(true);
}

void YH::enter_account()
{int id;
cout<<"请输入帐号:";
cin>>id;
int flag = 1;
int i = 0; //__page_break__
while((i{
if(id==account[i]->get_id()) flag = 0; else i++;
}
if(flag)
{
cout<<"帐号不存在!"<return;
}
cout<<"请输入密码:";
string passw;
cin>>passw;
if(passw!=account[i]->get_passwd()) return;
account[i]->display();cin.get();cin.get();
int n;
do{system("cls");
cout<<"请选择你要进行的操作:"<
cin>>n;

switch(n)
{case 1: account[i]->display();break;
case 2: account[i]->fetchmoney();save();break;
case 3:account[i]->savemoney();save();break;
case 4:account[i]->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;

cout<cin>>id;
cout<cin>>nam;
cout<cin>>passw;
cout<cin>>m;
while(m<=0)
{
cout<<"请输入正确的数字!"<cin>>m;
}
consumer * acc = new consumer(id,nam,passw,m);
account[acnum] = acc;
cout<<"开户成功!!"<acnum++;
save();
cin.get();
return;

}

void YH::del_account()
{
int id;
cout<cin>>id;
int flag = 1;
int i = 0;
while((i{
if(id == account[i]->get_id())
{
flag = 0;
}
else
{
i++;
}
}
if(flag)
{
cout<<"帐号不存在!"<return;
}
for(int j=i;j{
account[j] = account[j+1];
}
account[acnum-1]=NULL;
acnum--;
cout<<"注销成功!!"<save();
cin.get();
return;
}


void consumer::change_passwd()
{
string pwd,repwd;
cout<<"请输入新密

码:";
cin>>pwd;
cout<<"请再输入一次新密码:";
cin>>repwd;
if(pwd!=repwd)
cout<<"你输入的两次密码不一样,请重新输入!"<
passwd=pwd;
cout<<"密码修改成功,请牢记!"<}

void consumer::fetchmoney()
{
float m;
char ch;
do
{
cout<"<cin>>m;
while(m<=0)
{
cout<<"请输入正确的数字!"<cout<<"$>";
cin>>m;
}
if(money{
cout<<"对不起,你的余额不足!"
<}
else
{money=money-m;
cout<<
}
cout<<"是否要继续该项操作:(Y/N) "
<cout<<"$ >";
cin>>ch;
while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y')
{
cout<<"$ >";
cin>>ch;
}
}while(ch=='y'||ch=='Y');
}

void consumer::savemoney()
{
float c;
char ch;
do
{
cout<"<cin>>c;
while(c<=0)
{
cout<<"请输入正确的数字!"<cout<<"$>";
cin>>c;
}
money=money+c;
cout<<"操作已成功!"<cout<<"是否要继续该项操作:(Y/N) "<cout<<"$ >";
cin>>ch;
while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y')
{
cout<<"$ >";
cin>>ch;
}
}while(ch=='y'||ch=='Y');
}


void consumer::display()
{system("cls");
cout<<"**********************************"<cout<<"*"<cout<<"* 用户姓名:"<cout<<"* 帐号: "<cout<<"* 余额: "<cout<<"**********************************"<}

void YH::exitYH()
{
cout<exit(0);
}

相关文档
最新文档