I am trying to construct a class with several functions and identifiers. The identifier in question is static double AIR which will hold the value of the annual interest rate in the class.
I have been getting an error message that I can't seem to get rid of:
error C2065: 'AIR' undeclared identifier
I have never worked with static identifiers before and I think I'm leaving something out somewhere but I don't know what.
Here's the header and .cpp files:
Any Ideas?
Thanks!
I have been getting an error message that I can't seem to get rid of:
error C2065: 'AIR' undeclared identifier
I have never worked with static identifiers before and I think I'm leaving something out somewhere but I don't know what.
Here's the header and .cpp files:
Any Ideas?
Code:
#ifndef SAVINGSACCOUNT_H
#include <iostream>
using namespace std;
class SavingsAccount
{
public:
SavingsAccount(int objn, double rate);
SavingsAccount(int objn, string fn, string ln, double rate);
SavingsAccount(int objn, string fn, string ln, double bal, double rate);
void setName(string, string);
// string getName() const;
string getFirstName();// const;
string getLastName();// const;
void setBalance(double);
double getBalance();// const;
static void setInterestRate(double);
static double getInterestRate();
int getNumber();// const;
double calculateNewBalance(double oldBalance);
~SavingsAccount();
private:
string firstName;
string lastName;
double savingBalance;
// const int objectnumber;
int objectnumber;
static double AIR;
};
#endif
Code:
#include <iostream>
#include <iomanip>
using namespace std;
#include "SavingsAccount.h"
double SavingsAccount::AIR = 0.05;
//constructor with no parameters***************
SavingsAccount::SavingsAccount(int objn, double rate)
{
objectnumber = objn;
firstName = "";
lastName = "";
savingBalance = 0.00;
setInterestRate(rate);
}
//constructor with name parameters******************
SavingsAccount::SavingsAccount(int objn, string fn, string ln, double rate)
{
objectnumber = objn;
setName(fn, ln);
setBalance(0.00);
setInterestRate(rate);
}
//constructor with name parameters and balance parameter*****
SavingsAccount::SavingsAccount(int objn, string fn, string ln, double bal, double rate)
{
objectnumber= objn;
setName(fn, ln);
setBalance(bal);
setInterestRate(rate);
}
//void setName()*********************************
void SavingsAccount::setName(string fn, string ln)
{
firstName = fn;
lastName = ln;
}
//string getName()const**************************
string SavingsAccount::getFirstName() //const
{
return firstName;
}
string SavingsAccount::getLastName() //const
{
return lastName;
}
//void setBalance()******************************
void SavingsAccount::setBalance(double bal)
{
savingBalance = bal;
}
//double getBalance()const***********************
double SavingsAccount::getBalance() //const
{
return savingBalance;
}
//static void setInterestRate()******************
//static void SavingsAccount::setInterestRate(double rate)
static void setInterestRate(double rate)
{
AIR = rate;
}
//static double getInterestRate()****************
//static double SavingsAccount::getInterestRate()
static double getInterestRate()
{
return AIR;
}
//getNumber()***********************************
int SavingsAccount::getNumber() //const
{
return objectnumber;
}
//calculateNewBalance()***************************
double SavingsAccount::calculateNewBalance(double oldBalance)
{
double newBalance = oldBalance + (oldBalance * (AIR/12));
return newBalance;
}
//destructor, message: "gone out of scope"***********
SavingsAccount::~SavingsAccount()
{
cout<<"Object "<<objectnumber<<" has gone out of scope"<<endl;
}
Comment