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

Need help with inheretience lab for c++. Please and thank you. Please send corre

ID: 665129 • Letter: N

Question

Need help with inheretience lab for c++. Please and thank you. Please send correct code and output. Dropbox with input.txt is below:

https://www.dropbox.com/sh/36sxpfkktf7rawv/AABiPMaEmnPVSsVlR65Jr7S6a?dl=0

This week we will be working with different bank accounts. For this lab, we will have checking, savings, and certificate of deposit (or CD) accounts.

About the accounts

Checking accounts:

* Can withdrawal and deposit money normally

* Do not gain interest

Savings accounts:

* Can withdrawal and deposit normally

* Gain 1% interest if they have $100.00 – 999.99

* Gain 2% interest if they have $1000.00 or more

Certificate of Deposits (CDs):

* Can deposit normally

* Tracks if money has been withdrawn

* Gain 10% interest if they haven’t been withdrawn

* Gain 1% interest if they have been withdrawn from

Structure

The base class is pretty simple on it’s own. The Account class is provided. But other derived classes all need to inherit the methods and properties of the Account class.

Ex: having a Rectangle class inherit from a Shape class:

Class Rectangle : public Shape { … }

We will use an array of pointers to Accounts to store these. Depending on the type of account we need, we’ll insert a new account in that point of the array. This won’t normally work, but using polymorphism, and setting up our accounts to inherit from a base Account class, then any subclass we define will actually also be a type of the base class.

Ex: Creating a new checking account: Account *newAccount;

newAccount = new CheckingAccount(123);

Input

The input file consists of multiple lines of commands. These tell the program what to do.

If the line starts with NEW, then it creates a new account of the next word’s type (CHECKING, SAVINGS, or CERTIFICATE). Then it creates it with the account number provided after that.

If the line starts with DEPOSIT, then it deposits into the account (listed next) the amount (listed after that).

If the line starts with WITHDRAWAL, then it withdraws from the account (listed next) the amount (listed after that).

If the line starts with INTEREST, we apply interest to all of the accounts. (Telling a checking account to gain interest will run, but it doesn’t do anything.)

If the line starts with TRANSFER, transfer from the first account number to the second account number the amount listed after that.

See the provided input.txt to see how the file looks.

Output

Print out the line “BANK STATEMENT” with an extra empty line. Then print out the account number, type, and balance in this format:

Account number: 101

Type of account: Checking

Balance: $40

Leave a blank line between each account.

Explanation / Answer

Code:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
using namespace std;

//bank Account generic class
class bankAccount
{
      //private:
            
      public:
           int bnkaccNumber;
              float bnkbalance;
              float bnkinterestRate;
             void bnkdeposit(float amount);
             void bknwithdraw(float amount);
             void bnkdisplayAccount(int, float);
             void bnksetupAccount(int, float, float);
             bool bnkmatchAccount(int);
             float bnkgetBalance();
};

bool bankAccount::bnkmatchAccount(int accNo)
{
     if(accNo==bnkaccNumber) return true;
     else return false;
}

void bankAccount::bnksetupAccount(int aN, float bal,float iRate)
{
    bnkaccNumber=aN;
    bnkbalance=bal;
    bnkinterestRate=iRate;
}

void bankAccount::bnkdeposit(float amount)
{
     bnkbalance=bnkbalance+amount;

}

void bankAccount::bknwithdraw(float amount)
{
     bnkbalance=bnkbalance-amount;

}

float bankAccount::bnkgetBalance()
{
      return bnkbalance;
}

class BnksavingsAccount : public bankAccount
{
     // private:
            
      public:
           BnksavingsAccount(){}
           int bnkaccNumber;
             float bnkbalance;
             float bnkinterestRate;
             void calculateInterest(float, float);
             BnksavingsAccount (int, float, float);
           bool bnkmatchAccount(int );
           void bnksetupAccount(int, float, float);
           void bnkdeposit(float );
           void bknwithdraw(float );
           float bnkgetBalance();
           void calculateInterest();

};

bool BnksavingsAccount::bnkmatchAccount(int accNo)
{
     if(accNo==bnkaccNumber) return true;
     else return false;
}

void BnksavingsAccount::bnksetupAccount(int aN, float bal,float iRate)
{
    bnkaccNumber=aN;
    bnkbalance=bal;
    bnkinterestRate=iRate;
}

void BnksavingsAccount::bnkdeposit(float amount)
{
     bnkbalance=bnkbalance+amount;

}

void BnksavingsAccount::bknwithdraw(float amount)
{
     bnkbalance=bnkbalance-amount;

}

float BnksavingsAccount::bnkgetBalance()
{
      return bnkbalance;
}

void BnksavingsAccount::calculateInterest()
{
     bnkbalance=bnkbalance+bnkbalance*bnkinterestRate;
}

// Constructor Function
BnksavingsAccount::BnksavingsAccount(int aN, float bal, float iRate)
{
    bnkaccNumber=aN;
    bnkbalance=bal;
    bnkinterestRate=iRate;
}

class BnkchecqueAccount : public bankAccount
{
      //private:
            
      public:
           int bnkaccNumber;
            float bnkbalance;
           BnkchecqueAccount (){}
            BnkchecqueAccount (int, float);
           bool bnkmatchAccount(int );
           void bnksetupAccount(int, float, float );
           void bnkdeposit(float );
           void bknwithdraw(float );
           float bnkgetBalance();
           void calculateInterest();
};

bool BnkchecqueAccount::bnkmatchAccount(int accNo)
{
     if(accNo==bnkaccNumber) return true;
     else return false;
}

void BnkchecqueAccount::bnksetupAccount(int aN, float bal,float iRate)
{
    bnkaccNumber=aN;
    bnkbalance=bal;
    bnkinterestRate=iRate;
}

void BnkchecqueAccount::bnkdeposit(float amount)
{
     bnkbalance=bnkbalance+amount;

}

void BnkchecqueAccount::bknwithdraw(float amount)
{
     bnkbalance=bnkbalance-amount;

}

float BnkchecqueAccount::bnkgetBalance()
{
      return bnkbalance;
}

void BnkchecqueAccount::calculateInterest()
{
     bnkbalance=bnkbalance+bnkbalance*bnkinterestRate;
}

// Constructor Function
BnkchecqueAccount::BnkchecqueAccount(int aN, float bal)
{
    bnkaccNumber=aN;
    bnkbalance=bal;
}

class BnkcreditAccount : public bankAccount
{
      private:
              int bnkaccNumber;
              float bnkbalance;
              float bnkinterestRate,credit;
      public:
           BnkcreditAccount();
             void checkLimit(bool);
           bool bnkmatchAccount(int );
           void bnksetupAccount(int, float, float);
           void bnkdeposit(float );
           void bknwithdraw(float );
           float bnkgetBalance();
           void calculateInterest();
           BnkcreditAccount(int, float, float, int);
           bool checkLimit(bool, float, int );

};

bool BnkcreditAccount::bnkmatchAccount(int accNo)
{
     if(accNo==bnkaccNumber) return true;
     else return false;
}

void BnkcreditAccount::bnksetupAccount(int aN, float bal,float iRate)
{
    bnkaccNumber=aN;
    bnkbalance=bal;
    bnkinterestRate=iRate;
}

void BnkcreditAccount::bnkdeposit(float amount)
{
     bnkbalance=bnkbalance+amount;

}

void BnkcreditAccount::bknwithdraw(float amount)
{
     bnkbalance=bnkbalance-amount;

}

float BnkcreditAccount::bnkgetBalance()
{
      //checkLimit();
      return bnkbalance;
}

void BnkcreditAccount::calculateInterest()
{
     bnkbalance=bnkbalance+bnkbalance*bnkinterestRate;
}

// Constructor Function
BnkcreditAccount::BnkcreditAccount(int aN, float bal, float iRate, int)
{
    bnkaccNumber=aN;
    bnkbalance=bal;
    bnkinterestRate=iRate;
}
//needs a lot more work, at the moment a rough idea of what it needs to do
bool BnkcreditAccount::checkLimit(bool exceeded, float bal, int limit)
{
    limit=5000;
    if(credit > limit) return true;
    else return false;
}


class BnkCustomer
{
      private:
              string name;
              string address;
              BnksavingsAccount sAccnt;
              BnkchecqueAccount cAccnt;
              BnkcreditAccount ccAccnt;
      public:
           //BnkCustomer(){}
             BnkCustomer(string = "", string ="", int =0, float =0.0,float =0.0);
             void CreateCust(string, string, int);
             void accessAccount(char);
             bool searchAccounts(int);
             void applyTrans(char,float);
};


//used for the ATM transactions
void BnkCustomer::applyTrans(char transType, float amt)
{
if(transType=='C') sAccnt.bnkdeposit(amt) ;
else if(transType=='D') sAccnt.bknwithdraw(amt) ;
       else sAccnt.calculateInterest();
}

//constructor function calling BnksavingsAccount constructor
BnkCustomer::BnkCustomer(string nme, string addr,int an, float b, float ir):sAccnt(an,b,ir)
{
   name = nme;
   address = addr;
}

//constructor function calling BnkchecqueAccount constructor
BnkCustomer::BnkCustomer(string nme, string addr,int an, float b, float ir):cAccnt(an,b,ir)
{
   name = nme;
   address = addr;
}

//constructor function calling BnkcreditAccount constructor
BnkCustomer::BnkCustomer(string nme, string addr,int an, float b, float ir):ccAccnt(an,b,ir)
{
   name = nme;
   address = addr;
}*/

bool BnkCustomer::searchAccounts(int accNo)
{
   if (sAccnt.bnkmatchAccount(accNo)) return true;
   else return false;

   if (cAccnt.bnkmatchAccount(accNo)) return true;
   else return false;

   if (ccAccnt.bnkmatchAccount(accNo)) return true;
   else return false;
}

// Access account to get bnkbalance
void BnkCustomer::accessAccount(char op)
{    float amt;
     cout<<fixed;
     if (op=='B')
       cout<<"Balance of "<<setw(10)<<name<<"s account is: "<<setw(10)<<setprecision(2)<<sAccnt.bnkgetBalance()<<endl;

}

class BnkTransact
{
      private:
              int accNo;
              float amt;
              char transType;
      public:
           BnkTransact(){}
             void readRecord(ifstream&);
             int getTransAccNo();
             float getTransAmt();
             char getCode();

};

// Read one transaction record from file
void BnkTransact::readRecord(ifstream &infile)
{
   infile>>accNo;
   infile >> amt;
   infile>>transType;

}
int BnkTransact::getTransAccNo()
{
return accNo;
}

float BnkTransact::getTransAmt()
{
return amt;
}
char BnkTransact::getCode()
{
return transType;
}

class BnkProcessTrans
{
  
    private:
      
       BnkCustomer custs[100];
       BnkTransact trans[100];
       ifstream infile;
       int numTrans;              
       int findAcc(int);                           
    public:
       BnkProcessTrans(){}
        void getCustomers();
        void getTrans();
        void Process();
        void Report();
};

void BnkProcessTrans::getCustomers()
{
     ifstream inFile.open("input.txt");             
  
      
    if(inFile.fail())                       
    {
      cout << "file could no be opened, file does not exist" << endl;
    }
    else
    {
     
       while(inFile.peek() !=EOF && !inFile.eof())
       {
       for(int i=0; i < 10; i++)
       {
        inFile >> nme
               >> addr
               >> aNum
               >> intr;
             
        accnt[i].bnksetupAccount( intr, nme, addr);
       }
       cout << " -+-Loading Data. Please Wait...-+-" << endl;
    }

// Load tranactions into array from file
void BnkProcessTrans::getTrans()
{   int count=0;
    infile.open("trans.dat");
    if(infile.fail()) cout<<"File not found";
    else {
      while(infile.peek()!=EOF) {
       trans[count].readRecord(infile);
       count++;
      }
    }
    infile.close();
    numTrans=count-1;

}

void BnkProcessTrans::Report()
{
for(int i=0;i<maxCustomers;i++)
    custs[i].accessAccount('B');
}

int BnkProcessTrans::findAcc( int accNo)
{
        for(int i=0;i<maxCustomers;i++)
         if (custs[i].searchAccounts(accNo))   return i;
        return -1;
}
// Main processing driver function
void BnkProcessTrans::Process()
{    int cust,i;
     for(i=0;i<numTrans;i++)
   {                 
       cust = findAcc(trans[i].getTransAccNo());
       if (cust>=0)
         custs[cust].applyTrans(trans[i].getCode(),trans[i].getTransAmt());
       else cout<<"No BnkCustomer found";
     }
}

int main()
{
   BnkProcessTrans pt;
   pt.getCustomers();
   cout<<"Bank system"<<endl;
   cout<<"Transaction Daily Report"<<endl;
   cout<<"========================"<<endl;
   cout<<"Initial Balances"<<endl;
   cout<<"----------------"<<endl;
   pt.Report();
   pt.getTrans();
   cout<<endl<<"Processing Transactions"<<endl<<endl;
   pt.Process();
   cout<<"Final Balances"<<endl;
   cout<<"--------------"<<endl;
   pt.Report();
   system("pause");
   return 0;
}