(增加密码修改的功能)
#include<iostream>
//#define PASSWORD 199109
using namespace std;
//void show ( );
//void getmima (int *p);
void reset_password();
int is_correct();
void show_func();
int function( int number);
void showbalance();
void drawmoney();
void showdeposit();
void showtransfer();
int password;
/************************************************************
*增加修改密码的功能
*************************************************************/
int main(void)
{
// int mima[6];
int cnt;
int func;
int end;
password=199109;
cnt=0;
// show(); //显示“您好!欢迎使用ATM,请输入6位密码
// getmima (mima) ; //获取密码值,并显示
while(! is_correct())
{
cnt++;
if(cnt==3)
{cout<<"密码已输入错误三次,账户已锁定,24时小时内不得使用!"<<endl;
return 0;
}
}
reset_password();
while(end)
{
show_func(); // 显示对应的功能;
cout<<"请输入功能号:";
cin>>func;
end=function(func); //根据对应功能号选择对应功能
}
while(1) ; //让画面定格住
return 0;
}
/******************************************
void show ( )
{
cout<<"您好!欢迎使用BBT自动取款机!!"<<endl;
cout<<"请输入您的密码:";
}
void getmima (int *p)
{
int i;
for(i=0; i<6; i++)
{
cin>>p[i];
}
p[i]='\0';
}
**************************************************/
void reset_password()
{
char choice;
int p1,p2;
do
{
cout<<"修改密码? y or n\n";
cin>>choice;
if(choice=='y')
{
cout<<"\n请输入你的密码:";
cin>>p1;
cout<<"\n请确认您的密码:";
cin>>p2;
if(p1==p2)
{
password=p1; //重置密码
cout<<"恭喜您,重置密码成功!\n" ;
break;
}
else
cout<<"对不起,您输入密码有误,请重新输入\n";
continue;
}
else break;
}while(1);
}
int is_correct()
{
int pass_word;
cout<<"请输入密码:";
cin>>pass_word;
cout<<endl;
if(pass_word!=password)
{
cout<<"错误,请重新输入!"<<endl;
return 0;
}
else
return 1;
}
void show_func()
{
int number_func;
cout<<"功能选项:"<<endl;
cout<<"1.查询"<<endl;
cout<<"2.取款"<<endl;
cout<<"3.存款"<<endl;
cout<<"4.转账"<<endl;
cout<<"0.退出"<<endl;
}
int function( int number)
{
switch(number)
{
case 1:
showbalance();
return 1;
case 2:
drawmoney();
return 1;
case 3:
showdeposit();
return 1;
case 4:
showtransfer();
return 1;
case 0:
cout<<"谢谢~欢迎下次使用~"<<endl;
return 0;
default:
cout<<"您输入的功能不存在,请重新输入!"<<endl;
return 1;
}
}
/*****************
*显示余额
******************/
void showbalance ()
{
cout<<" 您的余额为5000元"<<endl;
}
/**********************************************88888
*存款
*功能:完成取款:要求输入金额、存期,然后计算利息(税就不扣了),输出应该取出多少钱,在屏幕上显示本金xxxx.xx元,利息xx.xx元
*利率:活期 0.50%
3个月 3.10%
6个月 3.30%
一年 3.50%
二年 4.40%
三年 5.00%
五年 5.50%
**************************************************/
void drawmoney()
{
int money;//本金
int time_deposit;//存期
float interest; //利息
cout<<"请输入存款金额,存期"<<endl;
cout<<"活期-0\n三个月-1\n6个月-2\n一年-3\n两年 -4\n三年-5\n五年-6\n" ;
cin>>money>>time_deposit;
switch(time_deposit)
{
case 0:
interest=(float)money*0.50/100.00;
break;
case 1:
interest=(float)money*3.10/100.00;
break;
case 2:
interest=(float)money*3.30/100.00;
break;
case 3:
interest=(float)money*4.40/100.00;
break;
case 4:
interest=(float)money*5.00/100.00;
break;
case 5:
interest=(float)money*5.50/100.00;
break;
default:
cout<<"您输入有误!"<<endl;
break;
}
cout<<"您的本金有"<<money<<"\n利息:" <<interest<<endl;
}
/***************
*存款
******************/
void showdeposit()
{
cout<<"请注意核对存款账号和金额"<<endl;
}
/*********************
* 汇款
**********************/
void showtransfer()
{
cout<<"请注意核对汇款账号和金额"<<endl;
}