用C++模拟ATM柜员机程序
发布网友
发布时间:2022-04-23 14:34
我来回答
共1个回答
热心网友
时间:2023-06-22 02:42
现写了一个,可运行,你看看有问题没有。
#include <iostream>
#include <string>
using namespace std;
class Users //账户类
{
private:
string name;
int balance;
string pwd;
public:
Users();
void face();
string getname();
string getpwd();
int getbalance();
void readba();//余额查询
void gep();//存款
void draw();//取款
void changepwd();
};
Users::Users()
{
name="123456";
pwd="123456";
balance=10000;
}
int Users::getbalance()
{
return balance;
}
string Users::getname()
{
return name;
}
string Users::getpwd()
{
return pwd;
}
void Users::readba()
{
cout<<"您的余额为:\t"<<balance<<"元\n";
}
void Users::gep()
{
int money;
cout<<"请输入您的存款金额:\n";
cin>>money;
if(money>0)
{
balance+=money;
cout<<"您已存入"<<money<<"元。\n";
}
else
cout<<"不可存入负值!\n";
}
void Users::draw()
{
int money;
cout<<"请输入您的提款金额\t(单位100元):\n";
cin>>money;
if(money*100>balance)
{
cout<<"不可透支!\n";
return;
}
if(money>=0 && money<=50)
{
balance-=(money*100);
cout<<"您已取出"<<money*100<<"元。\n";
}
else if(money<0)
{
cout<<"不可取出负值!\n";
}
else if(money>50)
{
cout<<"每次取款额不得超过5000元!\n";
}
}
void Users::changepwd()
{
string temp,temp0,temp1;
cout<<"请输入旧密码:\n";
cin>>temp;
if(temp==pwd)
{
cout<<"输入新密码(密码长度不低于6):\n";
cin>>temp0;
cout<<"请再次输入新密码:\n";
cin>>temp1;
if(temp0==temp1)
{
pwd=temp1;
}
else
{
cout<<"前后两次密码不符,修改失败!\n";
}
}
else
{
cout<<"密码错误!\n";
}
}
void Users::face()
{
int c;
cout<<"您好!欢迎使用ATM!\n";
while(1)
{
cout<<"-------------------------------------------------------------------\n";
cout<<"请选择服务:\n";
cout<<"【1】提款\t\t【2】存款\n【3】余额查询\t\t【0】退出\n";
cin>>c;
switch(c)
{
case 0:
return;
case 1:
draw();
break;
case 2:
gep();
break;
case 3:
readba();
break;
default:
cout<<"无效指令!请重新选取!\n";
break;
}
}
}
int main()
{
Users user;
user.face();
return 0;
}