#include<iostream>
using namespace std;
class System;
class money{ //定义钱类
public:
money(double b) {balance=b;}
void check_balance(); //查询余额函数
void save_money(); //存钱函数
void draw_money(); //取钱函数
private:
double balance; //数据成员:余额
};
class account{ //定义账户类
public:
account(int n,int p)
{
number=n;
password=p;
}
void change_password();
protected:
int number; //账号
int password; //密码
int time;
};
class System:public money,public account{
public:
System(double b,int n,int p):money(b),account(n,p)
{
balance=b;
number=n;
password=p;
}
void Interface();
void office(System &s);
void log(System &s);
protected:
double balance;
int number;
int password;
};
void money::check_balance()
{
cout<<"您的余额为:"<<balance<<endl;
}
void money::save_money()
{
int sel=1;
while(sel)
{
int s;
cout<<"请输入您要存储的金额数:"<<endl;
cin>>s;
if(s%100!=0) cout<<"对不起,请输入整百的金额"<<endl;
else {balance+=s;cout<<"存入成功!"<<endl<<"您的剩余金额为:"<<balance<<endl;sel=0;}
}
}
void money::draw_money()
{
int w=1;
while(w)
{
int d;
cout<<"请输入您要提取的金额:"<<endl;
cin>>d;
if(d%100!=0) cout<<"对不起,请输入整百的金额"<<endl;
else if(d>balance) cout<<"对不起,余额不足!"<<endl;
else if(d>5000) cout<<"对不起,每次取款金额不能超过5000!"<<endl;
else { balance-=d;cout<<"剩余金额:"<<balance<<endl;w=0;}
}
}
void account::change_password()
{
int pa;
time=0;
while(time<3)
{
cout<<"请输入当前密码:"<<endl;
cin>>pa;
if(password==pa)
{
int p1,p2,stop=1;
while(stop)
{
cout<<"请输入六位密码:"<<endl;
cin>>p1;
cout<<"请再次输入六位密码:"<<endl;
cin>>p2;
if(p1==p2)
{
password=p1;
cout<<"修改成功!请牢记密码。"<<endl;
stop=0;
time+=3;
}
else cout<<"两次输入的密码不相同,请重新输入!"<<endl;
}
}
else cout<<"密码不正确,请重新输入:"<<endl;
time++;
}
if(time==3) {system("cls");cout<<"您已连续输入三次密码错误,再见!"<<endl;
system("pause");exit(1);}
}
void System::Interface()
{
cout<<"\n\n\n"
<<"\t\t **********欢迎使用!**********"<<endl
<<"\t\t 1. 查询余额 "<<endl
<<"\t\t 2. 取款 "<<endl
<<"\t\t 3. 存款 "<<endl
<<"\t\t 4. 修改密码 "<<endl
<<"\t\t 0. 退出登陆 "<<endl
<<"\t\t 请输入服务选项: "<<endl;
}
void System::office(System &s)
{
int jx=1;
while(jx)
{
system("cls");
cout<<"\n\n\n"
<<"\t\t ******欢迎使用!******"<<endl
<<"请输入账号:"<<endl;
int n,p;
int select;
int again=1;
char t;
cin>>n;
time=0;
while(time<3)
{
if(s.number==n)
{
cout<<"请输入密码:";
cin>>p;
if(s.password==p)
{
while(again)
{
system("cls");
Interface();
cin>>select;
switch(select)
{
case 1:money::check_balance();break;
case 2:money::draw_money();break;
case 3:money::save_money();break;
case 4:account::change_password();;break;
case 0:System::log(s);
default:cout<<"输入错误,请重新输入"<<endl;system("pause");
continue;
}
cout<<"是否继续?(y/n)";
cin>>t;
cout<<endl;
if(!(t=='Y'||t=='y'))
again=0;
}
}
else {cout<<"密码错误,请重新输入:"<<endl;time++;}
}
else {cout<<"没有该用户,请核对后再输入!"<<endl<<"是否继续?(y/n)";
char c;
cin>>c;
if(!(c=='Y'||c=='y'))
exit(1);
if(c=='Y'||c=='y') break;}
}
if(time==3)
{
system("cls");
cout<<"对不起,您已连续三次输入密码错误,再见!"<<endl;
system("pause");
exit(1);
}
}
}
void System::log(System &s)
{
s.office(s);
}
int main()
{
System s1(10000,123456,000000);
s1.office(s1);
system("pause");
return 0;
}
课程设计:ATM机模拟系统
最新推荐文章于 2022-06-20 17:02:13 发布