Project 2
Description: In this project, you will combine the experience from previous assignments and projects to create your largest program. You will also gain experience using vectors, reading and writing files, and formatting output.
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 at least the following functionality:
Add a new account.
Delete an existing account.
Inquire on an existing account (or all accounts).
Save accounts to a file.
Load accounts from a file.
BankingSystem must also use a private data member that is declared as follows:
vector <Account> accounts_;
Your third task will be to develop a driver program. The driver program will print some type of menu allowing the user to choose the option they want. Instead of using a BankingSystem object, you must use a pointer to a BankingSystem object with the new operator. So, in your driver program (int main()), you would write the following:
BankingSystem* myBankingSystem = new BankingSystem();
At the end of your program (end of main() before returning), you have to free this memory explicitly by writing the following:
delete myBankingSystem;
Unlike previous assignments and projects, this one is very open-ended. Besides my explicit requirements, you are free to make your own design decisions. But, remember to use good programming practices such as those pertaining to formatting, commenting, and file organization (i.e. header, implementation, driver).
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. Remember from the chapter on arrays that a vector is really just a "better" array. Vector's can make life easier than arrays for tasks like searching, adding, and removing items. Another good reference you can find online is
http://www.cplusplus.com/reference/stl/vector/. For adding an account, you will find the push_back() function useful. For removing an account, you will find the erase() function useful.
If you would rather not use vectors, which are recommended, they can be substituted using arrays. Due note that arrays cannot grow and shrink as a vector can, so there may be some additional complexity that may prove more difficult.
That said, here are some vector code snippets....
Similar to an array, to create a vector that will store account objects, you'll need to:
vector <Account> accounts_;
If you need more storage in your vector to hold additional account information, you can do so by dynamically creating a new position:
accounts_.push_back( bankAccount );
As with an array, you can iterate through each position of your vector by using the size() function in your for loop. In order to access an object stored in the vector, just use the same indexing method that you'd use for an array.
for( int i = 0; i < accounts_.size(); i++ )
{
bankAccount = accounts_[ i ];
...... Your Code ......
}
Basically, once you come to understand the initial syntax of using a vector, working with them is not that much different that working with an array.
Sample Output:
*** Welcome to the Banking System ***
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 1
Enter the accountID: 1
Enter the passcode: 1
Enter the first name: Yosemite
Enter the last name: Sam
Enter the starting balance: $2.45
Account added successfully.
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 1
Enter the accountID: 2
Enter the passcode: 2
Enter the first name: Bugs
Enter the last name: Bunny
Enter the starting balance: $2.50
Account added successfully.
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 1
Enter the accountID: 3
Enter the passcode: 3
Enter the first name: Daffy
Enter the last name: Duck
Enter the starting balance: $45.00
Account added successfully.
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 3
Enter the account ID (-1 for all): -1
Account ID Passcode Last Name First Name Balance
================================================================
1 1 Sam Yosemite 2.45
2 2 Bunny Bugs 2.50
������ 3 3 Duck Daffy 45.00
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 4
Enter the filename: bankaccounts.txt
File bankaccounts.txt saved successfully.
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 2
Enter the accountID: 1
Account erased.
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 2
Enter the accountID: 2
Account erased.
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 2
Enter the accountID: 3
Account erased.
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 3
Enter the account ID (-1 for all): -1
Account ID Passcode Last Name First Name Balance
================================================================
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 5
Enter the filename: bankaccounts.txt
File bankaccounts.txt loaded successfully.
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 3
Enter the account ID (-1 for all): -1
Account ID Passcode Last Name First Name Balance
================================================================
1 1 Sam Yosemite 2.45
2 2 Bunny Bugs 2.50 3 3 Duck Daffy 45.00
(1) Add Account
(2) Delete Account
(3) Account Inquiry
(4) Save Accounts to File
(5) Load Accounts from File
(6) Exit
Enter selection: 6
Bonus Challenge:
Add the ability to withdraw money from an account (5 points).
Add the ability to deposit money into an account (5 points).
Submission:
As always, make sure to include your header in each file:
/***********************
Your Name
Project 2
***********************/
Zip up the coded files and title the zip with the following format: lastname, first initial, underscore, proj2 (ie John Doe would submit DoeJ_proj2.zip)
Submit the zip file.