I'm having a bit of trouble figuring out what i'm doing wrong with my overloaded operators
Header file
#ifndef SavingsAccount_H
#define SavingsAccount_H
#include <string>
using namespace std;
class SavingsAccount
{
friend istream &operator >>(istream& input, SavingsAccount & );
friend ostream &operator <<(ostream& output, const SavingsAccount & );
public:
SavingsAccount();
SavingsAccount(string, string);
SavingsAccount(string, string, double);
~SavingsAccount();
SavingsAccount& operator+=(const SavingsAccount& );
SavingsAccount& operator-=(const SavingsAccount& );
void setFirstName(string);
void setLastName(string);
void setSavingsBalance(double);
string getFirstName() const;
string getLastName() const;
double getSavingsBalance() const;
void printInfo();
int getNumber() const;
int getObjCount();
static double getIntrestRate();
void static setIntrestRate(double);
void CalculateNewBalance();
private:
string FirstName;
string LastName;
double SavingsBalance;
static double AnnualIntrestRate;
static int objcount;
const int ObjectNumber;
};
#endif
Member functions
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include "SavingsAccount.h"
using namespace std;
double SavingsAccount::AnnualIntrestRate = .05;
int SavingsAccount::objcount = 0;
SavingsAccount::SavingsAccount():ObjectNumber(++objcount)
{
FirstName = LastName = "";
SavingsBalance = 0;
}
SavingsAccount::SavingsAccount(string First, string Last):ObjectNumber(++objcount)
{
setFirstName(First);
setLastName(Last);
setSavingsBalance(0);
}
SavingsAccount::SavingsAccount(string First, string Last, double Balance):ObjectNumber(++objcount)
{
setFirstName(First);
setLastName(Last);
setSavingsBalance(Balance);
}
void SavingsAccount::setFirstName(string First)
{
FirstName = First;
}
void SavingsAccount::setLastName(string Last)
{
LastName = Last;
}
void SavingsAccount::setSavingsBalance(double Balance)
{
SavingsBalance = Balance;
}
void SavingsAccount::setIntrestRate(double Intrest)
{
AnnualIntrestRate = Intrest;
}
string SavingsAccount::getFirstName() const
{
return FirstName;
}
string SavingsAccount::getLastName() const
{
return LastName;
}
double SavingsAccount::getIntrestRate()
{
return AnnualIntrestRate;
}
double SavingsAccount::getSavingsBalance() const
{
return SavingsBalance;
}
int SavingsAccount::getNumber() const
{
return ObjectNumber;
}
void SavingsAccount::CalculateNewBalance()
{
SavingsBalance = SavingsBalance + SavingsBalance * AnnualIntrestRate / 12;
}
void SavingsAccount::printInfo()
{
cout << "The users serial number is " << ObjectNumber << "." << endl << "The users name is " << FirstName << " " << LastName << "." << endl;
cout << "The users starting balance is $" << SavingsBalance << "." << endl << endl;
}
SavingsAccount::~SavingsAccount()
{
cout << "The object with a first name of " << FirstName << " and a last name of " << LastName << " and a serial number of " << ObjectNumber << " has gone out of scope. " << endl << endl;
}
int SavingsAccount::getObjCount()
{
return objcount;
}
istream &operator >>(istream& input, SavingsAccount &Info )
{
input >> Info.FirstName;
input >> Info.LastName;
input >> Info.SavingsBalance;
return input;
}
ostream &operator <<(ostream& output, const SavingsAccount &Info)
{
output << "The users first name is " << Info.FirstName << endl;
output << "The users last name is " << Info.LastName << endl;
output << "The users balance is " << Info.SavingsBalance << endl;
output << "The users intrest rate is " << Info.AnnualIntrestRate << endl;
return output;
}
const SavingsAccount &SavingsAccount::operator+=(const SavingsAccount& double increase )
{
SavingsBalance += increase;
return *this;
}
const SavingsAccount &SavingsAccount::operator-=(const SavingsAccount& double decrease )
{
SavingsBalance -= decrease;
return *this;
}
main
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include "SavingsAccount.h"
using namespace std;
int main()
{
cout << setprecision(2) << fixed;
SavingsAccount SaverOne("Margaret" , "Olson", 2000.00);
SavingsAccount SaverTwo("Debra" , "Baxter");
SavingsAccount SaverThree("", "");
SaverTwo.setSavingsBalance(5000.00);
SaverThree.setFirstName("Aruro");
SaverThree.setLastName("Ortiz");
SaverThree.setSavingsBalance(10000.00);
SaverOne.CalculateNewBalance();
SaverTwo.CalculateNewBalance();
SaverThree.CalculateNewBalance();
cout << "The first users new monthly balance is " << SaverOne.getSavingsBalance() << endl;
cout << "The second user new monthly balance is " << SaverTwo.getSavingsBalance() << endl;
cout << "The Third users new monthly balance is " << SaverThree.getSavingsBalance() << endl << endl;
cout << "The first users information is ";
SaverOne.printInfo();
cout << "The second users information is ";
SaverTwo.printInfo();
cout << "The third users information is ";
SaverThree.printInfo();
SavingsAccount::setIntrestRate(.10);
SaverOne.CalculateNewBalance();
SaverTwo.CalculateNewBalance();
SaverThree.CalculateNewBalance();
cout << "The first users new monthly balance is " << SaverOne.getSavingsBalance() << endl;
cout << "The second user new monthly balance is " << SaverTwo.getSavingsBalance() << endl;
cout << "The Third users new monthly balance is " << SaverThree.getSavingsBalance() << endl << endl;
cout << "The first users information is ";
SaverOne.printInfo();
cout << "The second users information is ";
SaverTwo.printInfo();
cout << "The third users information is ";
SaverThree.printInfo();
// programming assignment 3 main starts here
SavingsAccount SaverFour("", "");
cout << "enter your first name, last name, account balance: " << endl;
cin >> SaverFour;
cout << "The information given was: ";
cout <<SaverFour << endl;
cout << "the users saving balance after increase is " << endl;
cout << SaverFour.getSavingsBalance()+= 1000.00;
cout << "The users saving balance after decrease is ";
cout << SaverFour.getSavingsBalance()-= 2000.00;
}
Here are the errors i get. Please note that everything else works great, I just can't get += or -= going correctly
Error 1 error C2676: binary '+=' : 'std::basic_ostream<_Elem,_Traits>' does not define this operator or a conversion to a type acceptable to the predefined operator h:\c++\programming assignment three\programming assignment two\programming assignment two\main.cpp 76
Error 2 error C2676: binary '-=' : 'std::basic_ostream<_Elem,_Traits>' does not define this operator or a conversion to a type acceptable to the predefined operator h:\c++\programming assignment three\programming assignment two\programming assignment two\main.cpp 79
Error 3 error C2511: 'const SavingsAccount &SavingsAccount::operator +=(double)' : overloaded member function not found in 'SavingsAccount' h:\c++\programming assignment three\programming assignment two\programming assignment two\member functions.cpp 123
Error 4 error C2511: 'const SavingsAccount &SavingsAccount::operator -=(double)' : overloaded member function not found in 'SavingsAccount' h:\c++\programming assignment three\programming assignment two\programming assignment two\member functions.cpp 129
5 IntelliSense: the #endif for this directive is missing h:\c++\programming assignment three\programming assignment two\programming assignment two\savingsaccount.h 7
6 IntelliSense: expected a declaration h:\c++\programming assignment three\programming assignment two\programming assignment two\savingsaccount.h 51
7 IntelliSense: the #if for this directive is missing h:\c++\programming assignment three\programming assignment two\programming assignment two\savingsaccount.h 53
8 IntelliSense: no operator "+=" matches these operands h:\c++\programming assignment three\programming assignment two\programming assignment two\main.cpp 76
9 IntelliSense: no operator "-=" matches these operands h:\c++\programming assignment three\programming assignment two\programming assignment two\main.cpp 79