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

C++ USING CLASSES INHERITANCE INCLUDE ACCOUNT.H, ACCOUNT.CPP, SAVINGSACCOUNT.H,

ID: 3861958 • Letter: C

Question

C++ USING CLASSES INHERITANCE

INCLUDE ACCOUNT.H, ACCOUNT.CPP, SAVINGSACCOUNT.H, SAVINGSACCOUNT.H.CPP, CHECKINGACCOUNT.H, CHECKINGACCOUNT.CPP, AND MAIN.CPP

Create a bank with two different types of bank accounts available. Each type of account has the following information: the account starts at zero balance so the user can deposit and withdraw money.
1) A first and last name for the account holder.
2) A routing number for the bank.
3) An account number.
4) A balance amount.
5) A transaction history, the transaction history must be a Vector
6) Methods for withdrawing money, depositing money, checking the account balance, and checking the transaction history.


7) The first type of Account, a "Savings Account", will inherit from "Account" and introduce the following features:
Maintain a count of the number of withdrawls and, if it exceeds 6, reject the withdrawl.
Not allow overdraft - if the withdrawl amount exceeds the account balance, reject the transaction.


8) The second type of Account, a "Checking Account", will inherit from "Account" and introduce the following features:
If the user attempts to withdraw more than they have available in their account, apply an overdraft fee of $35.
Allow total overdraft of up to $500 (including fees). If the account withdrawl + fees will make the user more than $500 overdrafted then reject the transaction.

INITIAL TEMPLATE :

#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <string>
class Account {
public:
Account(std::string firstName, std::string lastName, double openingBalance);
~Account();
std::string getFirstName();
std::string getLastName();
bool withdraw(double amount);
bool deposit(double amount);
static std::string getRoutingNumber();


double getBalance();

//ADD TRANSACTION HISTORY VECTOR

private:
std::string firstName;
std::string lastName;

std::string accountNumber:
std::string routingNumber;
double balance;
};

=============================================== SavingAccount.h

#ifndef SAVINGS_H
#define SAVINGS_H
#include <string>
#include "Account.h"

class SavingsAccount : public Account {
public:
SavingsAccount(std::string firstName, std::string lastName, double balance);
~SavingsAccount();
bool withdraw(double amount);
private:
int withdrawCount;
};
#endif

========================= CheckingAccount.h

#ifndef CHECKING_H
#define CHECKING_H
#include <string>
#include "Account.h"

class CheckingAccount : public Account {
public:
CheckingAccount(std::string pFirstName, std::string pLastName, double pBalance);
~CheckingAccount();
bool withdraw(double amount);
};
#endif

======================================== main.cpp

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

int main() {
bool done = false;
char selection;
cout << "Welcome to TrustUs Savings and Loan:" << endl;
cout << "Where you money is as safe as you think it is." << endl;
while (!done) {
cout << "Please select from the following menu options: " << endl;
cout << "1. Deposit Money" << endl;
cout << "2. Withdraw Money" << endl;
cout << "3. View Account Info" << endl;
cout << "4. Exit" << endl;
cout << "Please enter a selection: ";
cin.get(selection);
cin.ignore();
switch (selection) {
case 1:
   // deposit.
   break;
case 2:
   // withdraw
   break;
case 3:
   // view account balance.
   break;
case 4:
   done = true;
   break;
default:
   cout << "Invalid selection. Please enter 1-4." << endl;
}
}
}

Explanation / Answer

#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <bits/stdc++.h>
using namespace std;
class Account {
protected:
vector<int> transactionHistory;
string firstName;
string lastName;
string accountNumber;
string routingNumber;
double balance;
public:
~Account(){delete this;};
std::string getFirstName(){return firstName;}
std::string getLastName(){return lastName;}
bool deposit(double amount){balance+=amount;transactionHistory.push_back(amount);cout<<amount<<" Deposited in account ";}
std::string getRoutingNumber(){return routingNumber;}

double getBalance(){return balance;}
void transaction()
{
system("cls");
cout<<" Transaction History ";
cout<<" Account balance: "<<balance<<endl<<endl;
for(auto &x:transactionHistory)
{
if(x<0)
cout<<"Withdrawl: "<<-1*x<<endl;
else
cout<<"Deposit: "<<x<<endl;
}
}
//ADD TRANSACTION HISTORY VECTOR
}
=============================================== SavingAccount.h
#ifndef SAVINGS_H
#define SAVINGS_H
#include <bits/stdc++.h>
using namespace std;
#include "Account.h"

class SavingsAccount : public Account {
public:
SavingsAccount(std::string fName, std::string lName){srand(time(NULL));firstName=fName;lastName=lName;balance=0;
stringstream ss;
ss<<rand();
withdrawCount=0;
accountNumber=ss.str();routingNumber="123456789";//Routing number of bank
}
~SavingsAccount(){delete this;}
bool withdraw(double amount){
if(amount>balance)
cout<<"Withdrawl amount exceeding balance Transcation Rejected ";
else
{
if(withdrawCount>6)
cout<<"Withdraw count exceeded 6 Transaction Failed ";
else
{balance-=amount;cout<<amount<<" Withdrawl successful ";transactionHistory.push_back(amount*(-1)); withdrawCount++;}
}
}
private:
int withdrawCount;
};

#endif
========================= CheckingAccount.h
#ifndef CHECKING_H
#define CHECKING_H
#include <bits/stdc++.h>
using namespace std;
#include "Account.h"
*/
class CheckingAccount:public Account{
public:CheckingAccount(std::string fName, std::string lName){
srand(time(NULL));firstName=fName;lastName=lName;balance=0;
stringstream ss;
ss<<rand();
accountNumber=ss.str();routingNumber="123456789";//Routing number of bank
}
~CheckingAccount(){delete this;}
bool withdraw(double amount)
{
if(amount<=balance)
{balance-=amount;cout<<"Withdrawl Successful";transactionHistory.push_back(-1*amount);}
else
{
if(balance<=0)
{
if((balance-amount-35)<500)
{cout<<"Overdraft exceed 500$ Transaction rejected";transactionHistory.pop_back();}
else
{balance-=(amount+35);cout<<"Withdrawl Successful";transactionHistory.push_back(-1*(amount+35));}
}
else
if(((amount-balance)+35)>500)
{cout<<"Overdraft exceed 500$ Transaction rejected ";transactionHistory.pop_back();}
else
{
int rz=amount;
amount-=balance;
balance=0;
balance-=amount;
cout<<"Withdrawl Successful ";
transactionHistory.push_back(-1*(rz+35));
balance-=35;//Overdraft fee
}
}
}
};--
#endif
======================================== main.cpp
#include "SavingsAccount.h"
#include "CheckingAccount.h"
#include <bits/stdc++.h>
using namespace std;
void wait(int seconds)
{
int endwait;
endwait = clock() + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait){}
}

int main() {
bool done = false;
int selection;
cout << "Welcome to TrustUs Savings and Loan:" << endl;
cout << " Where you money is as safe as you think it is." << endl;
cout<<" Initialize a bank account:";
cout<<" Enter the first name and last name of account holder:";
string fname,lname;
cin>>fname>>lname;
cout<<" Enter the account type(Savings(0),Checking(1)):";
int flag;
cin>>flag;
CheckingAccount c(fname,lname);
SavingsAccount s(fname,lname);
while (!done) {
cout << " Please select from the following menu options: " << endl;
cout << "1. Deposit Money" << endl;
cout << "2. Withdraw Money" << endl;
cout << "3. View Account Info" << endl;
cout << "4. Transaction History" << endl;
cout << "5. Exit" << endl;
cout << "Please enter a selection: ";
cin>>selection;
switch (selection) {
case 1:
// deposit.
cout<<"Enter the amount to deposit:";
int x;cin>>x; cout<<endl<<endl;
if(flag)
c.deposit(x);
else
s.deposit(x);
break;
case 2:
// withdraw
cout<<"Enter the amount to withdraw:";
cin>>x;
cout<<endl<<endl;
if(flag)
c.withdraw(x);
else
s.withdraw(x);
break;
case 3:
// view account balance.
if(flag)
cout<<" Account balance: "<<c.getBalance()<<endl<<endl;
else
cout<<" Account balance: "<<s.getBalance()<<endl<<endl;
break;
case 4:
if(flag)
c.transaction();
else
s.transaction();
break;
case 5:
done = true;
break;
default:
cout << "Invalid selection. Please enter 1-5." << endl;
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote