用C++实现ATM机(会将信息储存到数据文件中)

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(); 
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值