# Help Me with this homework problem Please!!

• 07-23-2002
Unregistered
Help Me with this homework problem Please!!
//The program says to Create a Savings Class. Use a static data member to contain the
//annual interestRat for each of the savers. Each member o the class contains a privcate data member savingsbalance indincating the amount the saver currently has on deposit.
//Provide data member SavingsBalance indicating he amount the saver currently has on deposit.
//Provide a calculateMonthlyInterest member function that calculates the monthly interest
//by multiplying the balance by annual InterestRate divide by 12
//This interest should be added to savings Balance.
//Provide a static member function modifyInterestRate that sets the satatic annual
//interestRate to a new value.
//Write a driver Program to test class with balance of \$200000 and 300000 respectively
//set annualInterestRate to 3%
//then calculate the monthly interest and print new balances for each savers
//Then set teh annualInterest Rate to 4% and calculate the next months interest and print the new balances
//for each of the savers

class SavingsAccount {

public:
SavingsAccount();

void calculateMonthlyInterest();
//static void modifyInterestrate(int);
void printbalance();

private:
static double savingsBalance;
double balance;

//int y;

//static data member
static double annualInterestRate;
};

double SavingsAccount::annualInterestRate = .3;
double SavingsAccount::savingsBalance = 20000;
//int SavingsAccount::modifyInterestrate = 4;

SavingsAccount::SavingsAccount()
{
savingsBalance = 0;
}

void SavingsAccount::calculateMonthlyInterest()
{
savingsBalance = savingsBalance * annualInterestRate/12.;

}

//void SavingsAccount::modifyInterestRate()
//{

//}

void SavingsAccount::printbalance()
{
cout<<"You balance is "<<savingsBalance;
}
int main()
{

SavingsAccount saver1;

//SavingsAccount saver2;
//cout<<" The current deposit for saver 1 is";

saver1.calculateMonthlyInterest;
saver1.printbalance;

return 0;

}

• 07-23-2002
geophyzzer
Well, not sure what the problem is (perhaps you could be more specific?) but if the problem is that you are getting the way wrong answer, try changing

Code:

```void SavingsAccount::calculateMonthlyInterest() {     savingsBalance = savingsBalance * annualInterestRate/12.; }```
to

Code:

```void SavingsAccount::calculateMonthlyInterest() {     savingsBalance += savingsBalance * annualInterestRate / 12.; }```
otherwise you are replacing the account balance with the interest instead of computing the interest and adding it. If this is not your problem please elaborate, and next time use code tags.
• 07-23-2002
Unregistered
//this is a problem in my text book..
//I just need to know about how to get started on it...
//Its not outputting anything

//The problem says to Create a Savings Class. Use a static data member to contain the
//annual interestRat for each of the savers. Each member o the class contains a private data member savingsbalance indincating the amount the saver currently has on deposit.
//Provide data member SavingsBalance indicating he amount the saver currently has on deposit.
//Provide a calculateMonthlyInterest member function that calculates the monthly interest
//by multiplying the balance by annual InterestRate divide by 12
//This interest should be added to savings Balance.
//Provide a static member function modifyInterestRate that sets the satatic annual
//interestRate to a new value.
//Write a driver Program to test class with balance of \$200000 and 300000 respectively
//set annualInterestRate to 3%
//then calculate the monthly interest and print new balances for each savers
//Then set teh annualInterest Rate to 4% and calculate the next months interest and print the new balances
//for each of the savers
• 07-23-2002
fletch
It looks like you have a good start. If you keep going, you'll probably get to where you want to go.

Do you have a more specific question than "Help me?" People are glad to help, but you need to ask specific questions. Also, there's no need to put double slashes // in // front // of //every //line.
• 07-23-2002
Unregistered
OK thanx
Well for one the program wont run...
copy and paste for me and run...
• 07-23-2002
fletch
OK, lets look at you SavingsAccount class.
Quote:

Use a static data member to contain the
//annual interestRat for each of the savers. Each member o the class contains a privcate data member savingsbalance indincating the amount the saver currently has on deposit.
A static variable is a variable that is accessible by all instances of a class. That means that every SavingsAccount that you create will share the static variables and if any of the SavingsAccount classes changes a static variable, then that variable changes in every SavingsAccount. In your problem, you want every SavingsAccount to have the same annualInterestRate, so you declared annualInterestRate as static. However, not every savings account has the same balance. So savingsBalance shouldn't be a static variable.
Quote:

//Provide a static member function modifyInterestRate that sets the satatic annual
//interestRate to a new value
You've declared static double annualInterestRate as a private variable, which is good. As a general rule, class variables should be private and you should provide functions that allow the user of a class to modify the variable. In this case, you want to create a static function called SavingsAccount::modifyInterestRate that takes an interest rate as an input. All the function will do is set annualInterestRate to the new interest rate. Pretty simple.
Quote:

//Provide a calculateMonthlyInterest member function that calculates the monthly interest
//by multiplying the balance by annual InterestRate divide by 12
//This interest should be added to savings Balance.
Looks like you've got it. Just make the change suggested by geophyzzer.
Quote:

//Provide data member SavingsBalance indicating he amount the saver currently has on deposit.
I assume that this is referring to a function, not a variable. Looks like you've got it with your function SavingsAccount::PrintBalance()

You need to be able to make deposits to your savings account. So you need to create a class function to add a deposited amount to your savingsBalance.

This should move you on your way.

fletch