목록으로 2013.03.14. 10:37
C언어

저축예금 클래스 VER.4

youtube

#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;}
   BankAccount(string n,int b,int c){name = n; balance=b; rate=c;}
        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("강봄");
  BankAccount bb("김여름",1000,7);
         
  ba.print();
  bb.print();
}

 

댓글 0

댓글 작성 권한이 없습니다. 로그인하기

NO
TITLE
섬네일
C언어
profile 너에게제공 | 03. 14 | 조회
42
C언어 ㄴㅇ
profile 너에게제공 | 09. 10 | 조회
37