Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment asks you to add some code to the program. Do not change the code

ID: 3567394 • Letter: T

Question

This assignment asks you to add some code to the program. Do not change the code, simply add to it as follows:

a. Overload the >> operator to allow for reading a new name and new balance from the keyboard and use the data to update the object's data members. example cin>>obj1;

b. Overload the << operator to display the Name, Balance, and Interest Rate of an object on the screen with proper labels. Do not use a Display Function. example use cout<<obj1; Fileout obj1; ofstream Fileout;

c. Overload the += operator to allow an increase to a saver's Balance. Use a void member function. The function call will have the following syntax: Saver1 += 10000;

d. Overoad the -= operator to allow a decrease to a saver's Balance.Use a void member function. Syntax should be Saver1 -= 700;

e. Create a 4th object and use it to test all the member functions and overloaded operator functions.

f. make a list of tasks your program performs in main using psuedocode

//SavingsAccount headerfile

#include<iostream>
#include<string>
using namespace std;

class SavingsAccount
{
private:
   string firstName;
   string lastName;
   double savingBalance;
   static double annualInterestRate;
   const int objectnumber;
public:
   SavingsAccount();
   SavingsAccount(string f, string l);
   SavingsAccount(string f, string l, double b);

   void setName(string f, string l);

   string getName() const;

   void setBalance(double b);

   double getBalance() const;

   static void setInterestRate(double i);

   static double getInterestRate();

   int getNumber() const;

   void calculateNewBalance();

   ~SavingsAccount();
};

//SavingsAccount cpp file

#include "SavingsAccount.h"

double SavingsAccount::annualInterestRate = 5;
static int objectCount = 1;
// Default constructor-allow objects to be created without arguments.
SavingsAccount::SavingsAccount() :objectnumber(objectCount++)
{
   firstName = "";
   lastName = "";
   savingBalance = 0;
}

//Constructor that allows an object to be created with name arguments only.
SavingsAccount::SavingsAccount(string f, string l) :objectnumber(objectCount++)
{
   firstName = f;
   lastName = l;
   savingBalance = 0;
}

//COnstructor that allows an object to be created with name arguments and beginning balance.
SavingsAccount::SavingsAccount(string f, string l, double b) :objectnumber(objectCount++)
{
   firstName = f;
   lastName = l;
   savingBalance = b;
}

//Setting a serial number to each object
void SavingsAccount::setName(string f, string l)
{
   firstName = f;
   lastName = l;
}
string SavingsAccount::getName() const
{
   return firstName + "" + lastName;
}
void SavingsAccount::setBalance(double b)
{
   savingBalance = b;
}
double SavingsAccount::getBalance() const
{
   return savingBalance;
}
void SavingsAccount::setInterestRate(double i)
{
   annualInterestRate = i;
}
double SavingsAccount::getInterestRate()
{
   return annualInterestRate;
}
int SavingsAccount::getNumber() const
{
   return objectnumber;
}
void SavingsAccount::calculateNewBalance()
{
   savingBalance = savingBalance + savingBalance * annualInterestRate / 12;
}
SavingsAccount::~SavingsAccount()
{
   cout << "Object no longer exist." << endl;
}

// Main cpp file

#include <iostream>
#include <string>
#include "SavingsAccount.h"
using namespace std;

int main()
{
   SavingsAccount Saver1("Margaret", " Olson", 2000);
   SavingsAccount Saver2("Debra", " Baxter");
   SavingsAccount Saver3;

   Saver2.setBalance(5000);
   Saver3.setName("Arturo"," Ortiz");
   Saver3.setBalance(10000);

   Saver1.calculateNewBalance();
   Saver2.calculateNewBalance();
   Saver3.calculateNewBalance();

   cout << "Customer account name is " << Saver1.getName() << " with account number " << Saver1.getNumber() << " Balance is " << Saver1.getBalance() << endl;
   cout << " Customer account name is " << Saver2.getName() << " with account number " << Saver2.getNumber() << " Balance is " << Saver2.getBalance() << endl;
   cout << " Customer account name is " << Saver3.getName() << " with account number " << Saver3.getNumber() << " Balance is " << Saver3.getBalance() << endl;

   SavingsAccount::setInterestRate(10);
   Saver1.calculateNewBalance();
   Saver2.calculateNewBalance();
   Saver3.calculateNewBalance();

   cout <<"" << endl;
   cout << "New monthly balance with the annual interest rate at 10%:" << endl;
   cout << "---------------------------------------------------------" << endl;

   cout << "Customer account name is " << Saver1.getName() << " with account number " << Saver1.getNumber() << " Balance is " << Saver1.getBalance() << endl;
   cout << " Customer account name is " << Saver2.getName() << " with account number " << Saver2.getNumber() << " Balance is " << Saver2.getBalance() << endl;
   cout << " Customer account name is " << Saver3.getName() << " with account number " << Saver3.getNumber() << " Balance is " << Saver3.getBalance() << endl;

   system("pause");
   return 0;
}

Explanation / Answer

Main.cpp

-------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>
#include <string>
#include "SavingsAccount.h"
using namespace std;

int main()
{
   SavingsAccount Saver1("Margaret", " Olson", 2000);
   SavingsAccount Saver2("Debra", " Baxter");
   SavingsAccount Saver3;
   //object 4
   SavingsAccount Saver4;

   Saver2.setBalance(5000);
   Saver3.setName("Arturo"," Ortiz");
   Saver3.setBalance(10000);

   Saver1.calculateNewBalance();
   Saver2.calculateNewBalance();
   Saver3.calculateNewBalance();

   cout << "Customer account name is " << Saver1.getName() << " with account number " << Saver1.getNumber() << " Balance is " << Saver1.getBalance() << endl;
   cout << " Customer account name is " << Saver2.getName() << " with account number " << Saver2.getNumber() << " Balance is " << Saver2.getBalance() << endl;
   cout << " Customer account name is " << Saver3.getName() << " with account number " << Saver3.getNumber() << " Balance is " << Saver3.getBalance() << endl;

   SavingsAccount::setInterestRate(10);
   Saver1.calculateNewBalance();
   Saver2.calculateNewBalance();
   Saver3.calculateNewBalance();

   //object 4 function
   cin>>Saver4;
   cout<<endl <<Saver4;
   Saver4+=100;
   Saver4-=50;


   cout <<"" << endl;
   cout << "New monthly balance with the annual interest rate at 10%:" << endl;
   cout << "---------------------------------------------------------" << endl;

   cout << "Customer account name is " << Saver1.getName() << " with account number " << Saver1.getNumber() << " Balance is " << Saver1.getBalance() << endl;
   cout << " Customer account name is " << Saver2.getName() << " with account number " << Saver2.getNumber() << " Balance is " << Saver2.getBalance() << endl;
   cout << " Customer account name is " << Saver3.getName() << " with account number " << Saver3.getNumber() << " Balance is " << Saver3.getBalance() << endl;

   system("pause");



   return 0;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SavingsAccount.cpp

--------------------------------------------------------------------------------------------------------------------

#include "SavingsAccount.h"

double SavingsAccount::annualInterestRate = 5;
static int objectCount = 1;
// Default constructor-allow objects to be created without arguments.
SavingsAccount::SavingsAccount() :objectnumber(objectCount++)
{
   firstName = "";
   lastName = "";
   savingBalance = 0;
}

//Constructor that allows an object to be created with name arguments only.
SavingsAccount::SavingsAccount(string f, string l) :objectnumber(objectCount++)
{
   firstName = f;
   lastName = l;
   savingBalance = 0;
}

//COnstructor that allows an object to be created with name arguments and beginning balance.
SavingsAccount::SavingsAccount(string f, string l, double b) :objectnumber(objectCount++)
{
   firstName = f;
   lastName = l;
   savingBalance = b;
}

//Setting a serial number to each object
void SavingsAccount::setName(string f, string l)
{
   firstName = f;
   lastName = l;
}
string SavingsAccount::getName() const
{
   return firstName + "" + lastName;
}

void SavingsAccount::setBalance(double b)
{
   savingBalance = b;
}
double SavingsAccount::getBalance() const
{
   return savingBalance;
}
void SavingsAccount::setInterestRate(double i)
{
   annualInterestRate = i;
}
double SavingsAccount::getInterestRate()
{
   return annualInterestRate;
}
int SavingsAccount::getNumber() const
{
   return objectnumber;
}
void SavingsAccount::calculateNewBalance()
{
   savingBalance = savingBalance + savingBalance * annualInterestRate / 12;
}

void SavingsAccount::operator +=(double bal){
   savingBalance+=bal;  
}
void SavingsAccount::operator -=(double bal){
   savingBalance-=bal;  
}


ostream &operator<<( ostream &Fileout,SavingsAccount& s1)
{
   cout <<"Name : " <<s1.getName();
   cout <<" Account Number : "<<s1.getNumber();
   cout <<" Balance : " <<s1.getBalance();
   cout <<" Interest Rate : "<<s1.getInterestRate();
   return Fileout;
}
istream &operator >>(istream &Filein,SavingsAccount& s1){
   string n1,n2;
   double bal=0;
   double intRate=0;
   cout <<"Enter First Name: ";
   cin >> n1;
   cout <<"Enter second Name: ";
   cin >>n2;
   cout <<"Enter Balance : ";
   cin >> bal;
   cout <<"Enter Interest Rate : ";
   cin >> intRate;

   s1.setName(n1,n2);
   s1.setBalance(bal);
   s1.setInterestRate(intRate);
   return Filein;

}
SavingsAccount::~SavingsAccount()
{
   cout << " Object no longer exist." ;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SavingsAccount.h

-----------------------------------------------------------------------------------------------------------------

#include<iostream>
#include<string>
using namespace std;

class SavingsAccount
{
private:
   string firstName;
   string lastName;
   double savingBalance;
   static double annualInterestRate;
   const int objectnumber;
public:
   SavingsAccount();
   SavingsAccount(string f, string l);
   SavingsAccount(string f, string l, double b);

   void setName(string f, string l);

   string getName() const;

   void setBalance(double b);

   double getBalance() const;

   static void setInterestRate(double i);

   static double getInterestRate();

   int getNumber() const;

   void calculateNewBalance();

   void operator +=(double bal);

   void operator -=(double bal);

   friend ostream &operator<<( ostream &Fileout,SavingsAccount &s1);

   friend istream &operator>>( istream &Filein,SavingsAccount &s1);

   ~SavingsAccount();
};