#include <iostream>
#include "Account.h"
using namespace::std;
Account::Account(int id, char* name, int balance) // 생성자
{
this->id=id;
this->balance=balance;
this->name=new char[strlen(name)+1];
strcpy(this->name, name);
}
Account::Account(const Account& acc) // 복사 생성자
{
this->id=acc.id;
this->balance=acc.balance;
this->name=new char[strlen(acc.name)+1];
strcpy(this->name, acc.name);
}
Account::~Account(){ //소멸자
delete []name;
}
int Account::GetID() const{
return id;
}
int Account::GetBalance() const{
return balance;
}
void Account::AddMoney(int val){
balance+=val;
}
void Account::MinMoney(int val){
balance-=val;
}
const char* Account::GetName() const{
return name;
}
void Account::ShowAllData(){
cout<<"계좌ID: "<<id<<endl;
cout<<"이 름: "<<name<<endl;
cout<<"잔 액: "<<balance<<endl;
}
Account& Account::operator=(const Account& acc){ //추가된 함수// Account.operator=(p) //Account=p;
delete[] name;
name=new char[strlen(acc.name)+1];
id=acc.id;
balance=acc.balance;
strcpy(name,acc.name);
return *this;
}
'C++ > 열혈 C++' 카테고리의 다른 글
열혈 C++ oop8 ContriAccount.cpp (0) | 2018.04.09 |
---|---|
열혈 C++ oop8 Container.cpp (0) | 2018.04.09 |
열혈 C++ oop8 AccManager.cpp (0) | 2018.04.09 |
열혈 C++ oop FaithAccount.h (0) | 2018.04.09 |
열혈 C++ oop8 ContriAccount.h (0) | 2018.04.09 |
댓글