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

Can anyone help me with this lab? Thanks The BankAccount.h: Exceptions Lab In th

ID: 3902555 • Letter: C

Question

Can anyone help me with this lab? Thanks

The BankAccount.h:

Exceptions Lab In this lab you will get practice with exceptions by adding them to a class that represents bank accounts. I have provided two files, BankAccount.h and BankAccount.cpp, which have the code for the class itself. Your task is to modify the code to have it throw exceptions under the conditions listed below, then write a main which uses try/catch blocks to display error messages when the bank account is used in ways that trigger exceptions. The bank account should throw exceptions under the following circumstances withdrawing a negative amount depositing a negative amount withdrawing more money than is present in the account setting a negative starting balance . . To practice throwing different kinds of exceptions, when withdrawing or depositing negative amounts of money, the code should throw an integer that is the negative amount. When withdrawing more money than it present the code should throw a string, and when setting a negative starting balance the code should throw a domain_error exception.

Explanation / Answer

BankAccount.h

#ifndef BANKACCOUNT_H

#define BANKACCOUNT_H

#include <iostream>

using namespace std;

class BankAccount {

public:

BankAccount(string name, double initialBalance);

string getName();

unsigned int getAccountNumber();

double getBalance();

double getInterestRate();

string getStatementString();

void deposit(double amount);

void deposit(double amount, string statement);

void withdraw(double amount);

void withdraw(double amount, string statement);

virtual void printStatement() = 0;

protected:

void addStatementLine(string statement, double amount);

private:

string name;

unsigned int accountNumber;

double balance;

static unsigned int nextAccountNumber;

string statementString;

};

#endif /* BANKACCOUNT_H */

BankAccount.cpp

#include "BankAccount.h"

#include <iostream>

#include <sstream>

#include <iomanip>

using namespace std;

unsigned int BankAccount::nextAccountNumber = 1;

BankAccount::BankAccount(string name, double initialBalance)

{

stringstream output;

this->name = name;

balance = initialBalance;

accountNumber = nextAccountNumber++;

output << setw(60) << left << "Transaction" << setw(10) << "Amount" << " " << "Balance" << endl;

statementString = output.str();

addStatementLine("Initial Deposit", initialBalance);

}

string BankAccount::getName()

{

return name;

}

unsigned int BankAccount::getAccountNumber()

{

return accountNumber;

}

double BankAccount::getBalance()

{

return balance;

}

void BankAccount::addStatementLine(string statement, double amount)

{

stringstream output;

  

output << setw(60) << left << statement << setw(10) << amount << " " << getBalance() << endl;

//.append(statement);

statementString.append(output.str());

}

void BankAccount::deposit(double amount)

{

deposit(amount, "Deposit");

}

void BankAccount::deposit(double amount, string statement)

{

balance += amount;

addStatementLine(statement, amount);

}

void BankAccount::withdraw(double amount)

{

withdraw(amount, "Withdrawal");

}

void BankAccount::withdraw(double amount, string statement)

{

if (balance >= amount)

{

balance -= amount;

addStatementLine(statement, amount);

}

else

{

addStatementLine(statement.append(" Overdraft"), amount);

}

}

string BankAccount::getStatementString()

{

return statementString;

}