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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.