0

Hi I'm into a code in which I have to Design a class named Account that contain:
1. Int data field named "id" for the account.
2. Double data field named "balance" for the account.
3. Double data field named annualInterestRate that stores the current interest rate.
4. A no-arg constructor that creats a default account with "id 0, balance 0, and annualInterestRate 0."
5. Create a function named getMonthlyInterestRate() that returns the monthly interest rate.
6. A function named withdraw that withdraws a specified amount from the account.
7. A function named deposits a specified amount to the account.

My question is how do I create a named "getMonthlyInterestRate() that returns the monthly interest rate. This what I have so far.
[/TEXT]

#include <cstdlib>
#include <iostream>

using namespace std;

class Account
{
      private:
              int id;
              double balance;
              double annualInteresetRate;
public:
       Account ()
       {
               id = 0;
               balance = 0;
               annualInterestRate = 0;
               }
       
       int getId()
       {
           return id;
           }
       
       int getBalance()
       {
           return balance;
           }
           
       int getAnnualInterestRate()
       {
           return AnnualInterestRate;
           }
           
           
       
               
               
               

int main(int argc, char *argv[])
{
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by VernonDozier
0

Before tackling your question, you need to get the thing to compile with what you have and follow the spec...

Double data field named annualInterestRate that stores the current interest rate.

Now your code...

private:
int id;
double balance;
double annualInteresetRate;

So far so good.


But look at line 30.

int getAnnualInterestRate()
{
return AnnualInterestRate;
}

Capitalization counts. So does spelling. There is no variable called AnnualInteresetRate. See the error message you get when you compile. Don't move on till it's fixed. Look at the red. If your function returns an int, it needs to return an int, not a double, and that's after you fix the spelling and capitalization. The brackets problem should be obvious. Fix all that and the other problems first. This is all before we even get to your actual question.

As to your actual question, how would you figure out what the monthly interest rate was given the annual with pencil and paper? There's a formula. Figure out what the formula is. The formula you write in the code will be the same one you write on paper.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.