Question

Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines.

Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your type will have to be of the base class, Bank. This will be explained in more detail later.

Step 1:

Create a header file Bank.h to define a Bank class with the following members:

Data members: The program should implement data hiding, so please define data members accordingly.

- accountNumber

- name

- balance

- Account type (see Step 3 below)

Note: The data types are not specified for this problem, so you have some flexibility in your design.

Member functions: Please include only the declaration of the member functions in the header file. The implementation of member functions will later be done in the Bank.cpp file. (You may inline get and set functions.)

  • Bank() constructor with no arguments creates a bank account with a default accountNumber as 9999, a name of an empty string, and balance value of zero.
  • Bank(param1, param2, param3) constructor with three parameters creates a bank account with a specified accountNumber, name and balance.
  • withdraw(param1) function to withdraw a specified amount (param1) from the account. The function should first check if there is sufficient balance in the account. If the balance is sufficient, withdrawal is processed and the current balance is returned as a string. Otherwise return a string to the caller that says “Insufficient balance” and leave the balance unchanged.
  • deposit(param1) function to deposit a specified amount of money (param1) to the account. This returns the new balance as a double.
  • setName(param1) mutator function that changes the name on the account.
  • getAccountNumber(): An accessor function that returns the account number. This function is later called by the displayAccountInfo() function from inside another independent function called displayAccountInfo().
  • getName(): An accessor function that returns the name on the account.
  • getBalance(): An accessor function that returns the account balance. This function is later called by the displayAccountInfo() function from inside another independent function called displayAccountInfo().

  • Note that nowhere does the code in your Bank class request input nor display output.

Step 2:

Create a Bank.cpp file and implement the member functions of the Bank class.

Step 3:

Create two derived classes with Bank as the base class, Savings and Checking, as follows. Your derived classes must have two constructors, one that takes no arguments and another that takes as arguments all possible fields for the class, including fields in the base class. These derived classes do not need to be in separate files. You can include the header and implementation in Bank.h and Bank.cpp, respectively.

-Savings accounts pay interest, so you need the following additional fields, along with accessors and mutators:

            -Annual interest rate, a floating-point number

            -Compounding period in days

            -Write an AddInterest function that takes a number of days and applies interest to the account at the given rate. It should return the amount of interest added, and the balance should reflect this.

-Checking accounts require two additional fields, along with accesors and mutators:

            -Minimum balance, in dollars

            -Monthly fee, in dollars.

Step 4:

Also define an independent displayAccountInfo(Bank object) function which takes a Bank object as a parameter and displays the accountNumber, name, and balance of the bank account specified by this Bank object. The displayAccountInfo() function is later called by the main function.

Please note: The displayAccountInfo() function IS NOT a member function of the Bank class. It is an independent function that is called from inside the main function.

Step 5:

Finally, create a main.cpp file to do the following functions. Note that each time you create an account, you must store the pointer to its object in your array.

Display a menu with the following options:

  1. Create a Savings object with values for accountNumber, name, and balance.
  1. Set the interest rate
  2. Set the compounding period
  1. Create a Checking object with values for accountNumber, name, and balance
  1. Set the minimum balance.
  2. Set the monthly fee
  1. Create Bank object with no parameters. This option will have to use the mutators to change the various fields.
  2. Deposit to Bank account (request account number and amount)
  3. Withdraw from Bank account (request account number and amount)
  4. Display information for all accounts including information that is specific to either checking or savings accounts
  5. Exit the program.

A minimal test would include the following:

  • Create a Bank account with no parameters. Try to withdraw $500 from this account.
  • Create another Checking account with accountNumber: 1111, your name, and $1000 balance. Withdraw $600, then withdraw $300, and then deposit $400 to this account.
  • Create a Savings account with account number 2222, your mother’s name, and $2000 balance. Withdraw $500 from it, then $1600.
  • Display all account information, per Option 5.

Assumptions: There will never be more than 100 accounts. Show an error message if the user tries to deposit to or withdraw from an account number that doesn’t exist. Show an error message if the user attempts to create an account number that already exists. Show any messages returned from the withdraw() function.

The main input validation is that things like names should not be null or blank, and that numeric values are actually numeric. The grader will not test with the intent of breaking your program with invalid input.

To hand in:

  1. Your .cpp and .h files.
  2. A Word file with screen shots showing your program the tests described above.

Grading

Program has correct class structure, including the base Bank class and derived classes, with appropriate access specifiers

50

Program works correctly for the test cases given and follows the assumptions shown

40

Program comments and variable names

10

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of the code:

(Bank.h)

(Bank.cpp)

(Main.cpp)

Code to copy:

/*Bank.h*/

#ifndef BANK_H

#define BANK_H

#include <iostream>

using namespace std;

// Define the Bank class

class Bank

{

protected:

// Declare the necessary member variables

int accountNumber;

string name;

double balance;

string accountType;

public:

// Declare the necessary functions for the class

Bank();

Bank(int accNumber, string accName, double bal);

string withdraw(double amount);

double deposit(double amount);

void setName(string accName);

int getAccountNumber();

string getName();

double getBalance();

};

// Define the derived class Savings

class Savings : public Bank

{

private:

// Declare the necessary member variables

float annual_interest_rate;

int compound_period;

public:

// Declare the necessary functions for the class

Savings();

Savings(float rate, int period, int accNumber, string accName, double bal);

double addInterest(int num_days);

void setInterestRate(float rate);

void setPeriod(int period);

float getInterestRate();

int getPeriod();

};

// Define the derived class Checking

class Checking : public Bank

{

private:

// Declare the necessary member variables

double minimum_balance, monthly_fee;

public:

// Declare the necessary functions for the class

Checking();

Checking(double min_bal, double fee, int accNumber, string accName, double bal);

void setMinBalance(double min_bal);

void setMonFee(double fee);

double getMinBalance();

double getMonFee();

};

// Declare the displayAccountInfo() function

void displayAccountInfo(Bank);

#endif

/*Bank.cpp*/

// Include the necessary header files

#include "Bank.h"

#include <iostream>

#include <string.h>

using namespace std;

// Define the default constructor for the Bank class

Bank::Bank()

{

accountNumber = 9999;

name = "";

balance = 0;

}

// Define the parameterized constructor for the Bank class

Bank::Bank(int accNumber, string accName, double bal)

{

accountNumber = accNumber;

name = accName;

balance = bal;

}

// Define the withdraw() function

string Bank::withdraw(double amount)

{

// Declare necessary variable

string str_bal;

// Check if the balance is sufficient

if(balance > amount)

{

// Subtract the amount from the balance

balance = balance - amount;

// Assign the balance amount to a variable

str_bal = to_string(balance);

}

else

{

// Assign "insufficient balance" to the variable

str_bal = "Insufficient balance";

}

// Return the value

return str_bal;

}

// Define the deposit() function

double Bank::deposit(double amount)

{

// Add the amount to the balance

balance = balance + amount;

// Return the updated amount

return balance;

}

// Define the setName() function

void Bank::setName(string accName)

{

name = accName;

}

// Define the getAccountNumber() function

int Bank::getAccountNumber()

{

return accountNumber;

}

// Define the getName() function

string Bank::getName()

{

return name;

}

// Define the getBalance() function

double Bank::getBalance()

{

return balance;

}

// Define the default constructor for the Savings class

Savings::Savings():Bank()

{

annual_interest_rate = 0;

compound_period = 0;

}

// Define the default constructor for the Savings class

Savings::Savings(float rate, int period, int accNumber, string accName, double bal):Bank(accNumber, accName, bal)

{

annual_interest_rate = rate;

compound_period = period;

}

// Define the addInterest() function

double Savings::addInterest(int num_days)

{

// Calculate the interest per day

double interest_per_day = balance * annual_interest_rate *(num_days/365);

// Add the interest to the balance

balance = balance + interest_per_day;

// return the value

  return balance;

}

// Define the setInterestRate() function

void Savings::setInterestRate(float rate)

{

annual_interest_rate = rate;

}

// Define the setPeriod() function

void Savings::setPeriod(int period)

{

compound_period = period;

}

// Define the getInterestRate() function

float Savings::getInterestRate()

{

return annual_interest_rate;

}

// Define the getPeriod() function

int Savings::getPeriod()

{

return compound_period;

}

// Define the default constructor for the Checking class

Checking::Checking():Bank()

{

minimum_balance = 0;

monthly_fee = 0;

}

// Define the default constructor for the Checking class

Checking::Checking(double min_bal, double fee, int accNumber, string accName, double bal):Bank(accNumber, accName, bal)

{

minimum_balance = min_bal;

monthly_fee = fee;

}

// Define the setMinBalance() function

void Checking::setMinBalance(double min_bal)

{

minimum_balance = min_bal;

}

// Define the setMonFee() function

void Checking::setMonFee(double fee)

{

monthly_fee = fee;

}

// Define the getMinBalance() function

double Checking::getMinBalance()

{

return minimum_balance;

}

// Define the getMonFee() function

double Checking::getMonFee()

{

return monthly_fee;

}

// Define the displayAccountInfo() function

void displayAccountInfo(Bank bank)

{

// display the account information

cout<<"Account Information"<<endl;

cout<<"\tAccount Number: "<<bank.getAccountNumber()<<endl;

cout<<"\tName: "<<bank.getName()<<endl;

cout<<"\tBalance: "<<bank.getBalance();

}

/*main.cpp*/

// Include the necessary header files

#include <iostream>

#include <cstdlib>

#include "Bank.h"

using namespace std;

// Define the main() function

int main()

{

// Create an array for the Bank class

Bank** Account_List = new Bank*[100];

// Declare the necessary variables

int option, account_count = 0;

do

{

Bank b;

// Declare the necessary variables

int acc_number, account_type;

double start_balance;

string acc_name;

// Display the menu

cout<<"1. Create a Bank Account"<<endl;

cout<<"2. Deposit to the Account"<<endl;

cout<<"3. Withdraw from the Account"<<endl;

cout<<"4. Display all Accounts"<<endl;

cout<<"0. Exit"<<endl;

// Read user's response

cin>>option;

// Print a blank line

cout<<endl;

switch(option)

{

case 1:

// Prompt user to enter the account number

cout<<"Account Number: ";

// Read user's response

cin>>acc_number;

// Prompt user to enter the name

cout<<"Account holder's name: ";

// Read user's response

cin>>acc_name;

// Prompt user to enter the starting balance

cout<<"Starting Balance: ";

// Read user's response

cin>>start_balance;

// Prompt user to select an account type

cout<<"Select the Account Type"<<endl;

cout<<"\t1. Savings Account"<<endl;

cout<<"\t2. Checking Account"<<endl;

// Read user's response

cin>>account_type;

// Check if account type is 1

if(account_type == 1)

{

// Check if the counter is greater than 100

if(account_count >= 100)

{

// Display the array is full

cout<<"Sorry no more accounts can be added!!"<<endl;

// Exit the program

exit(0);

}

// Declare the necessary variables

float interest_rate;

int compound_period;

// Prompt user to enter the interest rate

cout<<"Enter the annual interest rate: ";

// Read user's response

cin>>interest_rate;

// Prompt the user to enter the compounding period

cout<<"Enter the compounding period (in days): ";

// Read user's response

cin>>compound_period;

// Create an object for Savings class and set the values

Savings* s = new Savings(interest_rate, compound_period, acc_number, acc_name, start_balance);

// Add the object to the array of the bank class

Account_List[account_count] = s;

// Increment the counter variable

account_count++;

// Print a blank line

cout<<endl;

break;

}

// Check if account type is 1

else if(account_type == 2)

{

// Check if the counter is greater than 100

if(account_count >= 100)

{

// Display the array is full

cout<<"Sorry no more accounts can be added!!"<<endl;

// Exit the program

exit(0);

}

// Declare the necessary varaibles

double minimum_balance, monthly_fee;

// Prompt user to enter the minimum balance

cout<<"Enter the minimum balance: ";

// Read user's response

cin>>minimum_balance;

// Prompt user to enter the monthly fee

cout<<"Enter the monthly fee: ";

// Read user's response

cin>>monthly_fee;

// Create an object for Checking class and set the values

Checking* c = new Checking(minimum_balance, monthly_fee, acc_number, acc_name, start_balance);

// Add the object to the array of the bank class

Account_List[account_count] = c;

// Increment the counter variable

account_count++;

// Print a blank line

cout<<endl;

}

else

{

// Display an invalid option is selected

cout<<"Sorry an invalid option is selected!"<<endl;

// Print a blank line

cout<<endl;

}

break;

case 2:

// Prompt the user to enter the account number

cout<<"Enter the account number: ";

// Read user's response

cin>>acc_number;

for(int x = 0; x < account_count; x++)

{

// Check if the account number exists in the list

if(acc_number == Account_List[x]->getAccountNumber())

{

// Declare a double variable

double deposit_amount;

// Prompt user to enter amount to deposit

cout<<"Enter the amount to deposit: ";

// Read user's response

cin>>deposit_amount;

// Call the deposit() function and calculate the

// total amount after deposit

double new_bal = Account_List[x]->deposit(deposit_amount);

// Print a blank line

cout<<endl;

// Display the amount has been added to the account

cout<<"$"<<deposit_amount<<" have been added to the account. New balance: $"<<new_bal<<endl;

break;

}

}

// Print a blank line

cout<<endl;

break;

case 3:

// Prompt the user to enter the account number

cout<<"Enter the account number: ";

// Read user's response

cin>>acc_number;

for(int x = 0; x < account_count; x++)

{

// Check if the account number exists in the list

if(acc_number == Account_List[x]->getAccountNumber())

{

// Declare a double variable

double withdraw_amount;

// Prompt user to enter the amount to withdraw

cout<<"Enter the amount to withdraw: ";

// Read user's response

cin>>withdraw_amount;

// Call the withdraw() function and calculate the

// total amount after withdrawal

string new_bal = Account_List[x]->withdraw(withdraw_amount);

// Print a blank line

cout<<endl;

// Display the amount is withdrawn from the account

cout<<"$"<<withdraw_amount<<" have been added to the account. New balance: $"<<new_bal<<endl;

break;

}

}

// Print a blank line

cout<<endl;

break;

case 4:

for(int x = 0; x < account_count; x++)

{

// Display all the accounts

displayAccountInfo(*Account_List[x]);

// Print a blank line

cout << endl;

}

break;

case 0:

// Terminate the program

exit(0);

default:

// Display error message

cout<<"Invalid input! Try again!"<<endl;

break;

}

}while(option != 0);

return 0;

}

Sample output:

Add a comment
Know the answer?
Add Answer to:
Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • In this, you will create a bank account management system according to the following specifications: BankAccount...

    In this, you will create a bank account management system according to the following specifications: BankAccount Abstract Class contains the following constructors and functions: BankAccount(name, balance): a constructor that creates a new account with a name and starting balance. getBalance(): a function that returns the balance of a specific account. deposit(amount): abstract function to be implemented in both Checking and SavingAccount classes. withdraw(amount): abstract function to be implemented in both Checking and SavingAccount classes. messageTo Client (message): used to print...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

  • Java coding help! Write a program to simulate a bank which includes the following. Include a...

    Java coding help! Write a program to simulate a bank which includes the following. Include a commented header section at the top of each class file which includes your name, and a brief description of the class and program. Create the following classes: Bank Customer Account At a minimum include the following data fields for each class: o Bank Routing number Customer First name Last name Account Account number Balance Minimum balance Overdraft fee At a minimum write the following...

  • Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’...

    Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this back can deposit (i.e. credit) money into their accounts and withdraw (i.e. debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction. Create base class Account and derived classes SavingsAccount and CheckingAccount that inherit...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • In Java: DATA TYPE CLASS Create one data type class Account_yourLastName that hold the information of...

    In Java: DATA TYPE CLASS Create one data type class Account_yourLastName that hold the information of an account such as accountNumber (String), name (String), address (String), balance (float), interestRate(float) and beside the no-argument constructor, parameterized constructor, the class has method openNewAccount, method checkCurrentBalance, method deposit, method withdrawal, method changeInterestRate REQUIREMENT - DRIVER CLASS Provide the application for the Bank Service that first displays the following menu to allow users to select one task to work on. After finishing one task,...

  • Design a bank account class named Account that has the following private member variables:

    Need help please!.. C++ programDesign a bank account class named Account that has the following private member variables: accountNumber of type int ownerName of type string balance of type double transactionHistory of type pointer to Transaction structure (structure is defined below) numberTransactions of type int totalNetDeposits of type static double.The totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals. numberAccounts of type static intand the following public member...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT