Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

define a structure to store a bank transaction. Each transaction contains the following information: a unique id (an integer), account number (an integer), dollar amount

define a structure to store a bank transaction. Each transaction contains the following information: a unique id (an integer), account number (an integer), dollar amount (double) and date (a string) containing the date and time when the transaction took place. For example:

1278657 1000258915 456.78 3/07/2022-18:15:00

This indicates a transaction with id 1278657 with account number 1000258915 for $456.78 dollars was register on March 07, 2022 at 6:45 PM.

C++ program to do the following: (5 points) Define the structure to store the information of a transaction (5 points) In the main function, display a menu to get user's option:

A. Get file location B. Readfileinformation C. Displaystatistics D. Search for a transaction (ID) E. Add a transaction F. Exit

You need to implement input validation to make sure that i) Option A was chosen before any of the B to E options, ii) Option B was chosen before C or D options, iii) The file name (and location) is valid before choosing E, and iv) only options from A to F are valid, among others. (10 points)

When A is chosen: (10 points) Ask the user to enter the file "full path" (location, filename and extension), then call a

function with the following header and description int testInputFile(string fullpath):This function receives a string as argument with the file location + name + extension. Returns the number of transactions in the file, and -1 if the files does not exists or 0 if it is empty (contains no data). If the file does not exist or is not readable, display a message to the user.

When B is chosen: (20 points) Check if option A was already chosen. Then call a function with the following header and

description:

array and a string with the file location + name + extension. Firstly, the function tests if the array already exists. If it does, release the memory, and allocate a new array of transactions of size SIZE. Then read the file information into the transaction array. The function returns true on success( no error allocating the array, nor reading the file) and false o.w. This function can be called if and only if, option A chosen and succeed before.

bool readTransactionInformation (transaction *&arr, int SIZE, string fullpath): This function receives a pointer to an array of transaction, the size of the

When C is chosen: (30 points) Call a function with the following header and description:

void transactionStatistics(transaction *arr, int size, int &min, int &max, double &average): This function finds the statistics about the transactions

by searching the element with the minimum and maximum dollar amount and calculates the average dollar amount of all the elements (The average is calculated by adding each element dollar amount in the array then dividing this sum by the size of the array). The first parameter of this function is a pointer to the dynamically created array, the second parameter is the size of the array, the third parameter is the index of the transaction with the minimum dollar value that is passed by reference, the fourth parameter is the index of the transaction with the maximum dollar value passes by reference, and the last parameter is the average value that is passed by reference. The transactionStatistics function returns a void, i.e. nothing needs to be return. Still, since min, max, and average are pass by reference, you should be able to display these variables' calculated values from the caller (main) function. Display the value of each statistic properly in the caller function (main). This function can be called, if and only if, option B was chosen and succeed before.

When D is chosen: (10 points) Ask the user for transaction id (an integer value - key). Then call a function with the

following header and description:

transaction *searchElement(transaction *arr, int size, int key): Search for an element in the array of transactions. The first parameter to the function is a pointer to the array. The second parameter is the size of the array. The third parameter is the value entered by the user and represents the transaction id you are looking for. You may either use linear or binary search here, whichever is most convenient for you. The function returns a pointer to the element if the key was found in the array, or a nullptr/NULL if the element was not found. Pleasedisplay properly whether the element was found (if found), or the element was not found (if the element is not found) in the main function.

When E is chosen: (10 points)

Call a function with the following header and description: bool addTransaction (string filename): This function receives a string as argument with the file location + name + extension. The function asks the user for the transaction details (e.g., id, account, amount and date and time), and appends the transaction information to the file. The function returns true if successful and false otherwise. In case of failure, it should display a message to the user.

When F is chosen: (5 points) Quit the program and release the memory that was dynamically allocate(if any). Option F

is the only way to end the program. This is, for any other option (A-D) the menu is displayed again. When option F is chosen, the program exits.

Please provide a screenshot of the output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

\f

Answered: 1 week ago