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

Thanks :)))))))))))) Account Class class Account {public: Account(double initBal

ID: 3813282 • Letter: T

Question

Thanks :))))))))))))

Account Class class Account {public: Account(double initBal=0);//balance must be non-negative//cout "attempt at negative balance"//on illegal initialization bool credit(double amt);//add amt to balance//amt must be non-negative//cout "attempt at negative deposit"//on illegal transaction bool debit(double amt);//subtract amt from balance//amt must be non-negative//cout "attempt at negative withdrawl"//balance must be non-negative//if attempt to overdraw cout//"debit amount exceeds balance"//leave balance unchanged//returns false if debit rejected double getBalance();//return current balance private: double balance;}; Savings Class class Savings: public Account {public: Savings (double initBal, double intRate); void yearlyUpdate();//update the balance double calcInterest(); private: double interestRate;//a percent 4 means 4%}; Checking Class class Checking: public Account {public: Checking(double initBal, double fee); bool credit(double amt); bool debit(double amt); private: double transFee;//fee for successful//credit or debit operation}; In addition to providing implementation (.cpp) files for the aforementioned classes, you must also provide a main function that exercises the Checking and Savings classes. Make sure to include usage of the inherited methods from the Account base class So, you should have the following implemented to turn in: main.cpp Account.cpp

Explanation / Answer


#include<iostream>
#include<string>

using namespace std;
class Account
{
   public:
       Account(double initBal=0);
       bool credit(double amt);
       bool debit(double amt);
       double getBalance();
   private:
       double balance;
};

class Saving :public Account
{
   public :
       Saving(double initBal, double initRate);
       void yearlyUpdate();
       double calcInterest();

   private:
       double interestRate;
};

class Checking : public Account
{
   public:
       Checking(double initBal,double fee);
       bool credit(double amt);
       bool debit(double amt);
   private:
       double transFee;
};

//========================================================

Account::Account(double initBal){
   balance = initBal;
}

bool Account::credit(double amt){
   if(amt<0){
       cout<<"attempt to negative deposit"<<endl;
       return false;
   }
   balance += amt;
   return true;
}

bool Account::debit(double amt){
   if(amt<0){
       cout<<"attempt to negative withdrawl"<<endl;
       return false;  
   }
   if(amt>balance){
       cout<<"debit amount exceeds balance"<<endl;
       return false;  
   }
   balance -=amt;
   return true;
}

double Account::getBalance(){
   return balance;
}

Saving::Saving(double initBal, double initRate):Account(initBal){
   interestRate = initRate;
}

void Saving::yearlyUpdate(){
   Account::credit(calcInterest());
}

double Saving::calcInterest(){
   return (Account::getBalance()*1*interestRate)/100.0;
}

Checking::Checking(double initBal,double fee):Account(initBal){
   transFee = fee;
}

bool Checking::credit(double amt){
   if(!Account::credit(amt-transFee)){
       cout<<"attempt to negative deposit"<<endl;
       return false;
   }
   return true;
}

bool Checking::debit(double amt){
   if(!Account::debit(amt+transFee)){
       cout<<"attempt to negative withdrawl"<<endl;
       return false;  
   }
   return true;
}

int main(){

   Saving* saving = new Saving(50000,5);
   saving->debit(-1000);
   saving->debit(270000);
   saving->debit(5000);

   saving->credit(-400);
   saving->credit(500);
   cout <<"Saving Balance :"<<saving->getBalance()<<endl<<endl;
  
   saving->yearlyUpdate();
   cout <<"After Yearly Update Saving Balance :"<<saving->getBalance()<<endl<<endl;

  
   Checking* checking = new Checking(50000,50);
   cout <<"Checking Balance :"<<checking->getBalance()<<endl<<endl;
  
   checking->debit(5000);
   cout <<"After Debit 5000 Checking Balance :"<<checking->getBalance()<<endl<<endl;

   checking->credit(-400);
   checking->credit(500);
   return 0;
}

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