ATM模拟程序能够完成ATM的主要功能
1)显示欢迎词及提示信息;
2)用户插卡,ATM验证用户账号及密码有效性,输入错误3次即被锁卡;
3)余额查询:初始余额为10000元;
4)取款功能:每次取款余额为100的整数倍,有单笔金额限制;
5)转账功能:可将本账户中的存款转入其它账户,转入账户账号需两次输入确认;
6)修改密码:密码为6位数字,新密码需要两次输入确认;
7)退卡。
程序所涉及到的用户资料、银行帐户、存取款记录等信息保存在数据文件中。
其中银行账户的格式如下:
在此代码中,所有文件放在了一个文件夹中
main.cpp:
#include <iostream>
#include "result.h"
using namespace std;
int main()
{
customer c1("1234567891234567890", "Lancaster", "123456789123456789", "123456"); //构造一个用户
ATM atm(c1);
atm.readCard();
return 0;
}
result.h:
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
class customer
{
protected:
string name, card, password, idcard; //姓名,卡号,密码
float remain; //余额
public:
customer(std::string card, std::string name, std::string idcard, std::string password);
std::string getName(); //获取姓名
std::string getCard(); //获取卡号
std::string getPassword(); //获取密码
std::string getIDcard(); //获取身份证(为了防止卡号相同时出问题,不过银行应该不会犯这个错)
float getRemain(); //获取余额
void setRemain(int i, float pos); //设置金额
void setPassword(std::string password); //设置密码
void changeRemain(float num, bool increase); //改变存款
};
customer::customer(std::string card = "", std::string name = "", std::string idcard = "", std::string password = "")
{
this->password = password;
this->name = name;
this->card = card;
this->idcard = idcard;
}
std::string customer::getName()
{
return this->name;
}
std::string customer::getCard()
{
return this->card;
}
std::string customer::getPassword()
{
return this->password;
}
std::string customer::getIDcard()
{
return this->idcard;
}
float customer::getRemain()
{
return this->remain;
}
void customer::setRemain(int i, float pos)
{
if (i == 1)
this->remain = 10000.0;
if (i == 2)
{
this->remain = pos;
}
}
void customer::setPassword(std::string password)
{
this->password = password;
}
void customer::changeRemain(float num, bool increase)
{
if (increase)
this->remain += num;
else
this->remain -= num;
}
class ATM
{
public:
ATM(customer &cm) : cust(cm)
{
}
friend class customer;
void welcome(); //起始页面
void readCard(); //读卡
void withdrawal(); //取款
void transfer();