linux ATM自定取款机简单实现


首先是在linux地下实现的,创建了四个文件,主要实现流程:

注册-登陆-存款-取款-转账-更改密码-查询个人信息-显示全部账户-退出系统

废话不多说,直接看代码:

Blank.h


#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <pthread.h>
using namespace std;

#define MAX_SIZE 65535
//互斥锁的初始化
static pthread_mutex_t mutex_lock=PTHREAD_MUTEX_INITIALIZER;

//定义用户的两种状态,在线和已注销
enum STATUS{ONLINE,LOGOUT};

//有一个缺点注销后的账号不能再使用

struct user
{
    string _name; //用户名
    string _id;  //身份证
    string _block_name; //卡号
    string _passwd;    //密码
    int _money;     //存的钱
    int _total_money; // 总共余额
//    STATUS status;   //用户的状态

    void insert_user(const string &name="",const string &id="",const string &block_name="",\
	    const string &passwd="",int money=0)
    {
	_name=name;
	_id=id;
	_block_name=block_name;
	_passwd=passwd;
	_money=money;
	_total_money=money;
	//status=ONLINE;
    }
    bool operator !=(const user &s)
    {
	return (strcmp(_block_name.c_str(),(s._block_name).c_str())!=0);
    }
};
//注册--》登陆--》存款--》取款--》查询--》显示全部信息--》更改密码--》注销用户--》退出系统
class Bank
{
    private:
	user value_user;
	vector<struct user> vector_user;
    private:
	Bank(const Bank &b);
	Bank& operator=(const Bank &b);
    public:
	Bank()
	{}
	~Bank() {}
	bool operator !=(const user &s)
	{
	    return value_user.operator!=(s);
	}
    public:
	//转账
	bool transfer_account(const string& block_name,const int number)
	{
	    string tmp_block_name;
	    cout<<"please enter block_name:";
	    fflush(stdout);
	    cin>>tmp_block_name;
	    string passwd;
	    cout<<"please enter passwd:";
	    fflush(stdout);
	    cin>>passwd;
	    vector<struct user>::iterator tmp=Find(tmp_block_name,passwd);
	    if(tmp !=vector_user.end())
	    {
		if(tmp->_total_money <number)
		{
		    cout<<"余额不足"<<endl;
		    return false;
		}
		vector<struct user>::iterator it=Find(block_name);
		pthread_mutex_lock(&mutex_lock); //加锁
		tmp->_total_money-=number;
		it->_total_money+=number;
		pthread_mutex_unlock(&mutex_lock);//解锁
		return true;
	    }
	    return false;
	}
	//注销用户  注销后的账号不能再次使用
	bool logout(const string &block_name,const string &passwd)
	{
	    vector<struct user>::iterator tmp=Find(block_name,passwd);
	    if(tmp !=vector_user.end())
	    {
		vector_user.erase(tmp);
		return true;
	    }
	    return false;
	}
	//更改密码
	bool c
  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值