Alright I had everything working until I started to incorporate my interst rate I'll post my header and cpp to see if anyone can steer me straight.
This is the error and I've tried tinkering quite a bit with no avail:
error LNK2001: unresolved external symbol "private: static double SavingsAccount::annualInterestRate" (?annualInterestRate@SavingsAccount@@0NA)
1>c:\Project2\Debug\Project2.exe : fatal error LNK1120: 1 unresolved externals
Code:
#include "SavingsAccount.h"
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
extern ofstream fileout;
// constructor function with 0 parameters
SavingsAccount::SavingsAccount()
{
setFirstName("");
setLastName ("");
setBalance (0.0);
setInterestRate (.05);
}
// constructor functions with 1 parameter
SavingsAccount::SavingsAccount (string first, string last )
{
setFirstName (first);
setLastName (last);
setBalance (0.0);
setInterestRate (.05);
}
// constructor function with 2 parameters
SavingsAccount::SavingsAccount(string first, string last, double balance)
{
setFirstName (first);
setLastName (last);
setBalance (balance);
setInterestRate (.05);
}
// calculate balance
double SavingsAccount::calcNewBalance()
{
monthlyRate = annualInterestRate/12;
return (monthlyRate * savingBalance) + savingBalance;
}
// set functions
void SavingsAccount::setInterestRate(double rate)
{
annualInterestRate = rate;
}
void SavingsAccount::setFirstName(string f)
{
firstName = f;
}
void SavingsAccount::setLastName(string l)
{
lastName = l;
}
// set balance
void SavingsAccount::setBalance (double b)
{
savingBalance = b;
}
// get functions
double SavingsAccount::getInterestRate(double rate)
{
return annualInterestRate;
}
string SavingsAccount::getFirstName()
{
return firstName;
}
string SavingsAccount::getLastName()
{
return lastName;
}
// get balance
double SavingsAccount::getBalance() const
{
return savingBalance;
}
// print function
void SavingsAccount::printData()
{
cout<< "\nName: " << firstName <<" "<< lastName;
cout<< "\nBalance: " << savingBalance;
cout<< "\nNew Balalce: " << calcNewBalance();
}
Code:
//SavingsAccount.h
//Defintion of class SavingsAccount
#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include <string>
using namespace std;
class SavingsAccount
{
public:
//overloaded constructor functions
SavingsAccount ();
SavingsAccount (string, string);
SavingsAccount (string, string, double);
//set functions
void setFirstName ( string );
void setLastName ( string );
void setBalance ( double );
void static setInterestRate ( double );
//get functions
string getFirstName();
string getLastName();
double getBalance() const;
static double getInterestRate (double);
//calculation functions
double calcNewBalance();
//print functions
void printData();
private:
string firstName;
string lastName;
double savingBalance;
double monthlyRate;
static double annualInterestRate;
int objectnumber;
};
#endif