C언어 저축예금 클래스 VER.3
#include <iostream>
#include <string>
using namespace std;
class BankAccount
{
private:
string name;
int balance;
int rate;
public:
BankAccount(string n){name = n; balance=1000; rate=5;}
void deposit(int money);
void withdraw(int money);
void print();
};
void BankAccount::deposit(int money)
{
cout << "입금액 " << money<<endl;
balance = balance + money;
cout<< "잔고 " << balance<<endl;
}
void BankAccount::withdraw(int money)
{
cout << "출금액 " << money<<endl;
balance = balance - money;
cout<< "잔고 " << balance<<endl;
if (balance <money)
cout << "출금액 "<< money<<"이 잔고"<<balance<<"보다 많아 출금 불가능!!"<<endl;
}
void BankAccount::print()
{cout << "예금주 : " << name << endl << "예금액 : " << balance << "원" << endl << "이율 : " << rate << "%" << endl;}
void main()
{
BankAccount ba("강봄");
ba.print();
ba.deposit(5000);
ba.withdraw(4000);
}