Account Class in C++
Posted by Samath
Last Updated: January 07, 2021
  8181

Write the solution for the problem below. You are required to submit three (3) files, Account.h, Account.cpp, andTester.cpp.

Question:

The Bank of Nova Scotia has asked you to develop a system which should be able to represent customers’ bank accounts. You were instructed to create a class called Account, to facilitate this request. Include data members of type: double to represent the account balance, and string to represent the name of the account holder. Provide a constructor that receives an initial balance, and an account holder’s name, and uses this information to initialize the data members. Please note, that the constructor should validate the initial balance to ensure that it’s greater than or equal to 0. If not, set the balance to 0 and display an error message indicating the initial balance was invalid.

Four (4) member functions are needed:
creditUpdate: this function should add an amount to the current balance
debitUpdate: this function should withdraw money from the account and ensure that the debit amount does not exceed the Account’s balance. If it does, the balance should be left unchanged and a message should be printed indicating, “The Debit amount of $XXX.XX exceeded your current account balance”

interestCal: this function should award a 10% interest to the current balance of the account holder.

printInfo (): this function should print the current balance and name of the account holder.

Note: Use getters and setters to access and manipulate the private data members.
Create a program called Tester.cpp, which executes the statements below. The console output should have the same values as the one to the right.

Account holder1(100.50, "Damion Mitchell");
Account holder2(200.00, "Syrie Mitchell");
holder1.printInfo();

holder1.creditUpdate(19.50);
holder1.printInfo();

holder2.interestCal();
holder2.printInfo();
holder2.debitUpdate(221.00);
holder2.printInfo();

Account holder3(-0.65, "Jane Doe");
holder3.printInfo();
holder3.creditUpdate(1000.00);
holder3.debitUpdate(500.00);
holder3.interestCal();
holder3.printInfo();

The result should be like this:

Account.cpp

#include "Account.h"
#include <iostream>
#include <string>
using namespace std;
 
 
 
       Account::Account(double bal, string name)
       {           
          account_holder = name;
           
          if(bal >= 0)
          {            
              account_balance = bal;
          }
          else
          {
              account_balance = 0;
              cout<<"The initial balance was invalid"<<endl;    
          }           
       }   
       
       
       
       void Account::creditUpdate(double amount)
       {
          account_balance =  account_balance + amount;   
       }  
       
       
       
       void Account::debitUpdate(double amount)
       {
            if(amount > account_balance)
            {
              cout<<"The Debit Amount of "<<amount<<" Exceeded Your Current Account Balance"<<endl;    
            }
            else
            {
              account_balance =  account_balance - amount;
            } 
       }  
       
       
       
       void Account::interestCal()
       {  
         double intrest = 0.1*account_balance;  
         account_balance = account_balance + intrest;
       }   
       
       
       
       void Account::printInfo()
       {
         cout<<"Name: "<<account_holder<<endl; 
         cout<<"Balance: "<<account_balance<<endl;           
       } 
       
       
       string Account::getAccount_Holder()
       {
          return account_holder;
       }   
       
       
       void Account::setAccount_Holder(string name)
       {
          account_holder = name;
       }   
       
       
       double Account::getAccount_Balance()
       {
          return account_balance;
       }   
       
       void Account::setAccount_Balance(double bal)
       {
          account_balance = account_balance + bal;
       } 

 

Account.h

#ifndef ACCOUNTH
#define ACCOUNTH
#include<iostream>
#include<string>
using namespace std;
class Account 
{
      public:
      Account(double bal, string name); 
      void creditUpdate(double amount);
      void debitUpdate(double amount);           
      void interestCal();   
      void printInfo();
      string getAccount_Holder(); 
      void setAccount_Holder(string name);  
      double getAccount_Balance(); 
       void setAccount_Balance(double bal);
      private:       
      double account_balance;
      string account_holder;      
};  
#endif

 

Tester.cpp

#include <cstdlib>
#include <iostream>
#include "Account.h"
 
using namespace std;
 
int main(int argc, char *argv[])
{
Account holder1(100.50, "Damion Mitchell");
Account holder2(200.00, "Syrie Mitchell");
holder1.printInfo();
cout<<"*****************************************************"<<endl;
holder1.creditUpdate(19.50);
holder1.printInfo();
cout<<"*****************************************************"<<endl;
holder2.interestCal();
holder2.printInfo();
cout<<"*****************************************************"<<endl;
holder2.debitUpdate(221.00);
holder2.printInfo();
cout<<"*****************************************************"<<endl;
Account holder3(-0.65, "Jane Doe");
holder3.printInfo();
cout<<"*****************************************************"<<endl;
holder3.creditUpdate(1000.00);
holder3.debitUpdate(500.00);
holder3.interestCal();
holder3.printInfo();
cout<<"*****************************************************"<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}
   
  
 
 
   

 
 
a tricky mission but one that was completed with minimum fuss!
 
Mi do my version of this program. I will post it soon...