//*******************************************
//银行自助存取款系统
//吴金笛
//161320302
//2014年5月10日
//备注:运行程序前需建立名为history的文本文件
//*******************************************
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<string.h>
using namespace std;
const char filename[]="history.txt";
class bank
{
private:
char *password;
static char word[7];
float qukuan,cunkuan;
static float yue;
static int times;
public:
bank(float q=0,float c=0,char *n="000000")
{
qukuan=q;
cunkuan=c;
password=new char[strlen(n)+1];
strcpy(password,n);
}
~bank()
{
delete []password;
}
void setpassword(char *p) //输入密码
{
strcpy(password,p);
}
bool panduanpassword() //判断密码
{
bool a=true;
for(int i=0;i<=strlen(password);i++)
if(password[i]!=word[i])
a=false;
return a;
}
bool panduan() //判断取款时余额是否足够
{
bool a=false;
if(qukuan<=yue)
a=true;
return a;
}
void setqukuan(float q)
{
qukuan=q;
}
void setcunkuan(float c)
{
cunkuan=c;
}
void changeword(char *a)
{
strcpy(word,a);
}
void qu()
{
yue-=qukuan;
times++;
}
void cun()
{
yue+=cunkuan;
times++;
}
float showyue()
{
return yue;
}
float showqukuan()
{
return qukuan;
}
float showcunkuan()
{
return cunkuan;
}
char *showword()
{
return word;
}
void showtimes()
{
cout<<"共交易了"<<times<<"次。"<<endl;
}
};
float bank::yue=1000; //设置余额为1000元
char bank::word[7]="123456"; //设置初始密码
int bank::times=0;
int main()
{
void show1(bank &); //显示余额功能
void show2(bank &); //取款功能
void show3(bank &); //存款功能
void show4(bank &); //显示交易历史功能
void add(fstream &,char,bank &); //向文件写交易信息功能
void show(fstream &); //读文件功能
void change(bank &); //修改密码功能
bool panduanword(char *,bank &);
bank b;
char *a;
char choose,ch;
fstream file;
file.open(filename,ios::in|ios::out|ios::app) ; //打开文件用于存储历史交易信息
if(!file)
{
cout<<"文件不存在!"<<endl;
exit(0);
}
a=new char[7];
cout<<"请输入密码:"<<endl; //输入密码并判断
cin>>a;
b.setpassword(a);
while(b.panduanpassword()==false)
{
static int k=1;
cout<<"密码输入错误,请重新输入。"<<endl;
cin>>a;
b.setpassword(a);
k++;
if(k==3)
{
cout<<"密码连续三次输入错误!"<<endl;
exit(0);
}
}
do{
cout<<"*********************************"<<endl;
cout<<"1.查询余额 2.取款 3.存款"<<endl; //选择选项进行交易
cout<<"4.历史交易 5.修改密码 6.退卡"<<endl;
cout<<"请选择1~~6选项:";
cin>>choose;
switch(choose)
{
case '1':show1(b);
add(file,choose,b);
break;
case '2':show2(b);
add(file,choose,b);
break;
case '3':show3(b);
add(file,choose,b);
break;
case '4':show4(b);
show(file);
break;
case '5':change(b);
add(file,choose,b);
break;
case '6':exit(0);
}
cout<<"继续请按Y,退出请按N。"<<endl;
cin>>ch;
}while(ch=='y'||ch=='Y');
file.close();
return 0;
}
void add(fstream &file,char choose,bank &b)
{
char *str;
str=new char[81];
switch(choose)
{
case '1':str="查询余额:RMB";
file<<str<<b.showyue()<<endl;
break;
case '2':str="取款:RMB";
file<<str<<b.showqukuan()<<endl;
break;
case '3':str="存款:RMB";
file<<str<<b.showcunkuan()<<endl;
break;
case '5':str="修改密码.";
file<<str<<endl;
break;
}
}
void show(fstream &file)
{
char data[81];
file.seekg(0L,ios::beg);
cout<<"##############################"<<endl;
while(!file.eof())
{
file.getline(data,81);
if(file.fail())
break;
cout<<data<<endl;
}
cout<<"################################"<<endl;
}
void show1(bank &b)
{
cout<<"余额是:"<<b.showyue()<<endl;
}
void show2(bank &b)
{
float money;
cout<<"请输入取款金额:"<<endl;
cin>>money;
b.setqukuan(money);
if( b.panduan()==false)
{cout<<"余额不足,请重新输入。"<<endl;
cin>>money;
b.setqukuan(money);
}
b.qu();
cout<<"取款成功!"<<endl;
}
void show3(bank &b)
{
float money;
cout<<"请输入存款金额:"<<endl;
cin>>money;
b.setcunkuan(money);
b.cun();
cout<<"存款成功!"<<endl;
}
void show4(bank &b)
{
cout<<"历史交易信息如下:"<<endl;
b.showtimes();
}
bool panduanword(char *y,bank &b) //在修改密码功能中判断密码
{
bool a=true;
for(int i=0;i<=6;i++)
if(y[i]!=b.showword()[i])
a=false;
return a;
}
void change(bank &b)
{
char *y;
y=new char[7];
cout<<"请输入原密码:"<<endl;
cin>>y;
while(panduanword(y,b)==false)
{
static int k=0;
cout<<"密码输入错误,请重新输入。"<<endl;
cin>>y;
k++;
if(k==3)
{
cout<<"密码连续三次输入错误!"<<endl;
exit(0);
}
}
cout<<"原密码输入正确,请输入新密码:"<<endl;
cin>>y;
b.changeword(y);
cout<<"请重新输入新密码以确定:"<<endl;
cin>>y;
while(panduanword(y,b)==false)
{
static int k=0;
cout<<"密码输入错误,请重新输入。"<<endl;
cin>>y;
k++;
if(k==3)
{
cout<<"密码连续三次输入错误!"<<endl;
exit(0);
}
}
cout<<"密码修改成功!"<<endl;
}
bank.zip_visual c
版权申诉
70 浏览量
2022-09-14
22:59:42
上传
评论
收藏 2KB ZIP 举报
钱亚锋
- 粉丝: 88
- 资源: 1万+
最新资源
- CISCN2024-re3-rust-baby(Frida多字节程序插桩爆破)
- soft:磁盘清理工具
- .netcore控制台使用Nssm打包windows服务,加winform管理服务界面
- db-college.sql
- wpf-dragdrop-treeview(WPF较好拖拽效果).7z
- img-1716258776282bf88540b0e387ddd2ea677d02c7f3594ad72383f796d86b02fb7d2ae2543915d.jpg
- 《伦敦共享单车数据分析与代码》
- SKIP-v2.1.1.apk
- IMG20240521103815.jpg
- 松下A4系列伺服参数调试软件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈