1. 은행계좌 ¶
- 은행계좌에 대한 정보를 입출력하는 class를 만들어 활용해본다.
- class CDaccount 멤버변수
- double balance;//현재잔액
- double interestRate; // 연 이자율 (%) * int term;//만기까지몇달인지나타냄
- 그외 필요한 멤버변수 추가
- double balance;//현재잔액
- class CDaccount 멤버함수
- private 멤버변수 입출력을 위한 함수 정의
- void input(); // 내용을 키보드로 입력. balance와 term을 키보드로 입력받는다. 이자율은 main()함수에서 5%로 할당
- double getMaturedBalance(); //term 동안의 이자를 단리로 계산하여 만기시의 금액을 리턴
- 그 외 필요한 멤버함수
- private 멤버변수 입출력을 위한 함수 정의
- 입력 에러 확인
- private 멤버변수의 입력을 위한 멤버함수에서 에러를 확인할 수 있다.
- 예) balance는 0보다 큰 숫자이다.
- int SetBalance(double b) 멤버함수를 정의:
- b가 0보다 크면 값을 update하고 1을 리턴, 아니면 0을 리턴
- input()에서 위 함수 호출하여 리턴값이 0이면 다시 입력받음
- private 멤버변수의 입력을 위한 멤버함수에서 에러를 확인할 수 있다.
- class CDaccount 멤버변수
2. 코드 제출 ¶
- 김한성
class CDaccount{
public:
public:
CDaccount(double balance, double interestRate, int term);
void input(); // balance, term을 키보드로 입력받음
double getMaturedBalance(); // term 동안의 이자를 단리로 계산하여 만기시의 금액을 리턴
double getBalance();
double getInterestRate();
int getTerm();
int setBalance(double balance);
void setInterestRate(double intersetRate);
void setTerm(int term);
private: void input(); // balance, term을 키보드로 입력받음
double getMaturedBalance(); // term 동안의 이자를 단리로 계산하여 만기시의 금액을 리턴
double getBalance();
double getInterestRate();
int getTerm();
int setBalance(double balance);
void setInterestRate(double intersetRate);
void setTerm(int term);
double balance; //잔액
double interestRate; //이자율(%)
int term; //기간
};double interestRate; //이자율(%)
int term; //기간
CDaccount::CDaccount(double balance, double interestRate, int term){
this->balance = balance;
this->interestRate = interestRate;
this->term = term;
}this->interestRate = interestRate;
this->term = term;
void CDaccount::input(){
double balance;
int term;
int i;
while(1){
while(1){
std::cout << "Matured balance: " << getMaturedBalance() <<" (Interest Rate: 5%)\n";
}int term;
int i;
while(1){
std::cout << "Enter the balance(upto 0): ";
std::cin >> balance;
if(setBalance(balance) == 1){
}std::cin >> balance;
if(setBalance(balance) == 1){
break;
}while(1){
std::cout << "Enter the term: ";
std::cin >> term;
if(term > 0){
}std::cin >> term;
if(term > 0){
setTerm(term);
break;
}break;
std::cout << "Matured balance: " << getMaturedBalance() <<" (Interest Rate: 5%)\n";
double CDaccount::getMaturedBalance(){
int i;
for(i=0;i
return balance;
}for(i=0;i
balance *= 1+interestRate;
}return balance;
double CDaccount::getBalance(){
double CDaccount::getInterestRate(){
int CDaccount::getTerm(){
return balance;
}double CDaccount::getInterestRate(){
return interestRate;
}int CDaccount::getTerm(){
return term;
}