C++ Program help - 20407

Request Posted by
traumatize

traumatize

Rating : No Rating
  • Requests:0
  • Solutions:0
Earned: $0
Request Detail
Price: $60
  • From: Computer Science, Programming
  • Due on: Sun 28 Jul, 2013 (04:47pm)
  • Asked on: Sun 28 Jul, 2013
  • Due date has passed, but you can still Post Solution.
Description

Description: In this project, you will combine the experience from previous assignments and projects to create your largest program. You will also gain more experience using arrays, formatting output, and doing simple input validation.  

 

Details: Write a program to simulate a simple banking system.  

 

Your first task is to create a class called Account. This class will store a person's account ID, passcode, last name, first name, and balance.  

 

For your second task, you will create a class called BankingSystem. This class must have the following functionality:

(1)  Add a new account.
(2)  Delete an existing account.
(3)  Print all accounts.
(4)  Deposit money into an account.
(5)  Withdraw money from an account.


BankingSystem must also use a private data array that is declared as follows:  

 

Account accounts_[MAX_NUM_ACCOUNTS];   

 

You can assume a max of 100 accounts.

 

Your third task will be to develop a driver program. The driver program will print a menu allowing the user to choose the option they want. See the sample output below for what each menu option should be.  

 

Place your class declarations in bankingSystem.h. Place your class implementations in bankingSystem.cpp. Place your driver in bankingSystemDriver.cpp. Unlike previous assignments and projects, this one is more open-ended in design (besides the explicit requirements above). But, remember to use good programming practices.  

 

Programming Tips: This project rolls everything together into one. So, it is important to know the concepts from the previous assignments and projects. It may be helpful to create one function at a time in BankingSystem and test it before proceeding. Next, please note the error conditions in the sample output below and the formatting of the accounts. Also, note that you're sort of playing the role of a bank employee more so than a customer, which is why you have more abilities than simply withdrawing and depositing. 
  
Note that your array in BankingSystem is of type Account.  The idea of using a user-defined type as a variable of a class is called composition.  This is just like having an array of type int, except now your type is an object in and of itself, and therefore can encapsulate associated data and functions.  Think of your array as a collection of accounts, where each slot holds one account.  Each account in turn has a last name, first name, balance, etc.
 
Ideally, you would use a vector instead of an array, but we assumed you're more familiar with arrays at this point.  Besides the max-size issue, another issue with using an array is you need to keep track of the current number of accounts with some type of integer variable, whereas with a vector, it keeps track of its own size.  If you're comfortable with using a vector, you can use that instead of an array for this project.  This would also mean you don't have to have a preset number of slots ready for your accounts_variable, instead having the following:


std::vector<Account> accounts_; 
 
Sample Output:  

 

*** Welcome to the Banking System *** 

 
(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit  

 
Enter selection: 1 

 

Enter the account ID: 1 

Enter the passcode: 1 

Enter the first name: Matt 

Enter the last name: Porter 

Enter the starting balance: 50.00 

 

Account added successfully! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 1 

 

Enter the account ID: 1 

 

Account already exists! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 1 

 

Enter the account ID: 2 

Enter the passcode: 2 

Enter the first name: Richard 

Enter the last name: Hurst 

Enter the starting balance: 75.00 

 

Account added successfully! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 1 

 

Enter the account ID: 3 

Enter the passcode: 3 

Enter the first name: Winston 

Enter the last name: Harris 

Enter the starting balance: 100.00 

 

Account added successfully! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 3 

 

Account ID   Passcode   Last Name       First Name       Balance

================================================================

         1          1   Porter          Matt               50.00

         2          2   Hurst           Richard            75.00

         3          3   Harris          Winston           100.00

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 4 

 

Enter the account ID: 4 

 

Account not found! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 4 

 

Enter the account ID: 3 

 

Enter the passcode: 2 

 

Invalid passcode! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 4 

 

Enter the account ID: 3 

 

Enter the passcode: 3 

 

How much would you like to deposit? 0 

 

You must deposit at least a penny! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 4 

 

Enter the account ID: 3 

 

Enter the passcode: 3 

 

How much would you like to deposit? 5.60 

 

Success! The new balance is 105.60! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 3 

 

Account ID   Passcode   Last Name       First Name       Balance

================================================================

         1          1   Porter          Matt               50.00

         2          2   Hurst           Richard            75.00

         3          3   Harris          Winston           105.60

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 5 

 

Enter the account ID: 1 

 

Enter the passcode: 1 

 

How much would you like to withdraw? 51.00 

 

Sorry, you don't have that much money to withdraw! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 5 

 

Enter the account ID: 1 

 

Enter the passcode: 1 

 

How much would you like to withdraw? 20.20 

 

Success! The new balance is 29.80! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 3 

 

Account ID   Passcode   Last Name       First Name       Balance

================================================================

         1          1   Porter          Matt               29.80

         2          2   Hurst           Richard            75.00

         3          3   Harris          Winston           105.60

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 2 

 

Enter the account ID: 4 

 

Account not found! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 2 

 

Enter the account ID: 2 

Enter the passcode: 2 

 

Account erased! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 3 

 

Account ID   Passcode   Last Name       First Name       Balance 

================================================================ 

         1          1   Porter          Matt               29.80 

         3          3   Harris          Winston           105.60

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 2 

 

Enter the account ID: 1 

Enter the passcode: 2 

 

Invalid passcode! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 2 

 

Enter the account ID: 1 

Enter the passcode: 1  

 

Account erased!
 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 
 
Enter selection: 3 

 

Account ID   Passcode   Last Name       First Name       Balance

================================================================

         3          3   Harris          Winston           105.60

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 2 

 

Enter the account ID: 3 

Enter the passcode: 3 

 

Account erased! 

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 3 

 

Account ID   Passcode   Last Name       First Name       Balance

================================================================

 

(1) Add Account 

(2) Delete Account 

(3) Print Accounts 

(4) Deposit 

(5) Withdrawal 

(6) Exit 

 

Enter selection: 6

 

Here are the layouts provided:

 

BankingSystem.h

 

#ifndef _BANKINGSYSTEM_H

#define _BANKINGSYSTEM_H

 

#include <iostream>

#include <string>

#include <cstdlib>

 

//Class Account holds an account ID, passcode,

//first name, last name, and balance.  All variables

//are kept private.  Access/changes are made through

//public set and get functions.

 

class Account

{

 

    public:

 

        void        SetAccountID(unsigned accountID);

        unsigned    GetAccountID();

 

        void        SetPasscode(unsigned passcode);

        unsigned    GetPasscode();

 

        void        SetFirstName(const std::string& firstName);

        std::string GetFirstName();

 

        void        SetLastName(const std::string& lastName);

        std::string GetLastName();

 

        void        SetBalance(double balance);

        double      GetBalance();

 

    private:

 

        unsigned    accountID_;

        unsigned    passcode_;

        std::string firstName_;

        std::string lastName_;

        double      balance_;

 

};

 

//Assume a max of 100 accounts.

 

const size_t MAX_NUM_ACCOUNTS = 100;

 

//Class BankingSystem uses an array of Account.

//You can create, delete, print, deposit, and withdraw.

 

class BankingSystem

{

 

    public:

 

                BankingSystem();

 

        void    CreateAccount();

        void    DeleteAccount();

        void    PrintAccounts();

        void    Deposit();

        void    Withdraw();

 

    private:

 

        Account accounts_[MAX_NUM_ACCOUNTS];

        size_t  current_num_accounts_;

 

        //Use these auxiliary functions if you want.

        //See bankingSystem.cpp for more info.

 

        size_t  FindAccount(unsigned accountID);

        bool    MatchPasscode(unsigned passcode, size_t index);

 

};

 

#endif

 

BankingSystem.cpp

 

#ifndef _BANKINGSYSTEM_CPP

#define _BANKINGSYSTEM_CPP

 

#include <iostream>

#include <string>

#include <cstdlib>

#include "bankingSystem.h"

 

void Account::SetAccountID(unsigned accountID)

{

 

    accountID_ = accountID;

 

}

 

unsigned Account::GetAccountID()

{

 

    return accountID_;

 

}

 

//*** TO DO:  Add the rest of your Account function implementations here.

 

//Default constructor just initializes

//current number of accounts to 0;

 

BankingSystem::BankingSystem() : current_num_accounts_(0)

{}

 

//Find an account by accountID.

//Return the array index if found, current_num_accounts_ otherwise.

 

size_t BankingSystem::FindAccount(size_t accountID)

{

 

    for (size_t i = 0; i < current_num_accounts_; ++i)

        if (accounts_[i].GetAccountID() == accountID)

            return i;

 

    return current_num_accounts_;

 

}

 

//Match the passcode at a given index with the given passcode.

//Return true for a match, false otherwise.

 

bool BankingSystem::MatchPasscode(unsigned passcode, size_t index)

{

 

    return accounts_[index].GetPasscode() == passcode;

 

}

 

//Add an account.

 

void BankingSystem::CreateAccount()

{

 

    Account     account;

    unsigned    accountID;

    unsigned    passcode;

    std::string firstName;

    std::string lastName;

    double      balance;

 

    //Get the account ID and make sure it doesn't already exist.

 

    std::cout << "\nEnter the account ID:  ";

    std::cin >> accountID;

 

    if (FindAccount(accountID) != current_num_accounts_)

    {

 

        std::cout << "\nAccount already exists!\n";

 

        return;

 

    }

 

    //*** TO DO:  Get the remaining items (passcode, first name, last name, balance).

 

    //Set this info into your Account object.

 

    account.SetAccountID(accountID);

    account.SetPasscode(passcode);

    account.SetFirstName(firstName);

    account.SetLastName(lastName);

    account.SetBalance(balance);

 

    //Add the account to your array and increment the count of accounts.

 

    accounts_[current_num_accounts_] = account;

    ++current_num_accounts_;

 

    std::cout << "\nAccount added successfully!\n";

 

}

 

//Delete an account.

 

void BankingSystem::DeleteAccount()

{

 

    size_t   index;

    unsigned accountID;

    unsigned passcode;

 

    //*** TO DO:  Get the account ID and verify it exists.

 

    //*** TO DO:  Get the passcode and verify it matches.

 

    //Remove the account.  First, shift everything over to the left.

 

    for (size_t i = index; i < current_num_accounts_ - 1; ++i)

        accounts_[i] = accounts_[i + 1];

 

    //Then, decrement the count of accounts.

 

    --current_num_accounts_;

 

    std::cout << "\nAccount erased!\n";

   

}

 

//*** TO DO:  Add your remaining BankingSystem function implementations here.

 

#endif

 

 

BankingSystemDriver.cpp

 

#include <iostream>

#include "bankingSystem.h"

 

//Print a menu of options to the user.

 

void PrintMenu()

{

 

    std::cout << "\n(1) Add Account\n";

    std::cout << "(2) Delete Account\n";

    std::cout << "(3) Print Accounts\n";

    std::cout << "(4) Deposit\n";

    std::cout << "(5) Withdrawal\n";

    std::cout << "(6) Exit\n";

    std::cout << "\nEnter selection:  ";

 

}

 

//Start your main program loop here.

 

int main()

{

 

    //All class functions are called through a BankingSystem object.

 

    BankingSystem b;

    int selection;

 

    std::cout << "\n*** Welcome to the Banking System ***\n";

 

    //*** TO DO:  Add a loop that prints a menu and

    //processes the user's selection.

 

    return 0;

 

}

 

 

1 Solution for C++ Program help
Title Price Category solution By purchased  
Banking Account System
$60.00 no category A-coder 2 time(s)
Please Login or Register to Submit the Solution for the Request