D
David
I am getting the an output with exponential values and negative numbers.Can
you see what is generating that problem
Any help will be appreciated.
/* Create a savings accountclass. Use a dat data member to contain the
annualInterest rate
for each of the savers. Each member of the calss contains a private
membr savingsBalance
indicating the amount the saver currently has on deposit.Provide a
calculate MonthlyInterest
member function that calculates the monthly interest by mulyiplying the
balance by annualInterestRate
divided by 12; This interest should be added to savingssBalance. Provide
a member funtion
modifyInterestRate tahe sets the annualInteretrte to a new value. Write
adriver proram to test
clas savings Account. Instantiate two different savingsAccount objects,
saver1 and saver2, with balances of
$2000 and $3000,respectively. Set annual interest rate to 3% than calculate
the monthly interest rate and print
the new balances for eac of the savers.Then set the annual interset rate to
4% and calculate the next month's
interest and print the new balances for each of rthe savers */
#include <iostream>
using namespace std;
class SavingsAccount //class definition
{
public: // prototypes of member functions
SavingsAccount(double);
double cal_monthlyInterest();
void modifyInterestRate();
void showBalance();
private: //Data Member
double savingsBalance;
double annualInterestRate;
};
SavingsAccount::SavingsAccount(double balance) //constructor
{
savingsBalance = balance;
}
double SavingsAccount::cal_monthlyInterest()
{
SavingsAccount::savingsBalance += (annualInterestRate/12) *
savingsBalance;
return savingsBalance;
}
void SavingsAccount::modifyInterestRate()
{
SavingsAccount::annualInterestRate = 0.04;
}
void SavingsAccount:: showBalance()
{
cout<< "Balance is : $"<<SavingsAccount::savingsBalance<<"\n";
}
int main()
{
SavingsAccount saver1(2000);
SavingsAccount saver2(3000);
cout<<"\n";
cout<<" The program calculates 2 fixed interest rates for 2 fixed
accounts.\n";
cout<<"\n";
cout<<"New balances for Saver1 account @ 3% and 4% respectively are :\n";
cout<<"\n";
saver1.cal_monthlyInterest();
saver1.showBalance();
cout<<"\n";
saver1.modifyInterestRate();
saver1.cal_monthlyInterest();
saver1.showBalance();
cout<<"\n";
cout<<"New balances for Saver2 account @ 3% and 4% respectively are :\n";
cout<<"\n";
saver2.cal_monthlyInterest();
saver2.showBalance();
saver2.modifyInterestRate();
cout<<"\n";
saver2.cal_monthlyInterest();
saver2.showBalance();
cout<<"\n";
cout<<"\n"<<"---------------------------------------------------------------
----------------"<<"\n";
return 0;
}
OUTPUT
The program calculates 2 fixed interest rates for 2 fixed accounts.
New balances for Saver1 account @ 3% and 4% respectively are :
Balance is : $-1.54266e+064
Balance is : $-1.5478e+064
New balances for Saver2 account @ 3% and 4% respectively are :
Balance is : $-2.31399e+064
Balance is : $-2.3217e+064
you see what is generating that problem
Any help will be appreciated.
/* Create a savings accountclass. Use a dat data member to contain the
annualInterest rate
for each of the savers. Each member of the calss contains a private
membr savingsBalance
indicating the amount the saver currently has on deposit.Provide a
calculate MonthlyInterest
member function that calculates the monthly interest by mulyiplying the
balance by annualInterestRate
divided by 12; This interest should be added to savingssBalance. Provide
a member funtion
modifyInterestRate tahe sets the annualInteretrte to a new value. Write
adriver proram to test
clas savings Account. Instantiate two different savingsAccount objects,
saver1 and saver2, with balances of
$2000 and $3000,respectively. Set annual interest rate to 3% than calculate
the monthly interest rate and print
the new balances for eac of the savers.Then set the annual interset rate to
4% and calculate the next month's
interest and print the new balances for each of rthe savers */
#include <iostream>
using namespace std;
class SavingsAccount //class definition
{
public: // prototypes of member functions
SavingsAccount(double);
double cal_monthlyInterest();
void modifyInterestRate();
void showBalance();
private: //Data Member
double savingsBalance;
double annualInterestRate;
};
SavingsAccount::SavingsAccount(double balance) //constructor
{
savingsBalance = balance;
}
double SavingsAccount::cal_monthlyInterest()
{
SavingsAccount::savingsBalance += (annualInterestRate/12) *
savingsBalance;
return savingsBalance;
}
void SavingsAccount::modifyInterestRate()
{
SavingsAccount::annualInterestRate = 0.04;
}
void SavingsAccount:: showBalance()
{
cout<< "Balance is : $"<<SavingsAccount::savingsBalance<<"\n";
}
int main()
{
SavingsAccount saver1(2000);
SavingsAccount saver2(3000);
cout<<"\n";
cout<<" The program calculates 2 fixed interest rates for 2 fixed
accounts.\n";
cout<<"\n";
cout<<"New balances for Saver1 account @ 3% and 4% respectively are :\n";
cout<<"\n";
saver1.cal_monthlyInterest();
saver1.showBalance();
cout<<"\n";
saver1.modifyInterestRate();
saver1.cal_monthlyInterest();
saver1.showBalance();
cout<<"\n";
cout<<"New balances for Saver2 account @ 3% and 4% respectively are :\n";
cout<<"\n";
saver2.cal_monthlyInterest();
saver2.showBalance();
saver2.modifyInterestRate();
cout<<"\n";
saver2.cal_monthlyInterest();
saver2.showBalance();
cout<<"\n";
cout<<"\n"<<"---------------------------------------------------------------
----------------"<<"\n";
return 0;
}
OUTPUT
The program calculates 2 fixed interest rates for 2 fixed accounts.
New balances for Saver1 account @ 3% and 4% respectively are :
Balance is : $-1.54266e+064
Balance is : $-1.5478e+064
New balances for Saver2 account @ 3% and 4% respectively are :
Balance is : $-2.31399e+064
Balance is : $-2.3217e+064