AccountHandler.h
#ifndef __AccountHandler_H__
#define __AccountHandler_H__
#include "Account.h"
#include "AccountArray.h"
class AccountHandler
{
private:
Account *accArr[100];
int accCnt;
int infoCount; //삭제해도 될듯?
public:
AccountHandler();
void SelectMenu(); //선택메뉴
void MakeAccount(); // 계좌 개설 함수
void DepositMoney(); //입금 함수
void WithdrawMoney(); //출금 함수
void ShowAllAccountInfo() const; // 계좌 정보 출력
};
#endif
AccountHandler.cpp
#include "BankingCommonDecl.h"
#include "AccountHandler.h"
#include "NormalAccount.h"
#include "HighCreditAccount.h"
#include "String.h"
AccountHandler::AccountHandler()
: accCnt(0),infoCount(1)
{
//empty
}
void AccountHandler::SelectMenu() //메뉴선택 함수
{
cout<<"----Menu----"<<endl;
cout<<"1. 계좌개설"<<endl;
cout<<"2. 입 금"<<endl;
cout<<"3. 출 금"<<endl;
cout<<"4. 계좌정보 전체 출력"<<endl;
cout<<"5. 프로그램 종료"<<endl;
}
void AccountHandler::MakeAccount() //계좌개설 함수
{
//char cn[50]
String cn; //고객이름
int select; //보통,신용계좌 선택
int id; //계좌 번호
int bal; // 잔액
int ir; //이자율
char grade; //신용등급
/************************************/
cout<<"[계좌 종류 선택]"<<endl;
cout<<"1.보통예금 계좌 2.신용예금 계좌"<<endl<<endl;
cout<<"선택 : "; cin>>select;
cout<<endl;
while(1)
{
if(select == 1)
{
cout<<"[보통예금계좌 개설]"<<endl;
cout<<"계좌 ID :"; cin>>id; //계좌 번호
cout<<"이 름 : "; cin>>cn; //고객 이름
cout<<"입금액 : "; cin>>bal; //잔액
cout<<"이자율 : 3%"<<endl<<endl;
accArr[accCnt] = new NormalAccount(cn,id,bal);
break;
}
else if(select == 2)
{
cout<<"[신용신뢰계좌 개설]"<<endl;
cout<<"계좌 ID :"; cin>>id; //계좌 번호
cout<<"이 름 : "; cin>>cn; //고객 이름
cout<<"입금액 : "; cin>>bal; //잔액
cout<<"이자율 : 5%"<<endl;
cout<<"신용등급(1toA, 2toB, 3toC): "; cin>>grade; //신용등급
cout<<endl;
if(grade == 'a' || grade == 'A') // 추가 이자율 7%
{
accArr[accCnt] = new HighCreditAccount(cn,id,bal,CreditGrade::Grade_A);
break;
}
else if(grade == 'b' || grade == 'B') //추가 이자율 4%
{
accArr[accCnt] = new HighCreditAccount(cn,id,bal,CreditGrade::Grade_B);
break;
}
else if(grade == 'c' || grade == 'C') //추가 이자율 2%
{
accArr[accCnt] = new HighCreditAccount(cn,id,bal,CreditGrade::Grade_C);
break;
}
else
{
cout<<"존재하지 않는 신용등급입니다."<<endl;
break;
}
}
else
{
cout<<"***다시 선택해 주세요***"<<endl;
break;
}
}
/************************************/
accCnt++;
if(accCnt>100)
{
cout<<"계좌 정보가 가득 차 개설할 수없습니다"<<endl;
return;
}
}
void AccountHandler::DepositMoney() //입금 함수
{
int id;
int money; //입금액
cout<<"[입 금]"<<endl;
cout<<"계좌 ID : "; cin>>id;
for(int i=0; i<accCnt; i++)
{
if(accArr[i]->GetID() == id)
{
cout<<"입금액 : "; cin>>money;
accArr[i]->Deposit(money);
cout<<"입금이 완료 되었습니다"<<endl;
cout<<"잔액 : "<<accArr[i]->GetMoney()<<endl<<endl;
return;
}
}
cout<<"유효하지 않은 계좌번호입니다"<<endl;
cout<<endl;
return;
}
void AccountHandler::WithdrawMoney() //출금 함수
{
int id;
int money; //출금액
cout<<"[출 금]"<<endl;
cout<<"계좌 ID : "; cin>>id;
for(int i=0; i<accCnt; i++)
{
if(accArr[i]->GetID() == id) // 계좌번호 검사
{
cout<<"출금액 : "; cin>>money;
if(accArr[i]->GetMoney() >= money)
{
accArr[i]->Withdraw(money);
cout<<"출금이 완료 되었습니다"<<endl;
cout<<"잔액 : "<<accArr[i]->Withdraw(money)<<endl;
cout<<endl;
return;
}
else
{
cout<<"잔액이 부족합니다"<<endl;
cout<<endl;
return;
}
}
}
cout<<"유효하지 않은 계좌번호입니다"<<endl;
cout<<endl;
return;
}
void AccountHandler::ShowAllAccountInfo() const// 계좌정보 출력
// 오버라이딩후 virtual 선언이 필요할듯
{
for(int i=0; i<accCnt; i++)
accArr[i]->ShowAccountInfo(); //ShowAccountInfo 오버라이딩
return;
}
HighCreditAccount.h
#ifndef __HighCreditAccount_H__
#define __HighCreditAccount_H__
#include "Account.h"
#include "String.h"
class HighCreditAccount : public Account //신용신뢰 계좌
{
//Account 클래스를 상속하므로 Account 클래스를 초기화할 의무를 가져야한다
private:
int interestRate; //이자비율
int additional_ir; //등급에 따른추가이율
public:
//HighCreditAccount(char* custName,int id,int balance,int grd);
HighCreditAccount(String custName,int id,int balance,int grd);
virtual int GetMoney() const; //가상함수 선언
virtual int Withdraw(int money);
};
#endif
HighCreditAccount.cpp
#include "HighCreditAccount.h"
//HighCreditAccount::HighCreditAccount(char* custName,int id,int balance,int grd);
HighCreditAccount::HighCreditAccount(String custName,int id,int balance,int grd)
: interestRate(5),Account(custName,id,balance)
{
additional_ir = interestRate + grd; // 기본 이율 + 등급에 따른 추가이율
}
int HighCreditAccount::GetMoney() const
{
return Account::GetMoney() + Account::GetMoney()*additional_ir/100;
// 클래스내에서 이미 등급에따른 추가 이자율 계산을 따로 끝낸 상태,여기서 해주는게 더 깔끔하게 보일까?
}
int HighCreditAccount::Withdraw(int money)
{
return GetMoney()-money;
}
NormalAccount.h
#ifndef __NormalAccount_H__
#define __NormalAccount_H__
#include "Account.h"
class NormalAccount : public Account //보통 예금 계좌
{
//Account 클래스를 상속하므로 Account 클래스를 초기화할 의무를 가져야한다.
private:
int interestRate; //이자비율
public:
//NormalAccount(char* custName,int id,int balance);
NormalAccount(String custName,int id,int balance); // Account의 멤버변수에 관한 정보를 makeAccount함수를 통해 전달받는다?
virtual int GetMoney() const; //GetMoney 호출시 NormalAccount GetMoney 호출
virtual int Withdraw(int money);
};
#endif
NormalAccount.cpp
#include "NormalAccount.h"
//NormalAccount::NormalAccount(char* custName,int id,int balance)
NormalAccount::NormalAccount(String custName,int id,int balance) // Account의 멤버변수에 관한 정보를 makeAccount함수를 통해 전달받는다?
: interestRate(3),Account(custName,id,balance)
{
//empty
}
int NormalAccount::GetMoney() const
{
return Account::GetMoney() + Account::GetMoney()*interestRate/100; //이자율 더해주기
}
int NormalAccount::Withdraw(int money)
{
return GetMoney()-money;
}
#ifndef __STRING_H_
#define __STRING_H_
#include "BankingCommonDecl.h"
#include "String.h"
String.h
class String
{
private:
char *std_str;
public:
String();
String(const char *str);//생성자 정의
String(const String& cpy); //복사생성자
String& operator=(const String& cpy); //대입연산자
String operator+(const String& cpy);
String& operator+=(const String& cpy);
/*
동일한 정의
String& operator+=(const String& cpy)
{
*this=*this+s;
return *this;
}
*/
bool operator==(const String& cpy);
~String(); //소멸자
friend ostream& operator<<(ostream& os,const String& cpy);
friend istream& operator>>(istream& is,const String& cpy);
};
#endif
String.cpp
#include "String.h"
#include "AccountHandler.h"
String::String()
{
std_str=NULL;
}
String::String(const char *str) //생성자 정의
{
std_str=new char[strlen(str)+1];
strcpy(std_str,str);
}
String::String(const String& cpy) //복사생성자
{
std_str=new char[strlen(cpy.std_str)+1];
strcpy(std_str,cpy.std_str);
}
String& String::operator=(const String& cpy) //대입연산자
{
if(std_str!=NULL)
delete []std_str;
std_str=new char[strlen(cpy.std_str)+1];
strcpy(std_str,cpy.std_str);
return *this;
}
String String::operator+(const String& cpy)
{
int len=strlen(std_str)+strlen(cpy.std_str)+1;
char *temp_str=new char[len];
strcpy(temp_str,std_str);
strcat(temp_str,cpy.std_str);
String temp(temp_str); //생성자호출
delete []temp_str;
return temp; //임시객체생성되면서 복사생성자 호출
}
String& String::operator+=(const String& cpy)
{
int len=strlen(std_str)+strlen(cpy.std_str)+1;
char *temp_str=new char[len];
strcpy(temp_str,std_str);
strcat(temp_str,cpy.std_str);
if(std_str!=NULL)
delete []std_str;
std_str=temp_str;
return *this;
}
/*
동일한 정의
String& operator+=(const String& cpy)
{
*this=*this+s;
return *this;
}
*/
bool String::operator==(const String& cpy)
{
if(!strcmp(std_str,cpy.std_str))
return true;
else
return false;
}
String::~String() //소멸자
{
if(std_str!=NULL)
delete []std_str;
}
ostream& operator<<(ostream& os,const String& cpy)
{
os<<cpy.std_str;
return os;
}
istream& operator>>(istream& is,String& cpy)
{
char str[100];
is>>str;
cpy=String(str); //임시객체생성(생성자호출)-> 대입연산자 호출
return is;
}
String 쓰지 말라는 이야기임 std::string 쓰면 됨. 좀더 자세히 분석하면 아... 귀찮어
stream 에서 오버로딩한 오퍼레이터 >> 이거에 인자로 String 오면 어떻게 할지 정의가 안되어있다는거 같은데.. 맞겠지? 당연히 stl에서 쓰라고 만든거니까 stl써야지 직접 class만들어서쓸거면 cin 쓰지말고 getc 같은거써서 구현하던가
ㅇㅇ // 아니 형님 당연히 기존에 있는 표준 string 클래스 인가 그거 쓰면 좋지요..근데 이건 걍 책에서 해보라고 내준 문제를 제시한거고 나는 코린이니까 이런것도 짜보고 적용시켜보는건데..근데 안되니까 하는 말이지..
ㄴ 직접 만들어 쓰는 것도 좋은 연습이다 ㅇㅇ
찾았다 ㅋㅋㅋㅋㅋ operator"꺽새꺼새" 에서 String:: 네임스페이스 추가해라
커헠 //형님 AccountHandler .cpp에서 말씀이신가요
커헠 // String.cpp에 있는 operator >> 이거 말씀이시면 원래 전역함수로 선언된게 맞아여 형님
커헠 << c++ 허접
이색기 근성 쩌네.. 야 그냥 vs 프로젝트 통쨰로 압축해서 확장자 바꿔서 올려봐 형이 5분안에 해결해줌
참고로 형 c++ 개고수인데 이거 라이브러리 추가 안했거나 니가 불러온 .h .cpp 파일 프로젝트에 추가 안해서 인식 못하는거야
d // 형 잠시만요..
d //프로젝트 자체를 압축해야해요? 아니면 그 걍 소스랑 헤더파일만 따로 압축해여?
프로젝트 폴더 자체를 압축하라고
소스 헤더파일 모아서 압축하던지
암튼 빨리 올려라 형 존나 바쁜 사람이다
형님 압축했는데 디씨에서 지원하지않는 확장자라는데..
그럼 확장자. 바꿔서. 올리면. 되자나. 웹서버가. 확장자만. 검사하지. 파일까지. 검사하긋냐
아니 시발 jpg로 변경했는데도 지원하지 않는다고하네 시팔 뭐지.;;
이미지로 올리지 말고 파일로 ㅜ ㅜ
형님 그러니가 파일로요;; 확장자 zip 안되길래 jpg로 변경했는데 ㅡㅡ;; 그래도안됨;
야 병신아 헤더 파일이랑 소스 파일이랑 함수 시기니쳐가 다르잖아
당연히 씨발 링커에러나지
txt로 해봐
125.177 // 됐따 형님 txt로 올렸어여 zip로 변경해서 해보세요
커헠 // 형님 무슨말인지 모르겠3..
야 함수 봐봐 헤더에서는 const String& 로 선언했고 너 소스 파일에서는 String& 로 선언했잖아
그리고 저거 전역으로 안 해도 돼 그냥 멤버 연산자로 해도 똑같다
헐 >>연산자에서 헤더에서는 매개변수를 const로 받았는데 소스파일에서는 그냥 받았네요;;;헐 세상에
와 세상에 형님 정말 감사합니다 프로그래밍 갤러리에 정말 고수분들만 모인듯;