U E D R , A S I H C RSS

Oops/과제/2014.09.12


1. 은행계좌

  • 은행계좌에 대한 정보를 입출력하는 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이면 다시 입력받음

2. 코드 제출

2.1. 김한성

 #include<iostream>

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(){
	return balance*(1+interestRate/12*term);;
}

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;
} 

2.2. 송치완

 
//
//  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;
    
    myAccount.input();
    myAccount.setRate(interestRate);

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

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

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

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

    
    do{
        
        cout<<"Please enter term: ";
        cin>>term;
        
        if(term<=0) cout<<"TERM SHOULD BE BIGGER THAN 0\n";
        
    }while(checkPositive(term));
}

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

void CDaccount::setRate(double interestRate){
    
    this->interestRate=interestRate/100;
    
}



2.3. 추성준


#include <iostream>
using namespace std;

class CDaccount {
	double balance;
	double interestRate;
	int term;
	int SetBalance(double);
public:
	void input();
	void putIntersetRate(int);
	double getMaturedBalance();
};

int CDaccount::SetBalance(double input_Balance){
	if (input_Balance > 0) {
		this->balance = input_Balance;
		return 1;
	} else {
		return 0;
	}
}

void CDaccount::input() {
	double input;

	while(true) {
		cout << "Enter the balance: ";
		cin >> input;
		if (this->SetBalance(input)==0) {
			continue;
		} else {
			break;
		}
	}
		cout << "Enter the term: ";
		cin >> this->term;
}

void CDaccount::putIntersetRate(int input_interestRate) {
	this->interestRate = input_interestRate;
}

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

int main () {
	int interestRate = 5;
	CDaccount account;

	account.input();
	account.putIntersetRate(interestRate);

	cout << "Matured balance: $" << account.getMaturedBalance() << "(Interst Rate : " << interestRate << "%)"<< endl;
	
	return 0;
}


2.4. 김성원

#include <iostream>
using namespace std;

class account{
	public:
		account(double balance, double interestRate, int term);

		void balanceInput();			//balance를 입력받는 함수
		double gerMaturedBalance();		//만기시 이자를 리턴해주는 함수
		void termInput();				//term을 입력 받는 함수
		void balanceOutput();			//balance를 출력하는 함수
		int setBalance(double b);
		int setTerm(double t);	

	private:
		double balance;					//현재 잔액
		double interestRate;			//이자율
		int term;						//만기까지 남은 개월 수

};



int main(){
	account me(0,0.05,0);
	me.balanceInput();
	me.termInput();
	me.balanceOutput();

	return 0;
}

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

void account::balanceInput(){
	cout<<"Input Your Balance."<<endl;
	cin>>balance;
	while(setBalance(balance)){
		cout<<"Error!! Input Balance Again"<<endl;
		cin>>balance;
	}
}

int account::setBalance(double b){
	if(b>0) return 0;
	else return 1;
}

int account::setTerm(double t){
	if(t>0) return 0;
	else return 1;
}

void account::termInput(){
	cout<<"Input Term."<<endl;
	cin>>term;
	while(setTerm(term)){
		cout<<"Error!! Input Term Again"<<endl;
		cin>>term;
	}
}

double account::gerMaturedBalance(){
	double val=0;

	val = balance*(interestRate/12)*term;

	return val;
}

void account::balanceOutput(){
	cout<<"After "<<term<<"months Your Balance is "<<balance + gerMaturedBalance()<<"(Interest Rate is 5% per Year.)"<<endl;
}




2.5. 최다인

//
//  main.cpp
//  BankAccount
//
//  Created by MeYou on 2014. 9. 17..
//  Copyright (c) 2014년 MeYou. All rights reserved.
//

#include <iostream>

using namespace std;

class CDaccount {
private:
    double balance;                 //The prevent balance of accounts
    double interestRate;            //Interest rate per year (%)
    int    term;                    //How many months left until expiration
    
    int    setBalance(double);      //Correct an error and update value of balance
    int    setTerm(int);            //Correct an error and update value of term
    void   setInterestRate(double); //set value of interest rate
    
public:
    void   input(double);           //Receive input of variable's values
    double getMaturedBalance();     //Return the amount of money when the account expires
};

int CDaccount::setBalance(double b)
{
    if (b > 0) {
        balance = b;
        return 0;
    } else {
        return -1;
    }
}

int CDaccount::setTerm(int t)
{
    if (t > 0) {
        term = t;
        return 0;
    } else {
        return -1;
    }
}

void CDaccount::setInterestRate(double r)
{
    interestRate = r;
}

void CDaccount::input(double r)
{
    double b;
    int    t;
    
    do {
        cout << "Enter the balance : ";
        cin >> b;
    } while (setBalance(b) == -1);
    
    do {
        cout << "Enter the term : ";
        cin >> t;
    } while (setTerm(t) == -1);
    
    setInterestRate(r);
}

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

int main(int argc, const char * argv[])
{
    CDaccount myAccount;
    double    interestRate = 5;
    
    myAccount.input(interestRate);
    
    cout << "\nMatured Balance : $" << myAccount.getMaturedBalance() << " (Interest Rate : " << interestRate << "%)" << endl;
    return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:55
Processing time 0.0178 sec