Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help in Part 2 by C++ coding with function arrays. Bank 2.0 now supports N > O customers, each with an account number (positive
Please help in Part 2 by C++ coding with function arrays.
Bank 2.0 now supports N > O customers, each with an account number (positive integer) and a balance (a real number that can be negative, zero, or positive). In part 01 you're going to support the same set of interactive commands as project 01: +,-, ?,^, , and X. The only difference is that the * command will output a subset of accounts -- those within a specific range of account numbers. Here's a summary of the commands: Page 1 of 9 1. Deposit: + account balance ** Welcome to Bank v2.0 ** 2. Withdrawal: - account balance Enter bank filename> bankv2-1.txt 3. Check balance: ? account ** Inputting account data... 4. Find the account with the largest balance: A ** Checking arrays... 5. List accounts that fall within low..high: * low high 1. 7, $250.98 5. 9921, $1258.75 ( Note that low and high do not need to be existing accounts. ] ** Processing user commands... 6. Exit: x Enter command (+,-, ?, ^, *x): * 7 9921 Another difference is the banking file format: the first line of the Account : balance $250.98 Account 34: balance $-10.00 file contains N, the # of bank accounts. For example, here are Account 123: balance $seeeeee.25 the contents of the "bankv2-1.txt" banking file that we'll be Account 467: balance $24.08 using for demonstration purposes: Account 9921: balance $1250.75 Enter command (+,-, ? ,, *, *): 5 7 250.98 34 -10.00 123 5000000.25 467 24.08 9921 1250.75 Note three differences from the previous project: (1) the first line of the file contains the # of bank accounts (5 in this case, but this will change), (2) the data is now guaranteed to be in ascending order by account number, and (3) the balances are always in a fixed format with 2 digits of precision. You may assume the file format is valid, no error checking of the file contents is required. Account 123: balance $5ee0ce0.25 Enter command (+,-) ?, ^, **): oops ** Invalid command, try again... Enter command (+,-, ?, *, *, X): + 9921 580 Account 9921: balance $1750.75 Enter command (+,-, ?, *, *, *): - 34 10 Account 34. balance $-20.00 Enter command (+,-, ?, *, *, *): ? 123 Account 123: balance $5000000.25 Enter command (+, -, ?, ^, , *): ? 99 ** Invalid account, transaction ignored Enter command (+,-) ?, *, *, *): Donec The screenshot to the right shows a sample run based on Saving account data... the "bankv2-1.txt" text file. When the user enters "x" to exit the loop, the program writes the account data back to the same file and ends. Here's the corresponding "bankv2- 1.txt" file after execution of the above: The screenshot to the right shows a sample run based on * Saving account data... Done ** the "bankv2-1.txt" text file. When the user enters "X" to exit the loop, the program writes the account data back to the same file and ends. Here's the corresponding "bankv2- 1.txt" file after execution of the above: 5 7 250.98 34 -20.00 123 5000000.25 467 24.08 9921 1750.75 Notice the first line is N, and the remaining lines use a fixed format with 2 digits of precision. You'll need to configure the output file much like we do the console output: out file at the top of "main.cpp". Your program is required to check if the filename entered can be successfully opened for input. If not, your program should output an error message and immediately return 0; you can assume that if it was opened successfully for input, it will successfully open for output (though it never hurts to check). Example: ** Welcome to Bank v2.0 ** Enter bank filename> pizzabank.txt Inputting account data... **Error: unable to open input file 'pizzabank.txt' Proiect restrictions program should output an error message and immediately return 0; you can assume that if it was opened successfully for input, it will successfully open for output (though it never hurts to check). Example: ** Welcome to Bank v2.0 ** Enter bank filename> pizzabank.txt * Inputting account data... **Error: unable to open input file pizzabank.txt" Project restrictions How you solve the problem is just as important as developing a correct solution. In this assignment we are going to impose the following restrictions, which you must adhere to. Breaking a restriction typically leads to a score of 0. 1. No global variables. A global variable is a variable declared in "main.cpp" but outside of any functions. Use local variables and parameters instead of global variables. 2. The only data structure permitted is dynamically-allocated arrays, created using the new operator. No other data structures: no static arrays, no vectors, no linked-lists, no use of the built-in C++ containers. To be more specific, you'll need to have 2 dynamically-allocated arrays: one for the accounts (an int array), and one for the balances (a double array). The expectation is that the size of these arrays will dynamically adapt based on the input file, and any accounts that may be added or deleted (part 02). It is not acceptable to allocate larger arrays than required and assume those will be big enough; such an approach will yield a project score of 0. 3. To help enforce restriction #2, your main() function is required to call the following function: void checkArrays(int accounts[], double balances[], int N); This will be discussed in more detail in the next section ("Getting Started"). 4. To help enforce good design, you are required to provide (and use) the following two functions: int search(int accounts[], int n, int acct); int maxBalance(double balances[], int N); This will be discussed in more detail in the next section ("Getting Started"). 5. This assignment is about arrays, not files. You are allowed to open the banking file exactly twice, once for input at program start and again for output at program end. 6. No use of the built-in algorithms for searching, sorting, min, max, etc. When necessary, you'll write your own functions. 7. Your program must represent a general solution, e.g. the ability to input & process any banking file not In part 02 you're going to add support for 4 additional ** Welcome to Bank v2.0 ** Enter bank filename> commands: bankv2-1.txt ** Inputting account data... ** Checking arrays... 7. List of accounts with a negative balance: ?, ^, *, *, $, add, del, x): del 34 Deleted account 34 Please note project restriction #2. You may be tempted to Enter command (+,-) ?, ^, *, *, $, add, del, x): del 123 create extra-large arrays at the beginning of the program so Deleted account 123 you can avoid having to enlarge the arrays here. But this type Enter command (+, -, ?, ^, * O customers, each with an account number (positive integer) and a balance (a real number that can be negative, zero, or positive). In part 01 you're going to support the same set of interactive commands as project 01: +,-, ?,^, , and X. The only difference is that the * command will output a subset of accounts -- those within a specific range of account numbers. Here's a summary of the commands: Page 1 of 9 1. Deposit: + account balance ** Welcome to Bank v2.0 ** 2. Withdrawal: - account balance Enter bank filename> bankv2-1.txt 3. Check balance: ? account ** Inputting account data... 4. Find the account with the largest balance: A ** Checking arrays... 5. List accounts that fall within low..high: * low high 1. 7, $250.98 5. 9921, $1258.75 ( Note that low and high do not need to be existing accounts. ] ** Processing user commands... 6. Exit: x Enter command (+,-, ?, ^, *x): * 7 9921 Another difference is the banking file format: the first line of the Account : balance $250.98 Account 34: balance $-10.00 file contains N, the # of bank accounts. For example, here are Account 123: balance $seeeeee.25 the contents of the "bankv2-1.txt" banking file that we'll be Account 467: balance $24.08 using for demonstration purposes: Account 9921: balance $1250.75 Enter command (+,-, ? ,, *, *): 5 7 250.98 34 -10.00 123 5000000.25 467 24.08 9921 1250.75 Note three differences from the previous project: (1) the first line of the file contains the # of bank accounts (5 in this case, but this will change), (2) the data is now guaranteed to be in ascending order by account number, and (3) the balances are always in a fixed format with 2 digits of precision. You may assume the file format is valid, no error checking of the file contents is required. Account 123: balance $5ee0ce0.25 Enter command (+,-) ?, ^, **): oops ** Invalid command, try again... Enter command (+,-, ?, *, *, X): + 9921 580 Account 9921: balance $1750.75 Enter command (+,-, ?, *, *, *): - 34 10 Account 34. balance $-20.00 Enter command (+,-, ?, *, *, *): ? 123 Account 123: balance $5000000.25 Enter command (+, -, ?, ^, , *): ? 99 ** Invalid account, transaction ignored Enter command (+,-) ?, *, *, *): Donec The screenshot to the right shows a sample run based on Saving account data... the "bankv2-1.txt" text file. When the user enters "x" to exit the loop, the program writes the account data back to the same file and ends. Here's the corresponding "bankv2- 1.txt" file after execution of the above: The screenshot to the right shows a sample run based on * Saving account data... Done ** the "bankv2-1.txt" text file. When the user enters "X" to exit the loop, the program writes the account data back to the same file and ends. Here's the corresponding "bankv2- 1.txt" file after execution of the above: 5 7 250.98 34 -20.00 123 5000000.25 467 24.08 9921 1750.75 Notice the first line is N, and the remaining lines use a fixed format with 2 digits of precision. You'll need to configure the output file much like we do the console output: out file at the top of "main.cpp". Your program is required to check if the filename entered can be successfully opened for input. If not, your program should output an error message and immediately return 0; you can assume that if it was opened successfully for input, it will successfully open for output (though it never hurts to check). Example: ** Welcome to Bank v2.0 ** Enter bank filename> pizzabank.txt Inputting account data... **Error: unable to open input file 'pizzabank.txt' Proiect restrictions program should output an error message and immediately return 0; you can assume that if it was opened successfully for input, it will successfully open for output (though it never hurts to check). Example: ** Welcome to Bank v2.0 ** Enter bank filename> pizzabank.txt * Inputting account data... **Error: unable to open input file pizzabank.txt" Project restrictions How you solve the problem is just as important as developing a correct solution. In this assignment we are going to impose the following restrictions, which you must adhere to. Breaking a restriction typically leads to a score of 0. 1. No global variables. A global variable is a variable declared in "main.cpp" but outside of any functions. Use local variables and parameters instead of global variables. 2. The only data structure permitted is dynamically-allocated arrays, created using the new operator. No other data structures: no static arrays, no vectors, no linked-lists, no use of the built-in C++ containers. To be more specific, you'll need to have 2 dynamically-allocated arrays: one for the accounts (an int array), and one for the balances (a double array). The expectation is that the size of these arrays will dynamically adapt based on the input file, and any accounts that may be added or deleted (part 02). It is not acceptable to allocate larger arrays than required and assume those will be big enough; such an approach will yield a project score of 0. 3. To help enforce restriction #2, your main() function is required to call the following function: void checkArrays(int accounts[], double balances[], int N); This will be discussed in more detail in the next section ("Getting Started"). 4. To help enforce good design, you are required to provide (and use) the following two functions: int search(int accounts[], int n, int acct); int maxBalance(double balances[], int N); This will be discussed in more detail in the next section ("Getting Started"). 5. This assignment is about arrays, not files. You are allowed to open the banking file exactly twice, once for input at program start and again for output at program end. 6. No use of the built-in algorithms for searching, sorting, min, max, etc. When necessary, you'll write your own functions. 7. Your program must represent a general solution, e.g. the ability to input & process any banking file not In part 02 you're going to add support for 4 additional ** Welcome to Bank v2.0 ** Enter bank filename> commands: bankv2-1.txt ** Inputting account data... ** Checking arrays... 7. List of accounts with a negative balance: ?, ^, *, *, $, add, del, x): del 34 Deleted account 34 Please note project restriction #2. You may be tempted to Enter command (+,-) ?, ^, *, *, $, add, del, x): del 123 create extra-large arrays at the beginning of the program so Deleted account 123 you can avoid having to enlarge the arrays here. But this type Enter command (+, -, ?, ^, *Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started