C++ 简易 Simple_ATM_drawmoney

学c++,昨晚突发奇想,做了一了Simple_ATM_drawmoney,后续功能持续开发中
,代码如下
//Bank.h
Bank的声明
#include<string>
using namespace std;
#ifndef Bank_h
#define Bank_h
class Bank
{
protected:
	string Bankid;//银行卡号
	int Bankpassword;//密码
	int drawmoney;//要取的钱
	int savemoney;//要存入的钱
	int totalmoney;//总共的钱
public:
	Bank();
	~Bank();		
    void setBankid(string);//输入账号
	string getBankid()const;//获取账号
	void setBankpassword(int);//输入密码
	int getBankpassword()const;//获取密码
	int getdrawmoney()const;//取钱 
	void setdrawmoney(int);//输入取钱
	int getpaymoney()const;//存钱
	void setpaymoney(int);//输入存钱
	int gettotalmoney()const;//总钱
	void print()const;//输出
};
#endif
//Bank.cpp
//Bank的实现
#include<string>
#include<iostream>
//#include<stdexcept>
#include"Bank.h"
using namespace std;
int total=1000;
Bank::Bank() ://构造函数初始化
Bankid(""),
Bankpassword(-1),
drawmoney(0),
savemoney(0),
totalmoney(1000)
{}
Bank::~Bank()//析构函数
{}
void Bank::setBankid(string id)//设置账号
{
	Bankid = id;
}
string Bank::getBankid()const//返回账号
{
	return Bankid;
}
void Bank::setBankpassword(int password)//设置密码
{
	Bankpassword = password;
}
int Bank::getBankpassword()const//返回密码
{
	return Bankpassword;
}
void Bank::setpaymoney(int money)//要存的钱
{
	savemoney = money;
}
int Bank::getpaymoney()const//存钱 
{
	 total = total + savemoney;
	return total;
}
void Bank::setdrawmoney(int money)//要取的钱
{
	drawmoney = money;
}
int Bank::getdrawmoney()const//取钱
{
	if (total < drawmoney)
	{
		cout << "余额不足" << endl;
		return 0;
	}
	else
		total = total - drawmoney;
		return total;
	//throw exception();
}
int Bank::gettotalmoney()const
{
	return total ;
}
void Bank::print()const
{
	cout << "余额剩余" << gettotalmoney() << endl;
}
//主函数
#include<iostream>
#include<Windows.h>
#include"Bank.h"
#include<string>
using namespace std;
int  Print();//打印主界面
void printpaymoney(Bank *b);//存钱界面
void printdrawmoney(Bank *b);//取钱界面
int main()
{
	Bank *p = new Bank;
	cout << "请输入银行卡号" << endl;
	string id;
	cin >> id;
	p->setBankid(id);
	//cout << p->getBankid()<< endl;
	cout << "请输入密码" << endl;
	int password;
	cin >> password;
	p->setBankpassword(password);
	cout << "输入正确,正在进入主界面。。。。" << endl;
	Sleep(500);
	bool done = true;
	while (done)
	{
		int section = Print();
		switch (section)
		{
		case 1:
			p->print();
			break;
		case 2:
			printpaymoney(p);
			cout << "存钱成功!您当前余额为";
			cout << p->getpaymoney() << endl;
			break;
		case 3:
			printdrawmoney(p);
			cout << "您当前余额";
			cout << p->getdrawmoney()<< endl;
			break;
		case 0:
			done = false;
			break;
		default:
			cout << "unkown command!" << endl;
		}
	}
	return 0;
}
int Print()
{
	int section;	
		cout << "1)查询当前余额 " << endl;
		cout << "2)存钱" << endl;		
		cout << "3)取钱" << endl;	
		cout << "0)退出" << endl;
	cin >> section;
	return section;
}
void printdrawmoney(Bank *b)//取钱界面
{
	cout << "请输入您要取钱的金额" << endl;
	int money;
	cin >> money;
	b->setdrawmoney(money);
}
void printpaymoney(Bank *b)//存钱界面
{
	cout << "请输入您要存入的金额" << endl;
	int money;
	cin >> money;
	b->setpaymoney(money);
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值