I got this question:
Create a SavingAccount class. Use a static data member annualInterestRate to store the annual interest rate for each of the savers. Each member of the class contains private data members: firstName, lastName, and savingsBalance to indicate the amount the saver currently has on deposit. Provide member function calculateMonthlyInterest that calculates the monthly interest by multiplying the balance by annualInterestRate divided by 12; this interest should be added to savingsBalance. Provide a static member function modifyInterestRate that sets the static annualInterestRate to a new value. Also, provide appropriate constructor, set functions, and get functions.

I did the definitions already. How would I write the implementation cpp file for it. I don't know much about this subject so any help is appreciated.

This is the definition I have:

#ifndef SAVINGACCOUNT_H
#define SAVINGACCOUNT_H


class SavingAccount
{
    public:
        /** Default constructor */
        SavingAccount();
        /** Default destructor */
        ~SavingAccount();
        string getfirstName() const
        string getlastName() const;
        static double modifyInterestRate();//static method declaration
        static double calculateMonthlyInterst(double,double);
        void setannualInterestRate(double)
        double getannualInterestRate() const;
        

    private:
        string firstName;
        string lastName;
        double savingsBalance;
        static double annualInterestRate;

};


#endif // SAVINGACCOUNT_H

Edited 5 Years Ago by Dexxta27: n/a

in your .cpp file you will need to include the .h file that the defenition is in. than you define the functions like you would a normal function but you have to add the class name to the front of the function name. note that if you are using templates you have to define the functions in the .h file

#include "class.h"

void ClassName::Function(int foobar)

I mean as in the file that states what these functions do. The pieces that I read call it the 'class implementation' or the 'test file'. I don't know exactly how to do it so I just need someone to help me with that

The site won't allow me to edit. I wasn't fully understanding it but now your answer makes perfect sense to me.

This article has been dead for over six months. Start a new discussion instead.