Account 클래스를 상속하는 다음 두 클래스를 추가로 정의한다.
NormalAccount
HighCreditAccount
NormalAccount 생성 과정에서 이율정보를 등록할 수 있도록 하고,
HighcreditAccount 생성 과정에서 추가 이율정보를 등록한다.
Account 클래스를 상속받는 normalAccount 클래스에 이자 정보를 추가하고,
normalAccount 클래스를 상속받는 highcreditAccount 클래스에 추가 이율 정보를 추가한다.
#include <iostream>
#include <cstring>
const int NAME_LEN=20;
class Accounts //데이터 클래스
{
private:
int ID;
char *name;
int amount;
int credit;
public:
Accounts(const int &ID, char *b, const int &amount) : ID(ID), amount(amount)
{
name=new char[strlen(b)+1];
strcpy(name,b);
}
bool Accountcheck(int a) const
{
if(a==ID)
return true;
else
return false;
}
virtual void Acdeposit(int a)
{
amount+=a;
}
void Acwithdraw(int a)
{
amount-=a;
}
void showAccount() const
{
std::cout<<"계좌ID: "<<ID<<std::endl;
std::cout<<"이름: "<<name<<std::endl;
std::cout<<"잔액: "<<amount<<std::endl<<std::endl;
}
};
class normalAccounts : public Accounts
{
private:
int interest;
public:
normalAccounts(const int &ID, char *b, const int &amount, int interest) : Accounts(ID, b, amount), interest(interest)
{
//empty
}
virtual void Acdeposit(int a)
{
Accounts::Acdeposit(a);
Accounts::Acdeposit(a*(interest/100));
}
};
class highcreditAccounts : public normalAccounts
{
private:
int creditgrade;
public:
highcreditAccounts(int &ID, char *b, int &amount, int interest, int creditgrade) : normalAccounts(ID, b, amount, interest), creditgrade(creditgrade)
{
//empty
}
virtual void Acdeposit(int a)
{
normalAccounts::Acdeposit(a);
normalAccounts::Acdeposit(a*(creditgrade)/100);
}
};
class Accounthandler
{
private:
//int x=0; //account 개수
public:
void typeAccount();
void MakeAccount();
void creditAccount();
void deposit();
void withdraw();
void account_fuc() const;
};
Accounts *Account[NAME_LEN];
normalAccounts *normalAccount[NAME_LEN];
highcreditAccounts *highcreditAccount[NAME_LEN];
int acc=0; //Account 번호
int main()
{
int num;
Accounthandler Accounthandler;
while(1)
{
{
std::cout<<"-----Menu_____"<<std::endl;
std::cout<<"1. 계좌개설"<<std::endl;
std::cout<<"2. 입 금"<<std::endl;
std::cout<<"3. 출 금"<<std::endl;
std::cout<<"4. 계좌정보 전체 출력"<<std::endl;
std::cout<<"5. 프로그램 종료"<<std::endl;
std::cout<<"선택: ";
std::cin>>num;
if(num==1)
{
Accounthandler.typeAccount();
}
else if(num==2)
{
Accounthandler.deposit();
}
else if(num==3)
{
Accounthandler.withdraw();
}
else if(num==4)
{
Accounthandler.account_fuc();
}
else if(num==5)
{
break;
}
}
}
return 0;
}
void Accounthandler::typeAccount()
{
int type;
std::cout<<"[계좌종류선택]"<<std::endl;
std::cout<<"1.보통예금계좌 2.신용신뢰계좌"<<std::endl;
std::cout<<"선택: ";
std::cin>>type;
if(type==1)
{
MakeAccount();
}
else
{
creditAccount();
}
}
void Accounthandler::MakeAccount()
{
int a;
char b[NAME_LEN];
int c;
int d;
std::cout<<"[보통예금계좌개설]"<<std::endl;
std::cout<<"계좌ID: ";
std::cin>>a;
std::cout<<"이 름: ";
std::cin>>b;
std::cout<<"입금액: ";
std::cin>>c;
std::cout<<"이자율: ";
std::cin>>d;
Account[acc]=new normalAccounts(a,b,c,d);
acc++;
}
void Accounthandler::creditAccount()
{
int a;
char b[NAME_LEN];
int c;
int d;
int e;
std::cout<<"[신용신뢰계좌개설]"<<std::endl;
std::cout<<"계좌ID: ";
std::cin>>a;
std::cout<<"이 름: ";
std::cin>>b;
std::cout<<"입금액: ";
std::cin>>c;
std::cout<<"이자율: ";
std::cin>>d;
std::cout<<"신용등급(1toA, 2toB, 3toC): ";
std::cin>>e;
Account[acc]=new highcreditAccounts(a,b,c,d,e);
acc++;
}
void Accounthandler::deposit()
{
int acID=0;
int num=0;
int am=0;
std::cout<<"[입 금]";
std::cout<<"계좌ID: ";
std::cin>>acID;
while(1)
{
if (Account[num]->Accountcheck(acID) == true)
break;
else
num++;
}
std::cout<<"입금액: ";
std::cin>>am;
Account[num]->Acdeposit(am);
std::cout<<"입금완료"<<std::endl;
}
void Accounthandler::withdraw()
{
int acID=0;
int num=0;
int am=0;
std::cout<<"[입 금]";
std::cout<<"계좌ID: ";
std::cin>>acID;
while(1)
{
if(Account[num]->Accountcheck(acID)==true)
break;
else
num++;
}
std::cout<<"출금액: ";
std::cin>>am;
Account[num]->Acwithdraw(am);
std::cout<<"출금완료"<<std::endl;
}
void Accounthandler::account_fuc() const
{
for(int r=0; r<acc; r++)
{
Account[r]->showAccount();
}
}
'Algorithm > C++' 카테고리의 다른 글
[백준] 11660번 : 구간 합 구하기 5 C++ 문제풀이 솔루션 (0) | 2024.04.05 |
---|---|
[백준] 11659번 : 구간 합 구하기 4 C++ 문제풀이 솔루션 (0) | 2024.04.05 |
열혈 C++ 프로그래밍 OOP 단계별 프로젝트 04단계 (0) | 2023.08.05 |
열혈 C++ 프로그래밍 OOP 단계별 프로젝트 02단계 (0) | 2023.07.22 |
C, C++ 객체 배열과 객체 포인터 배열 / 세그멘테이션 오류 segmentation fault(core dumped) (0) | 2023.07.22 |
댓글