Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  hw
Language: C/C++
Code:
#include <iostream>
#include <string>
//#include "SavingsAccount.h"
using namespace std;


#ifndef SavingAccount_H
#define SavingAccount_H

class SavingsAccount
{
public:
     SavingsAccount();
     void setName(string);
     void setInitialBalance(double);     
     void setRate(double);
     void calculateMonthlyInterest (double);
     static void modifyInterestRate(double);
     
private:
     string name;
     double savingsBalance;
    static double annualInterestRate;

};
#endif

double SavingsAccount::annualInterestRate=0.00;

SavingsAccount::SavingsAccount()
{
     name="NA";
     savingsBalance=0.00;
    annualInterestRate=0.00;
}


void SavingsAccount::setName(string accountName)
{
     name = accountName;
     cout<<"the current account name in class is "<<name<<endl;
}

void SavingsAccount::setRate(double rate)
{
     annualInterestRate = rate;
     cout<<"the current account rate in class is "<< annualInterestRate <<endl;
}

void SavingsAccount::setInitialBalance(double balance)
{
     savingsBalance =balance;
     cout<<"the current account balance in class is "<< savingsBalance <<endl;
}

void SavingsAccount::calculateMonthlyInterest (double rate)
{

     savingsBalance= savingsBalance+ savingsBalance*rate/12;
     
     cout<<"the current account balance with interest is "<< savingsBalance <<endl;

}

void SavingsAccount::modifyInterestRate(double newRate)
{
     annualInterestRate=newRate;
     cout<<"the new rate in class "<<annualInterestRate<<endl;
}



int main()
{
     SavingsAccount a1;
     SavingsAccount a2;
     string accountName;
     double rate;
     double balance;
     
     //1st client
     cout<<"Please enter first account holder's name"<<endl;
     getline(cin, accountName);
     a1.setName(accountName);
     cout<<"Please enter  initial balance"<<endl;
     cin>>balance;
     a1.setInitialBalance(balance);
     cout<<"Please enter  interest rate"<<endl;
     cin>>rate;
     a1.setRate (rate);
     a1.calculateMonthlyInterest(rate);
     cout<<"Please enter the new interest rate"<<endl;
     cin>>rate;
     a1.modifyInterestRate(rate);
     a1.calculateMonthlyInterest(rate);

     //2nd client
     cout<<"Please enter second account holder's name"<<endl;
     getline(cin, accountName);
     a2.setName(accountName);
     cout<<"Please enter  2nd initial balance"<<endl;
     cin>>balance;
     a2.setInitialBalance(balance);
     cout<<"Please enter 2nd new interest rate"<<endl;
     cin>>rate;
     a2.setRate (rate);
     a2.calculateMonthlyInterest(rate);
    a2.modifyInterestRate(0.04);
    a2.calculateMonthlyInterest(rate);
     
     return 0;

}



Comments: