I am writing a Savings account program using a class with methods but it won't compile. I can't seem to figure out why.
Hhere is my program. It contains an header file, source code file, and a program cpp file:
Here is part of the error I get,
C:\Users\JEFF~1.JEF\AppData\Local\Temp\ccWScaaa.o(.text+0x17a) In function main': [Linker error] undefined reference to
SavingsAccount::SavingsAccount(double)'
......
any help or pointers would be appreciated.
--------------------------
(Header File):
//Header file
#ifndef FILENAME_H
#define FILENAME_H
class SavingsAccount
{
public:
SavingsAccount(double a);
~SavingsAccount();
static double modifyInterestRate(double b);
double calculateMonthlyInterest();
void printBalance();
private:
static double annInterestRate;
double saBalance;
};
#endif
//end
(SavingsAccount .ccp):
#include <iostream>
#include "SavingsAccount.h"
using namespace std;
SavingsAccount::SavingsAccount(double a)
{
saBalance = a;
annInterestRate = 0;
}
SavingsAccount::~SavingsAccount()
{
}
double SavingsAccount::modifyInterestRate(double b)
{
annInterestRate = b;
}
double SavingsAccount::calculateMonthlyInterest()
{
double interest = saBalance * annInterestRate;
saBalance = saBalance + interest;
}
void SavingsAccount::printBalance()
{
cout << saBalance << endl;
}
double SavingsAccount::annInterestRate;
//end of Class Definition
(Program Driver cpp)
using namespace std;
#include <iostream>
#include <iomanip>
#include "SavingsAccount.h"
// Driver program below
int main()
{
SavingsAccount saver1( 2000.0 );
SavingsAccount saver2( 3000.0 );
SavingsAccount::modifyInterestRate( .03 ); // change interest rate
cout << "Initial balances:\nSaver 1: ";
saver1.printBalance();
cout << "\tSaver 2: ";
saver2.printBalance();
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
cout << "\n\nBalances after 1 month's interest applied at .03:\n"
<< "Saver 1: ";
saver1.printBalance();
cout << "\tSaver 2: ";
saver2.printBalance();
SavingsAccount::modifyInterestRate( .04 ); // change interest rate
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
cout << "\n\nBalances after 1 month's interest applied at .04:\n"
<< "Saver 1: ";
saver1.printBalance();
cout << "\tSaver 2: ";
saver2.printBalance();
cout << endl;
system("pause");
return 0;
}
//end of main
----------
~Jeff