//customer.h //#ifndef CUSTOMER_H //#define CUSTOMER_H #include #include using n
ID: 3557265 • Letter: #
Question
//customer.h
//#ifndef CUSTOMER_H
//#define CUSTOMER_H
#include
#include
using namespace std;
class Customer
{
private:
string accountID;
string name;
public:
Customer();
Customer(string, string);
void view();
Customer operator= (const Customer &);
};
//#endif
//customer.cpp
//#include
//#include
//#include "customer.h"
//using namespace std;
Customer::Customer()
{
name="";
accountID="";
}
Customer::Customer(string n, string a)
{
name = n;
accountID = a;
}
void Customer::view()
{
cout << name;
cout << accountID;
}
Customer Customer::operator= (const Customer &obj)
{
name = obj.name;
accountID = obj.accountID;
return *this;
}
//account.h
//#ifndef ACCOUNT_H
//#define ACCOUNT_H
//#include "customer.h"
class Account // base class account
{
protected:
float balance; //amount in the account
Customer cust; //Customer Object
public:
Account();
Account(double, Customer);
void makeDeposit(float);
float getBalance();
virtual bool makeWithdrawal(float);
virtual void adjustBalance();
virtual void view();
};
//#endif
//account.cpp
//#include
//#include "customer.h"
//#include "account.h"
//using namespace std;
Account::Account() //calls the no argument contructor Customer constructor for default inialiazation
{
balance = 0.0;
Customer::Customer(); // the call to the customer no argu. constructor
}
/*two-argument constructor which sets balance to the value of the first parameter,
a floating point value entered by the user in the test driver, and sets cust to the value of the second parameter,
the Customer variable c created and initialized in the test driver, using the overloaded assignment operator of the
Customer class*/
Account::Account(double bal, Customer cust)
{
balance = bal;
}
void Account::makeDeposit(float depo)
{
balance += depo;
}
bool Account::makeWithdrawal(float withd)
{
balance -= withd;
return true;
}
void Account::view()
{
cust.view();
cout << " Balance: $ " << balance << endl;
}
float Account::getBalance()
{
return balance;
}
void Account::adjustBalance() //does nothing is a pure virtual
{}
//saving.h
//#ifndef SAVINGS_H
//#define SAVINGS_H
//#include "account.h"
class Savings : public Account
{
private:
float interestRate; //monthly interest rate
public:
Savings();
Savings(Customer, double, float);
void makeDeposit(float);
bool makeWithdrawal(float);
void adjustBalance();
virtual void view();
};
//#endif
//saving.cpp
//#include
//#include "savings.h"
//using namespace std;
Savings::Savings()
{
interestRate = 0;
Account::Account(); // invokes the account no argu. contructor
}
Savings::Savings(Customer custy, double bal , float rate) : Account(bal, custy)
{
Account::Account(bal,custy);
interestRate = rate;
}
void Savings::makeDeposit(float depos)
{
Account::makeDeposit(depos);
}
bool Savings::makeWithdrawal(float with)
{
if (balance - with < 0)
return false;
else
Account::makeWithdrawal(with);
return true;
}
void Savings::adjustBalance()
{
Account::balance = (interestRate * balance) + balance;//updates the balance
}
void Savings::view()
{
cout << "Savings Account" << endl;
Account::view();
}
//checking.h
//#ifndef CHECKING_H
//#define CHECKING_H
//#include "account.h"
class Checking : public Account
{
private:
bool overdraftProtection;
public:
Checking();
Checking(Customer, double, bool);
void makeDeposit(float);
bool makeWithdrawal(float);
void adjustBalance();
virtual void view();
};
//#endif
//checking.cpp
//#include
//#include "checking.h"
//using namespace std;
Checking::Checking()
{
Account::Account();
overdraftProtection = false;
}
Checking::Checking(Customer custy,double bal, bool Protect) : Account(bal, cust)
{
overdraftProtection = Protect;
}
void Checking::makeDeposit(float depos)
{
Account::makeDeposit(depos);
}
bool Checking::makeWithdrawal(float with)
{
if (balance - with > 0) //if remaning balance is not neg. ask for protection if true call withraw
if (overdraftProtection = true)
Account::makeWithdrawal(with);
else
return false; //return false if not true
}
void Checking::adjustBalance()
{
const int servCharge = 10;
const int min = 1000;
if (balance < min)
Account::balance -= servCharge;
}
void Checking::view()
{
cout << "Checking Account:" << endl;
Account::view();
}
//test.cpp
//#include
//#include "account.h"
//#include "checking.h"
//#include "savings.h"
//using namespace std;
const int MAX = 4;
void doTransactions(Account*);
int main()
{
Account* acctsPtr[MAX];
char acctType;
bool validType = true;
string custName; // char custName[NAME_SIZE];
string acctID; //char acctID[ID_SIZE];
double startBal;
int aNum;
for (aNum = 0; aNum < MAX && validType; aNum++)
{
cout << "Enter c for checking; s for savings; any other character to quit: ";
cin >> acctType;
acctType = tolower(acctType);
if (acctType == 'c' || acctType == 's')
{
cout << "Enter customer name: ";
cin >> custName;
cout << "Enter account number: ";
cin >> acctID;
cout << "Enter account beginning balance: ";
cin >> startBal;
}
switch (acctType)
{
case 'c':
{
char response;
bool overdraftOk;
cout << "Does this account have overdraft protection? ";
cin >> response;
overdraftOk = (tolower(response) == 'y') ? true : false;
Customer c(custName, acctID);
acctsPtr[aNum] = new Checking(c, startBal, overdraftOk);
doTransactions(acctsPtr[aNum]);
acctsPtr[aNum]->adjustBalance();
cout << "Balance after service charge (if any): " <<
acctsPtr[aNum]->getBalance() << endl;
break;
}
case 's':
{
double intRate;
cout << "Enter current monthly interest rate: ";
cin >> intRate;
Customer c(custName, acctID);
acctsPtr[aNum] = new Savings(c, startBal, intRate);
doTransactions(acctsPtr[aNum]);
acctsPtr[aNum]->adjustBalance();
cout << "Balance after interest: " <<
acctsPtr[aNum]->getBalance() << endl;
break;
}
default:
validType = false;
aNum--;
break;
}
}
int totalAccts = aNum;
cout << " Accounts: ";
for (int i = 0; i < totalAccts; i++)
{
acctsPtr[i]->view();
cout << " ";
}
for (int i = 0; i < totalAccts; i++)
delete acctsPtr[i];
}
void doTransactions(Account * aPtr)
{
double depAmt, withdAmt;
cout << "Enter total deposits: ";
cin >> depAmt;
aPtr->makeDeposit(depAmt);
cout << "Balance after deposits: "
<< aPtr->getBalance() << endl;
cout << "Enter total withdrawals: ";
cin >> withdAmt;
if (aPtr->makeWithdrawal(withdAmt))
cout << "Balance after withdrawals: "
<< aPtr->getBalance() << endl;
else
cout << "Withdrawal not made -- balance too low "
<< " and no overdraft protection ";
}
Customer Class
The Customer class has two private member variables:
You may NOT create any other member variables for the Customer class.
The Customer class has two constructors, a no-argument constructor and a two-argument constructor, and possibly, a destructor.
You may write other constructors or a destructor as you decide is necessary. But, if you do so, please justify it in a code comment just before the added constructor or the destructor or in a readme.txt file that you will include in your zip file.
The Customer class also has two member functions:
Customer c (custName, acctID);
acctsPtr[aNum] = new Checking (c, startBal, overdraftOk);
//OR
Customer c (custName, acctID);
acctsPtr[aNum] = new Savings (c, startBal, intRate);
If you write additional member functions, please justify your decision in a code comment just before the added member function or in a readme.txt file or that you will include in your zip file.
Account Class
The Account base class represents a generic account which will never be instantiated as an Account object. Subclasses (aka derived classes) of the Account base class, namely, the Savings account subclass and the Checking account subclass described below, can be instantiated objects.
The Account base class has two member variables:
These member variables cannot be public. You cannot add any other member variables.
The Account base class has two constructors:
You may write other constructors or a destructor as you decide is necessary. But, if you do so, please justify it in a code comment just before the added constructor or the destructor or in a readme.txt file that you will include in your zip file.
In addition to the constructors, and destructor if any, the Account base class has the following member functions:
Explanation / Answer
Customer.h
Customer.cpp
Driver.cpp
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.