设计并实现简单的银行存取款系统,系统主界面包括登录和注册两个选项,选择登录,提示用户输入银行帐号和密码,验证通过后进入主界面,主界面包括:存款、取款、查询余额、历史记录、修改密码等功能。注册功能让用户输入账号和密码,在注册时要验证账号是否已经存在。所有数据能够保存在文件中,退出系统后再次运行系统,之前注册的用户和存款信息都存在。
#include
#include
#include
#include
using namespace std;
struct user;
typedef user T;
queue uu;
int count=0;
struct user
{
string id;
string pass;
int n;
double *money;
user() {}
user(string id,string pass,int n,double *money):id(id),pass(pass),n(n),money(money) {}
};
int gongshow();
int gong(string newid);
int save(string newid, string newpass);
int setid(string newid,string newpass);
int main()
{
system("color 0A");
while(1)
{
int m;
string newid,newpass;
cout << "\t\t\t *************************" << endl;
cout << "\t\t\t *Bank Simulation Program*" << endl;
cout << "\t\t\t *************************" << endl;
cout << "\t\t\t * *" << endl;
cout << "\t\t\t * 1.LOG IN *" << endl;
cout << "\t\t\t * 2.ENROLL *" << endl;
cout << "\t\t\t * 3.ESC *" << endl;
cout << "\t\t\t * *" << endl;
cout << "\t\t\t *************************" << endl<
cout << "\t\t\t Please enter the serial number:";
cin >> m;
if(m==3)
return 0;
system("cls");
cout << "\t\t\t *************************" << endl;
cout << "\t\t\t *Bank Simulation Program*" << endl;
cout << "\t\t\t *************************" << endl<
cout << "\t\t\t ID:";
cin >> newid;
cout << "\t\t\t PASSWORD:";
cin >> newpass;
int x=save(newid,newpass);// id 1 password 0 no_id 2
if(m==1)
if(x==1)
{
cout << "\t\t\t LOGIN SUCCESSFUL";
system ("pause>nul");
system("cls");
while(1)
{
if(gong(newid)==0) break;
int x=save(newid,newpass);
system ("pause>nul");
system("cls");
}
}
else if(x==2)
{
cout << "\t\t\t ACCOUNT DOS'T EXIST";
system ("pause>nul");
system("cls");
}
else
{
cout << "\t\t\t WRONG PASSWORD";
system ("pause>nul");
system("cls");
}
else if(m==2)
{
if(x==2)
{
if(setid(newid,newpass))
{
cout << "\t\t\t ENROLL SUCCESS";
while(1)
{
while(!uu.empty()) uu.pop();
int x=save(newid,newpass);
system ("pause>nul");
system("cls");
if(gong(newid)==0) break;
}
}
else
{
cout << "\t\t\t ENROLL FAILURE";
system ("pause>nul");
system("cls");
}
}
else if(x==1)
{
cout << "\t\t\t ACCOUNT ALREADY EXISTS";
system ("pause>nul");
system("cls");
}
system("cls");
}
}
return 0;
}
int gongshow()
{
cout << "\t\t\t *************************" << endl;
cout << "\t\t\t *Bank Simulation Program*" << endl;
cout << "\t\t\t *************************" << endl;
cout << "\t\t\t * *" << endl;
cout << "\t\t\t * 1.DPOSIT *" << endl;
cout << "\t\t\t * 2.WITHDRAWALS *" << endl;
cout << "\t\t\t * 3.CHECK BALANCES *" << endl;
cout << "\t\t\t * 4.HISTORY RECORD *" << endl;
cout << "\t\t\t * 5.CHANGE PASSWORD *" << endl;
cout << "\t\t\t * 6.ESC *" << endl;
cout << "\t\t\t * *" << endl;
cout << "\t\t\t *************************" << endl;
cout << endl << "\t\t\t Please enter the serial number:";
int n;
cin >>n;
return n;
}
int gong(string newid)
{
int n=gongshow();
if(n==2||n==1||n==5)
{
fstream f("ios.txt",ios::out);
if(n==1)
{
double n=0;
cout << "\t\t\t Enter deposit amount:";
cin >> n;
while(!uu.empty())
{
if(uu.front().id==newid)
{
f<
for(int i=0; i
{
f<< uu.front().money[i]<
}
f<< uu.front().money[uu.front().n-1]+n<< endl;
cout << "\t\t\t Deposit has been successful";
}
else
{
f<
for(int i=0; i
{
f<< uu.front().money[i]<
}
f<
}
uu.pop();
count--;
if(count==1)
uu.pop();
}
}
if(n==2)
{
double n=0;
cout << "\t\t\t Enter the withdrawal amount:";
cin >> n;
while(!uu.empty())
{
if(uu.front().id==newid&&uu.front().money[uu.front().n-1]-n>=0)
{
f<
for(int i=0; i
{
f<< uu.front().money[i]<
}
f<< uu.front().money[uu.front().n-1]-n<< endl;
f<< endl;
cout << "\t\t\t Withdrawals success";
}
else if(uu.front().id!=newid)
{
f<
for(int i=0; i
{
f<< uu.front().money[i]<
}
f<
}
else if(uu.front().id==newid&&uu.front().money[uu.front().n-1]-n<0)
{
f<
for(int i=0; i
{
f<< uu.front().money[i]<
}
f<
cout << "\t\t\t INSUFFICIENT BALANCE\n";
}
uu.pop();
count--;
if(count==1)
uu.pop();
}
}
else if(n==5)
{
string newpass;
cout << "\t\t\t Please enter a new password:";
cin >> newpass;
while(!uu.empty())
{
if(uu.front().id==newid)
{
f<
for(int i=0; i
{
f<< uu.front().money[i]<
}
f<< uu.front().money[uu.front().n-1]<< endl;
}
uu.pop();
count--;
if(count==1)
uu.pop();
}
cout << "\t\t\t PASSWORD RESET COMPLETE\n";
}
f.close();
}
else if(n==3)
{
while(!uu.empty())
{
if(uu.front().id==newid)
{
cout << "\t\t\t BALANCES:" << uu.front().money[uu.front().n-1]<
}
uu.pop();
}
}
else if(n==4)
{
while(!uu.empty())
{
if(uu.front().id==newid)
{
cout<
for(int i=1; i
{
cout<
double difference=uu.front().money[i]-uu.front().money[i-1];
if(difference>0)
cout<
cout<
}
if(uu.front().n==1) cout<
}
uu.pop();
}
}
else if(n==6)
{
system("cls");
return 0;
}
return 1;
}
int save(string newid, string newpass)
{
count=0;
int flog=2;
fstream fi;
fi.open("ios.txt",ios::in);
if(!fi)
{
fi.open("ios.txt",ios::out);
fi.close();
fi.open("ios.txt",ios::in);
}
while(!fi.eof())
{
double *money=new double;
user a;
fi >> a.id >> a.pass >> a.n;
if(a.id==newid)
if(a.pass==newpass)
flog=1;
else
return 0;
for(int j =0; j
{
fi >> money[j];
}
a.money=money;
uu.push(a);
count++;
}
fi.close();
return flog;
}
int setid(string newid,string newpass)
{
fstream fi("ios.txt",ios::app|ios::out);
int n=1;
double x=0.0;
fi<< newid << ' ' << newpass << ' ' << n << ' ' << x <
fi.close();
return 1;
}
到这里就写完了 :) .