创建一个银行的账号,实现存钱取钱。(c++)

创建一个银行的类,要求有用户的姓名,余额,以及存钱,取钱函数的实现。
以下是我的代码:


//text.cpp
#include <iostream>
#include<iomanip>
#include"Account.h"
using namespace std;
int main()
{
	int a;
	Account k("0001","sunny","2018年10月12日",0);
	cout << "客户要存入多少钱\n";
	cin >>a; 
	k.setAccount1(a);
	cout << "余额为"; 
	k.getAccount();
	
	cout <<"客户要取多少钱\n";
	cin >>a;
	k.setAccount2(a);
	cout <<"余额为"; 
	k.getAccount();   
}


//Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include<iostream>
class Account
{
	public:
		explicit Account(std::string n,std::string na,std::string da,int se);
		void setAccount(std::string n,std::string na,std::string da,int se);
		void setAccount1(int se);
		void setAccount2(int se);
		void getAccount();
	private:
		void counter(int a, int b);
		void sub(int a , int b);
		std::string number;
		std::string name;
		std::string date;
		int semain;
};

#endif
#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account
{
	public:
	protected:
};

#endif

Account.cpp
#include "Account.h"
#include<iostream>
#include<iomanip>
using namespace std;
Account::Account(string n=0,string na="0",string da="0",int se=0)
{
	number=n,name=na,date=da,semain=se;
}
void Account::setAccount(string n,string na,string da,int se) 
{
	number=n,na=name,da=date,se=semain;
}
void Account::setAccount1(int se)
{
	counter(se, semain);
 } 
 void Account::setAccount2(int se)
 {
 	sub(se,semain);
 }
void Account::getAccount()
{
	cout << semain << endl;
}
void Account::counter(int a, int b)
{
		semain=a+b;
 } 
void Account::sub(int a,int b)
{
		if(b-a<0)
		{
			cout << "取钱超过余额,只能取" << b << endl;	 
		}
		else
		{
			semain=b-a;
		}
}
#include "Account.h"
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三少爷的剑!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值