Computer Science
COSC1408 Foundations of Computer Science II
Term Project Phase II
Due Date: Monday, 05/11/2020
Exception Classes
Define a NegativeAmountException class. This exception will be thrown when a negative number applied to balance, deposit, withdrawal, or rate. This class holds the following information for this type of
exception:
amount: double – the value of balance or rate passed into constructor, or the value of amount passed into deposit or withdraw methods which will be a negative number.
NegativeAmountException should have the following member functions:
NegativeAmountException(double): constructor, accepts a negative number which could be balance and/or rate for constructor, or amount for deposit or withdraw methods.
getMessage(): string. Return a string message include the negative value
Define a NotEnoughFund class. This exception will be thrown from withdraw method of SavingsAccount when the withdrawal amount is greater than balance.
NotEnoughFund should have the following member functions:
NotEnoughFund (): default constructor.
getMessage(): string. Returns a string message "Not enough fund".
Bank Accounts
Design a BankAccount class to hold the following information about a bank account:
type: string – "Unknown" in BankAccount, "Checking Account" in CheckingAccount, "Savings Account" in SavingsAccount.
balance: double
numDeposits: int – number of deposits this month
numWithdrawls: int – number of withdrawals
rate: double – annual interest rate BankAccount should have the following member functions:
BankAccount(): default constructor, initialize all attributes to zero, type is Unknown.
BankAccount(double balance, double rate): constructor, accepts arguments for the balance and annual interest rate and initialize other attributes to be zero and type to be Unknown. If either balance or rate is negative then a NegativeAmountException will be thrown.
get and set methods for all attributes. In any set method, if a negative number is passed in then a NegativeAmountException will be thrown.
void deposit(double amount): A virtual function that accepts an argument for the amount of the deposit. The function should add the argument to the account balance. It should also increment
the variable holding the number of deposits. If amount is negative then a
NegativeAmountException will be thrown.
void withdraw(double amount): A virtual function that accepts an argument for the amount of the withdrawal. The function should subtract the argument from the balance. It should also
increment the variable holding the number of withdrawals. If amount is negative then a
NegativeAmountException will be thrown. If account balance is less than the withdrawal amount then throws NotEnoughFund exception.
void calcInt(): A function that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas:
MonthlyInterestRate = (AnnualInterestRate/12)
MonthlyInterest = Balance * MonthlyInterestRate
Balance = Balance+MonthlyInterest
void print(): a virtual function, print the account information including account type, balance, number of deposit, number of withdrawal, interest rate.
SavingsAccount
Design a SavingsAccount class which is derived from the BankAccount class.
SavingsAccount: The savings account class should have the following attribute:
status: bool – represent an active or inactive account. If the balance of an account falls below $25, it becomes inactive. (The status will be false.) No
more withdrawals may be made until the balance is raised above $25, at which time the account
becomes active again
The savings account class should have the following member functions:
SavingsAccount(): default constructor, initialize status to be false and type to be "Savings Account".
SavingsAccount(double balance, double rate): constructor, accepts arguments for the balance and annual interest rate which calls BankAccount(double, double) in the BankAccount class. Set type to be "Savings Account". If either balance or rate is negative then a NegativeAmountException will be thrown.
void withdraw(double amount): A function that checks to see if the account is inactive before a withdrawal is made. (No withdrawal will be allowed if the account is not active.) A withdrawal is
then made by calling the base class version of the function. If amount is negative then a
NegativeAmountException will be thrown. If account balance is less than the withdrawal amount then throws NotEnoughFund exception. If account status is active and the withdrawal brings the balance less than $25 then set status to false.
void deposit(double amount): A function that checks to see if the account is inactive before a deposit is made. If the account is inactive and the deposit brings the balance above $25, the
account becomes active again. The deposit is then made by calling the base class version of the
function. If amount is negative then a NegativeAmountException will be thrown.
bool getStatus(): returns the status of the savings account.
void print(): call print function in the base class (BankAccount) and also print status of the account.
CheckingAccount
Next, design a CheckingAccount class, also derived from the BankAccount class. CheckingAccount should have the following member functions:
CheckingAccount(): default constructor which calls the default constructor of BankAccount and sets type to be "Checking Account".
CheckingAccount(double balance, double rate): constructor, accepts arguments for the balance and annual interest rate which calls BankAccount(double, double) in the BankAccount class and sets type to be "Checking Account".
void withdraw(double amount): If amount is negative then a NegativeAmountException will be thrown. If account balance is less than the withdrawal amount then throws NotEnoughFund exception and a service charge of $15 will be taken from the account balance. (The withdrawal
will not be made.). If there isn’t enough in the account to pay the service charge, the balance will
become negative and the customer will owe the negative amount to the bank.
CheckingAccount does not redefine the print() function in BankAccount
Employee class in Phase1
Add a private attribute accounts to Employee class to record the employee's bank accounts information. The accounts can record multiple checking accounts and/or savings accounts. The
type of accounts should be either vector or list in STL (Standard Template Library).
Modify print() function, in addition to print an employee's information, also prints the employee's accounts information.
Run Project.cpp to test your program.