MFC模拟自动取款机

框架:MFC
语言:C++

##(二)模拟自动取款机

1.问题描述

模拟银行的自动取款机ATM使用过程中的界面和用户交互过程。

2.基本要求

  • (1)模拟自动取款机的流程,实现查询银行卡余额、取款、修改密码、退出系统等功能。
  • (2)卡号和密码错误时最多输入3次,否则直接退出系统。
  • (4)系统通过必要的提示信息,提示用户完成相应的操作。
  • (5)取款金额受到信用卡余额、ATM机单笔最大取款金额和ATM当前剩余余额的限制。

3.实现提示

  • (1)设计ATM机类,具有核对密码,取款、修改密码、查询信息、退出系统、锁机吞卡等功能。
  • (2)银行卡具有身份验证、查询余额、修改密码、交易成功更改余额等工作。

源码预览

  • 数据结构
#include <vector>
#include "pch.h"class ATMCore {
public:ATMCore() : m_amount(0), m_max(5000) {}public:void load(const CString& filename) {CFile file;if (file.Open(filename, CFile::modeRead | CFile::typeBinary)) {CArchive ar(&file, CArchive::load);int count;ar >> count;ar >> m_amount;ar >> m_max;m_customers.clear();for (int index = 0; index < count; ++index) {Customer customer;customer.load(ar);m_customers.push_back(customer);}}}void save(const CString& filename) const {CFile file;if (file.Open(filename, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary)) {CArchive ar(&file, CArchive::store);int count = (int)m_customers.size();ar << count;ar << m_amount;ar << m_max;for (vector<Customer>::const_iterator iter = m_customers.begin(); iter != m_customers.end(); ++iter) {iter->save(ar);}}}Customer* login(const CString& id, const CString& password) {Customer* customer = find(id);if (customer) {if (customer->m_password == password) {return customer;}}return NULL;}bool deposit(const CString& id, double money) {Customer* customer = find(id);if (customer && money > 0) {customer->m_amount += money;m_amount += money;return true;}return false;}bool withdrawal(const CString& id, double money) {Customer* customer = find(id);if (customer && money > 0 && money <= customer->m_amount && money <= m_amount && money <= m_max) {customer->m_amount -= money;m_amount -= money;return true;}return false;}double getAmount() const {return m_amount;}void setAmount(double amount) {m_amount = amount;}double getMax() const {return m_max;}void setMax(double max) {m_max = max;}bool add(const CString& id, const CString& name, const CString& password) {if (find(id)) return false;Customer customer(id, name, password);m_customers.push_back(customer);return true;}Customer* find(const CString& id) {for (vector<Customer>::iterator iter = m_customers.begin(); iter != m_customers.end(); ++iter) {if (iter->m_id == id) {return &*iter;}}return NULL;}private:double m_amount;double m_max;vector<Customer> m_customers;
};
  • 对话框

// ATMDlg.cpp : implementation file
//#include "pch.h"
#include "framework.h"
#include "ATM.h"
#include "ATMDlg.h"
#include "afxdialogex.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endif// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogEx
{
public:CAboutDlg();// Dialog Data
#ifdef AFX_DESIGN_TIMEenum { IDD = IDD_ABOUTBOX };
#endifprotected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support// Implementation
protected:DECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{CDialogEx::DoDataExchange(pDX);
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()// CATMDlg dialogCATMDlg::CATMDlg(CWnd* pParent /*=nullptr*/): CDialogEx(IDD_ATM_DIALOG, pParent), m_core(NULL), m_user(NULL)
{m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CATMDlg::DoDataExchange(CDataExchange* pDX)
{CDialogEx::DoDataExchange(pDX);
}BEGIN_MESSAGE_MAP(CATMDlg, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON_MODIFY, &CATMDlg::OnBnClickedButtonModify)ON_BN_CLICKED(IDC_BUTTON_IN, &CATMDlg::OnBnClickedButtonIn)ON_BN_CLICKED(IDC_BUTTON_OUT, &CATMDlg::OnBnClickedButtonOut)
END_MESSAGE_MAP()// CATMDlg message handlersBOOL CATMDlg::OnInitDialog()
{CDialogEx::OnInitDialog();// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != nullptr){BOOL bNameValid;CString strAboutMenu;bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);ASSERT(bNameValid);if (!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);}}// Set the icon for this dialog.  The framework does this automatically//  when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);          // Set big iconSetIcon(m_hIcon, FALSE);     // Set small icon// TODO: Add extra initialization hereSetDlgItemText(IDC_EDIT_ID, m_user->m_id);SetDlgItemText(IDC_EDIT_NAME, m_user->m_name);SetDlgItemText(IDC_EDIT_PASSWORD, m_user->m_password);SetDlgItemInt(IDC_EDIT_AMOUNT, (int)m_user->m_amount);return TRUE;  // return TRUE  unless you set the focus to a control
}void CATMDlg::OnSysCommand(UINT nID, LPARAM lParam)
{if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialogEx::OnSysCommand(nID, lParam);}
}// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.void CATMDlg::OnPaint()
{if (IsIconic()){CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);// Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icondc.DrawIcon(x, y, m_hIcon);}else{CDialogEx::OnPaint();}
}// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CATMDlg::OnQueryDragIcon()
{return static_cast<HCURSOR>(m_hIcon);
}void CATMDlg::OnBnClickedButtonModify() {// TODO: Add your control notification handler code hereCString password;GetDlgItemText(IDC_EDIT_PASSWORD, password);password.Trim();if (password.GetLength() == 0) {AfxMessageBox(TEXT("密码不能为空!"));return;}if (m_user->m_password != password) {m_user->m_password = password;m_core->save(ATM_DB);AfxMessageBox(TEXT("密码修改成功!"));} else {AfxMessageBox(TEXT("请输入新密码!"));}
}void CATMDlg::OnBnClickedButtonIn() {// TODO: Add your control notification handler code hereint money;money = GetDlgItemInt(IDC_EDIT_MONEY);if (money <= 0) {AfxMessageBox(TEXT("请输入存款金额!"));return;}if (m_core->deposit(m_user->m_id, money)) {m_core->save(ATM_DB);SetDlgItemText(IDC_EDIT_MONEY, TEXT(""));SetDlgItemInt(IDC_EDIT_AMOUNT, (int)m_user->m_amount);AfxMessageBox(TEXT("存款成功!请查看余额变化。"));} else {AfxMessageBox(TEXT("存款失败!"));}
}void CATMDlg::OnBnClickedButtonOut() {// TODO: Add your control notification handler code hereint money;money = GetDlgItemInt(IDC_EDIT_MONEY);if (money <= 0) {AfxMessageBox(TEXT("请输入取款金额!"));return;}if (m_core->withdrawal(m_user->m_id, money)) {m_core->save(ATM_DB);SetDlgItemText(IDC_EDIT_MONEY, TEXT(""));SetDlgItemInt(IDC_EDIT_AMOUNT, (int)m_user->m_amount);AfxMessageBox(TEXT("取款成功!请查看余额变化。"));} else {AfxMessageBox(TEXT("取款失败!(可能原因:1 账户余额不足! 2 ATM机余额不足! 3 超出单笔取款最大金额!)"));}
}void CATMDlg::OnOK() {// TODO: Add your specialized code here and/or call the base class
}

源码下载


链接:源码下载链接
提取码:1111

MFC模拟自动取款机相关推荐

  1. Python游戏编程(十六)模拟自动取款机

    模拟自动取款机,数据临时存放在变量列表中,实现一个取款机上的存取款模拟效果,包括登录.退出.查询余额.取款和存款功能. 目录 (一)设置账号信息列表 (二)showAccout(accout,pass ...

  2. mfc模拟自动登录QQ[查找单机版连连看的剩余方块]

    #pragma once #include "atltypes.h" // CGameModifyDlg 新建一个单文档对话框无菜单的项目. /*mfc模拟按键打开桌面的qq登陆器 ...

  3. 程序设计java银行自动取款机_模拟自动取款机系统(JAVA)

    import java.io.*; /*该类为实现客户信息及部分功能*/ class Account { private String code =null; private String name ...

  4. 自动取款机流程模拟C语言的实现

    C语言实现自动取款机的流程,锻炼对文件操作的理解和结构体的 运用,和对程序的组织能力,VC++6.0环境,win 7操作系统 . 代码如下: #include<stdio.h> #incl ...

  5. 虚拟自动取款机ATM设计(C语言)

    1.设计一个模拟自动取款机ATM,有常用的功能 2.常用的功能有:用户输入密码登录界面:取款界面:取款后的取款金额以及剩余显示,退出功能等等 3.程序执行的命令包括:(1)输入正确密码进入主登录页面 ...

  6. atm机编程java_如何用Java编写模拟ATM取款机的程序

    /** * @version 1.0 * @author Devil_Angel * 该程序的功能为实现模拟银行ATM自动取款机提款,查询等功能. * */ import Java.io.*; /*该 ...

  7. 模拟atm取款机 php,C语言模拟ATM自动取款机系统

    C语言实验报告 题目名称:C语言模拟ATM自动取款机系统 一:问题描述: C语言模拟实现ATM自动取款机功能:输入密码,余额查询,取款,存款,转账,修改密码,退出功能: 代码实现的功能: 账号及密码输 ...

  8. C语言ATM自动取款机系统项目的设计与开发

    文章目录 基于C语言的ATM自动取款机系统项目设计与开发 一.ATM自动取款机系统功能分析与介绍 二.开发ATM自动取款机系统的工具以及创建项目的过程 2.1.本项目使用Visual Studio 2 ...

  9. java初级atm取款机,java基础:模拟ATM取款机

    package com.atm; import java.util.Scanner; /** * ATM类实现 * * @author 向往的生活 */ public class ATM { publ ...

最新文章

  1. javaweb学习总结(二十四):jsp传统标签开发
  2. java mset_Java 反射机制(包括组成、结构、示例说明等内容)
  3. 【JAVA 第四章 流程控制语句】课后习题 直线斜率 以及判断坐标是否在直线上点到直线的距离
  4. 理想更新“货车并线预警”遭用户吐槽 李想:仍在优化
  5. linux如何抓取本地socket,linux 本地socket
  6. 历史上的今天:阿帕网退役;Quintus 收购 Mustang;同步电流磁芯存储器获得专利...
  7. 一道很简单却也很容易入坑的java面试题
  8. -bash: mysql: command not found
  9. 图片去水印Inpaint5.2汉化破解便携版
  10. vmware 14 pro许可证
  11. 如何合并多个PDF文件?这几个小妙招快来码住吧
  12. Win10 英伟达显卡驱动安装不上,显示由于该设备有问题,Windows已将其停止,错误代码43
  13. MySql底层索引原理
  14. 如何在 Mac 上卸载 Java
  15. Python爬虫4.2 — ajax(动态网页数据抓取)用法教程
  16. java zip 读取_java读取zip (含压缩包内的文件)
  17. lager_error_logger_h dropped ~p messages in the last second that exceeded the limit of ~p messages/s
  18. 计算机网络多元化媒体传达,网页版式设计的特征及其视觉元素
  19. 孙思邈的养生十三法[转]
  20. ssh 配置使用密钥登录

热门文章

  1. 第一篇,开个好头,匠奥壁挂炉M,哈哈
  2. 数据驱动产品增长 - 收藏集 - 掘金
  3. 指令双人攻击战斗模板
  4. 项目管理PMP学习笔记一
  5. quilt-补丁工具
  6. socket源码分析之accept
  7. keepass2android 1.0.3,Keepass2Android离线版
  8. DD-WRT 中继桥接模式 配置方法
  9. Oracle关闭回收站
  10. python3.9安装wordcloud报错:ERROR: Command errored out with exit status 1: ....