1. Engineering
  2. Computer Science
  3. here is the code before in c include ltiostreamgt include...

Question: here is the code before in c include ltiostreamgt include...

Question details

Here is the code before in C++:

#include <iostream>
#include <ctime>
#include <iomanip>

using namespace std;

static time_t now = time(0);
static tm *ltm = localtime(&now);

class BankAccount {

protected:
   double balance, interestRate;
   struct tm lastInterestDate;

public:

   BankAccount() {

       balance = 0;
       interestRate = 0;
       lastInterestDate.tm_mon = 0;
       lastInterestDate.tm_year = 0;
       lastInterestDate.tm_mday = 1;
       lastInterestDate.tm_sec = 0;
       lastInterestDate.tm_min = 0;
       lastInterestDate.tm_hour = 0;
   }

   BankAccount(double b, double r, struct tm lid = *ltm) {

       balance = b;
       interestRate = r;
       lastInterestDate = lid;
   }

   void withdraw(double deduction)

   {
       if (balance < deduction)
           cout << "Insufficient amount.." << endl;
       else
           balance -= deduction;
   }

   void setBalance(double b) {
       balance = b;
   }

   void increaseBalanceBy(double amount) {
       balance += amount;
   }

   void setInterestRate(double r) {
       if (r < 0 || r > 1) {
           cout << "invalid rate!" << endl;
           return;
       }

       interestRate = r;
   }

   void deposit(double addition)
   {
       balance += addition;
   }
   void addInterest() {
       time_t t = time(NULL);
       struct tm now;
       localtime_s(&now, &t);
       int today = (now.tm_year + 1990) * 10000 + (now.tm_mon + 1) * 100 + (now.tm_mday);
       cout << "Today: " << today << endl;
       cout << "last interest date: " << lastInterestDate.tm_mday << endl;
       if ((today - lastInterestDate.tm_mday) > 30)
       {
           balance = balance + balance * interestRate;
           lastInterestDate.tm_mday = today;
       }
   }

   void info() {
       std::ios cout_state(NULL);
       cout_state.copyfmt(cout);
       cout << "Balance: $" << setw(6) << setfill('0') << fixed << setprecision(1) << balance << endl;
       char buffer[80];
       strftime(buffer, 80, "%D", &lastInterestDate);
       cout << "Interest rate: %" << interestRate << endl;
       cout << "Last interest paid on " << buffer << endl << endl;
   }
   double getBalance() {
       return balance;
   }
   double getInterestRate() {
       return interestRate;
   }
   struct tm getLastInterestDate() {
       return lastInterestDate;
   }
};

class walletAccount :public BankAccount

{
private:
   double maxWalletCapacity = 100;

public:
   walletAccount() :BankAccount()
   {
   }
   walletAccount(double bal, double rate) :BankAccount(bal, rate)
   {
   }
   double getMaxWalletCapacity()
   {
       return maxWalletCapacity;
   }
   void deposit(double addition)
   {
       if ((balance + addition) <= maxWalletCapacity)
           deposit(addition);
       else
           cout << "Balance would exceed the wallet capacity" << endl;
   }
   void setBalance(double bal)
   {
       if (bal <= maxWalletCapacity)
           balance = bal;
       else
           cout << "Balance would exceed the wallet capacity" << endl;
   }
   void printInfo()
   {
       info();
       cout << " Max wallet capacity: $" << maxWalletCapacity << endl;
   }
};

class SavingAccount :public BankAccount

{
private:
   bool lock = false;
   void accountLockMessage()
   {
       if (lock)
           cout << "Account is locked" << endl;
       else
           cout << "Account is open" << endl;
   }

public:
   SavingAccount(double bal, double rate, bool lock) :BankAccount(bal, rate)
   {
       this->lock = lock;
   }
   void lockAccount()
   {
       lock = true;
       accountLockMessage();
   }
   void removeLock()
   {
       lock = false;
       accountLockMessage();
   }
   void setBalance(double bal)
   {
       if (lock == false)
           balance = bal;
       else
           cout << "access is denied due to account being locked." << endl;
   }
   void setInterestRate(double rate)
   {
       if (lock == false)
           interestRate = rate;
       else
           cout << "access is denied due to account being locked." << endl;
   }
   void addInterest()
   {
       if (lock == false)
           BankAccount::addInterest();
       else
           cout << "access is denied due to account being locked." << endl;;
   }
   void deposit(double addition)
   {
       if (lock == false)
           BankAccount::deposit(addition);
       else
           cout << "access is denied due to account being locked." << endl;;
   }
   void withdraw(double deduction)
   {
       if (lock == false)
           BankAccount::withdraw(deduction);
       else
           cout << "access is denied due to account being locked." << endl;;
   }
   void printInfo()
   {
       info();
       cout << lock << endl;
   }
};

int main()
{
   SavingAccount saving(1000, 0.02, true);
   saving.printInfo();
   saving.withdraw(200);
   saving.removeLock();
   saving.withdraw(300);
   saving.withdraw(1000);
   saving.lockAccount();
   saving.deposit(2000);
   saving.printInfo();

   walletAccount wallet(70.0, 0.02);
   wallet.printInfo();
   wallet.deposit(50);
   wallet.printInfo();
}

Write a new main function: o (3 point) Create a pointer for class SavingsAccount and initialize it o (3 point) Create a pointer for class WalletAccount and initialize it o (2 point) Print the current number of accounts Hint: use static method defined in BankAccount o (2 point) Ask user if he wants to open an account o (2 point) If no show a message o If yes (2 point) Ask if he wants to open a savings account If yes (1 point) ask for balance . (7 point) create a new SavingsAccount object assign it to savings pointer (2 point) Ask if he wants to open a wallet account - If yes (1 point) Ask for balance (7 point) Create a new WalletAccount object Assign it to wallet pointer o (3 point) Print the current number of accounts* (15 point) Possible output: . Run the code three time Try the same inputs provided in sample outputs . Get a screenshot of each results » Save all vour files in a folder Make a zip and submit it through canvas urrent number of accounts is: e Do you want to open an account? (y/n)rn aybe some other time! urrent number of accounts is: e Press any key to continue . . urrent number of accounts is: θ you want to open an account? (y/n)y o you want to open a savings account with 2% int reast rate? (y/n)y hat is your initial balance? 180 you want to open a wallet account with 2% intreast rate and $100 maximim capacity? (y/n)n urrent number of accounts is: 1 ress any key to continue . . . _ urrent number of accounts is: e o you want to open an account? (y/n)y Do you want to open a savings account with 2% intre ast rate? (y/n)y hat is your initial balance? 1ee O you want to open a wallet account with 2% intreast rate and $10θ maximim capacity? (y/n)y hat is your initial balance? 38 urrent number of accounts is: 2 Press any key to continue .. . _

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution