Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Oops/과제/2014.09.12: Difference between revisions

From ZeroWiki
imported>chi3236
No edit summary
imported>chi3236
No edit summary
Line 22: Line 22:
= 코드 제출 =
= 코드 제출 =
* 김한성
* 김한성
|| #include<iostream>
 
class CDaccount{
class CDaccount{
public:
public:
CDaccount(double balance, double interestRate, int term);
CDaccount(double balance, double interestRate, int term);
void input(); // balance, term을 키보드로 입력받음
void input(); // balance, term을 키보드로 입력받음
double getMaturedBalance(); // term 동안의 이자를 단리로 계산하여 만기시의 금액을 리턴
double getMaturedBalance(); // term 동안의 이자를 단리로 계산하여 만기시의 금액을 리턴
 
double getBalance();
double getBalance();
double getInterestRate();
double getInterestRate();
int    getTerm();
int    getTerm();
 
int setBalance(double balance);
int setBalance(double balance);
void setInterestRate(double intersetRate);
void setInterestRate(double intersetRate);
void setTerm(int term);
void setTerm(int term);
 
private:  
private:  
double balance; //잔액
double balance; //잔액
double interestRate; //이자율(%)
double interestRate; //이자율(%)
int term; //기간
int term; //기간
};
};
 
 
 
int main(){
int main(){
CDaccount account(0,0.05,0);
CDaccount account(0,0.05,0);
account.input();
account.input();
return 0;
return 0;
}
}
 
CDaccount::CDaccount(double balance, double interestRate, int term){
CDaccount::CDaccount(double balance, double interestRate, int term){
this->balance = balance;
this->balance = balance;
this->interestRate = interestRate;
this->interestRate = interestRate;
this->term = term;
this->term = term;
}
}
 
void CDaccount::input(){
void CDaccount::input(){
double balance;
double balance;
int term;
int term;
int i;
int i;
 
while(1){
while(1){
std::cout << "Enter the balance(upto 0): ";
std::cout << "Enter the balance(upto 0): ";
std::cin &gt;&gt; balance;
std::cin >> balance;
if(setBalance(balance) == 1){
if(setBalance(balance) == 1){
break;
break;
}
}
}
}
 
while(1){
while(1){
std::cout &lt;&lt; "Enter the term: ";
std::cout << "Enter the term: ";
std::cin &gt;&gt; term;
std::cin >> term;
if(term &gt; 0){
if(term > 0){
setTerm(term);
setTerm(term);
break;
break;
}
}
}
}
 
std::cout &lt;&lt; "Matured balance: " &lt;&lt; getMaturedBalance() &lt;&lt;" (Interest Rate: 5%)\n";
std::cout << "Matured balance: " << getMaturedBalance() <<" (Interest Rate: 5%)\n";
}
}
 
double CDaccount::getMaturedBalance(){
double CDaccount::getMaturedBalance(){
int i;
int i;
for(i=0;i&lt;term;i++){
for(i=0;i<term;i++){
balance *= 1+interestRate;
balance *= 1+interestRate;
}
}
return balance;
return balance;
}
}
 
double CDaccount::getBalance(){
double CDaccount::getBalance(){
return balance;
return balance;
}
}
double CDaccount::getInterestRate(){
double CDaccount::getInterestRate(){
return interestRate;
return interestRate;
}
}
int    CDaccount::getTerm(){
int    CDaccount::getTerm(){
return term;
return term;
}
}
 
int CDaccount::setBalance(double balance){
int CDaccount::setBalance(double balance){
if(balance &gt; 0){
if(balance > 0){
this-&gt;balance = balance;
this->balance = balance;
return 1;
return 1;
} else{
} else{
return 0;
return 0;
}
}
}
}
void CDaccount::setInterestRate(double interestRate){
void CDaccount::setInterestRate(double interestRate){
this-&gt;interestRate = interestRate;
this->interestRate = interestRate;
}
}
void CDaccount::setTerm(int term){
void CDaccount::setTerm(int term){
this-&gt;term = term;
this->term = term;
}  
} ||


* 송치완
* 송치완
|| //
//  main.cpp
//  main.cpp
//  CDaccount
//  CDaccount
//
//
//  Created by Chiwan Song on 2014. 9. 15..
//  Created by Chiwan Song on 2014. 9. 15..
//  Copyright (c) 2014년 Chiwan Song. All rights reserved.
//  Copyright (c) 2014년 Chiwan Song. All rights reserved.
//
//
 
#include &lt;iostream&gt;
#include &lt;iostream&gt;
using namespace std;
using namespace std;
 
class CDaccount{
class CDaccount{
   
   
private:
private:
   
   
    double balance;
    double balance;
    double interestRate;
    double interestRate;
    int term;
    int term;
   
   
    int checkPositive(double value);
    int checkPositive(double value);
    int checkPositive(int value);
    int checkPositive(int value);
   
   
public:
public:
   
   
    void input();
    void input();
    double getMaturedBalance();
    double getMaturedBalance();
    void setRate(double rate);
    void setRate(double rate);
   
   
};
};
 
int main(int argc, const char * argv[]){
int main(int argc, const char * argv[]){
   
   
    CDaccount myAccount;
    CDaccount myAccount;
   
   
    double interestRate=5.0;
    double interestRate=5.0;
    double maturedBalance;
    double maturedBalance;
   
   
    myAccount.input();
    myAccount.input();
    myAccount.setRate(interestRate);
    myAccount.setRate(interestRate);
    maturedBalance=myAccount.getMaturedBalance();
    maturedBalance=myAccount.getMaturedBalance();
 
    cout&lt;&lt;"Matured Balance: $"&lt;&lt;maturedBalance&lt;&lt;" (Interest rate: "&lt;&lt;interestRate&lt;&lt;"%)\n";
    cout<<"Matured Balance: $"<<maturedBalance<<" (Interest rate: "<<interestRate<<"%)\n";
   
   
    return 0;
    return 0;
   
   
}
}
 
int CDaccount::checkPositive(double value){
int CDaccount::checkPositive(double value){
   
   
    if(value&lt;=0) return 0;
    if(value<=0) return 0;
    else return 1;
    else return 1;
   
   
}
}
 
int CDaccount::checkPositive(int value){
int CDaccount::checkPositive(int value){
   
   
    if(value&lt;=0) return 0;
    if(value<=0) return 0;
    else return 1;
    else return 1;
   
   
}
}
 
void CDaccount::input(){
void CDaccount::input(){
   
   
    int check=0;
    int check=0;
    while(check==0){
    while(check==0){
       
       
        cout&lt;&lt;"Please enter balance: ";
        cout<<"Please enter balance: ";
        cin&gt;&gt;balance;
        cin>>balance;
       
       
        check=checkPositive(balance);
        check=checkPositive(balance);
       
       
        if(check==0) cout&lt;&lt;"BALANCE SHOULD BE BIGGER THAN 0\n";
        if(check==0) cout<<"BALANCE SHOULD BE BIGGER THAN 0\n";
       
       
    }
    }
   
   
    check=0;
    check=0;
   
   
    while(check==0){
    while(check==0){
       
       
        cout&lt;&lt;"Please enter term: ";
        cout<<"Please enter term: ";
        cin&gt;&gt;term;
        cin>>term;
       
       
        check=checkPositive(term);
        check=checkPositive(term);
       
       
        if(check==0) cout&lt;&lt;"TERM SHOULD BE BIGGER THAN 0\n";
        if(check==0) cout<<"TERM SHOULD BE BIGGER THAN 0\n";
       
       
    }
    }
}
}
 
double CDaccount::getMaturedBalance(){
double CDaccount::getMaturedBalance(){
   
   
    return balance+(balance*interestRate*term/12);
    return balance+(balance*interestRate*term/12);
   
   
}
}
 
void CDaccount::setRate(double rate){
void CDaccount::setRate(double rate){
   
   
    interestRate=rate/100;
    interestRate=rate/100;
   
   
}
} ||



Revision as of 08:46, 15 September 2014

은행계좌

  • 은행계좌에 대한 정보를 입출력하는 class를 만들어 활용해본다.
    • class CDaccount 멤버변수
    • double balance;//현재잔액
    • double interestRate; // 연 이자율 (%) * int term;//만기까지몇달인지나타냄
    • 그외 필요한 멤버변수 추가
    • class CDaccount 멤버함수
    • private 멤버변수 입출력을 위한 함수 정의
    • void input(); // 내용을 키보드로 입력. balance와 term을 키보드로 입력받는다. 이자율은 main()함수에서 5%로 할당
    • double getMaturedBalance(); //term 동안의 이자를 단리로 계산하여 만기시의 금액을 리턴
    • 그 외 필요한 멤버함수
    • 입력 에러 확인
    • private 멤버변수의 입력을 위한 멤버함수에서 에러를 확인할 수 있다.
    • 예) balance는 0보다 큰 숫자이다.
    • int SetBalance(double b) 멤버함수를 정의:
    • b가 0보다 크면 값을 update하고 1을 리턴, 아니면 0을 리턴
    • input()에서 위 함수 호출하여 리턴값이 0이면 다시 입력받음

코드 제출

  • 김한성
class CDaccount{
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: 
	double balance;				//잔액
	double interestRate;		//이자율(%)
	int	term;					//기간
};



int main(){
	CDaccount account(0,0.05,0);
	account.input();
	return 0;
}

CDaccount::CDaccount(double balance, double interestRate, int term){
	this->balance = balance;
	this->interestRate = interestRate;
	this->term = term;
}

void CDaccount::input(){
	double balance;
	int term;
	int i;

	while(1){
		std::cout << "Enter the balance(upto 0): ";
		std::cin >> balance;
		if(setBalance(balance) == 1){
			break;
		}
	}

	while(1){
		std::cout << "Enter the term: ";
		std::cin >> term;
		if(term > 0){
			setTerm(term);
			break;
		}
	}

	std::cout << "Matured balance: " << getMaturedBalance() <<" (Interest Rate: 5%)\n";
}

double CDaccount::getMaturedBalance(){
	int i;
	for(i=0;i<term;i++){
		balance *= 1+interestRate;
	}
	return balance;
}

double CDaccount::getBalance(){
	return balance;
}
double CDaccount::getInterestRate(){
	return interestRate;
}
int    CDaccount::getTerm(){
	return term;
}

int CDaccount::setBalance(double balance){
	if(balance > 0){
		this->balance = balance;
		return 1;
	} else{
		return 0;
	}
}
void CDaccount::setInterestRate(double interestRate){
	this->interestRate = interestRate;
}
void CDaccount::setTerm(int term){
	this->term = term;
} 
  • 송치완
//  main.cpp
//  CDaccount
//
//  Created by Chiwan Song on 2014. 9. 15..
//  Copyright (c) 2014년 Chiwan Song. All rights reserved.
//

#include <iostream>
using namespace std;

class CDaccount{
    
private:
    
    double balance;
    double interestRate;
    int term;
    
    int checkPositive(double value);
    int checkPositive(int value);
    
public:
    
    void input();
    double getMaturedBalance();
    void setRate(double rate);
    
};

int main(int argc, const char * argv[]){
    
    CDaccount myAccount;
    
    double interestRate=5.0;
    double maturedBalance;
    
    myAccount.input();
    myAccount.setRate(interestRate);
    maturedBalance=myAccount.getMaturedBalance();

    cout<<"Matured Balance: $"<<maturedBalance<<" (Interest rate: "<<interestRate<<"%)\n";
    
    return 0;
    
}

int CDaccount::checkPositive(double value){
    
    if(value<=0) return 0;
    else return 1;
    
}

int CDaccount::checkPositive(int value){
    
    if(value<=0) return 0;
    else return 1;
    
}

void CDaccount::input(){
    
    int check=0;
    while(check==0){
        
        cout<<"Please enter balance: ";
        cin>>balance;
        
        check=checkPositive(balance);
        
        if(check==0) cout<<"BALANCE SHOULD BE BIGGER THAN 0\n";
        
    }
    
    check=0;
    
    while(check==0){
        
        cout<<"Please enter term: ";
        cin>>term;
        
        check=checkPositive(term);
        
        if(check==0) cout<<"TERM SHOULD BE BIGGER THAN 0\n";
        
    }
}

double CDaccount::getMaturedBalance(){
    
    return balance+(balance*interestRate*term/12);
    
}

void CDaccount::setRate(double rate){
    
    interestRate=rate/100;
    
}