Question
Task Create a C++ application which will read a file of daily payments, calculate the total as well as the average payment, display the results
Task Create a C++ application which will read a file of daily payments, calculate the total as well as the average payment, display the results to the screen and write the results to a file. The input and output file names should be provided as command line arguments. task_3.cpp The task_3.cpp file holds the main() function which is responsible for the following functionality: Extracts the input file name and output file name from the command line arguments. o If the number of command line arguments is not correct, throw an exception. The exception class is Argc_error : public logic_error.
o The exception handler should display a prompt for the correct usage and exit. Please use the same phrasing shown in the sample runs below. Calls the appropriate openFile() function (see description below) to open the relevant files. If the file name returned by openFile() is different from the one originally specified in the command line, require the user to confirm to proceed with processing or to quit. Please use the prompts shown in the sample runs provided below. Reads the input file line by line, and extracts the relevant payment.
o Check if the extracted payments are valid. Throw an exception if the payment is not a number all characters are digits from 09. The exception class for errors is Digit_error : public logic_error.
o If the payment is not valid, the exception handler will skip the line, and display a message. Please use the same error messages shown in the sample runs below.
Each line has the first 40 char for the name, then 10 char space for the payment, and the rest of the line for comments. Each line has the first 40 char for the name, then 10 char space for the payment, and the rest of the line for comments. Calculates the total as well as the average payment. Writes the results to the output file and displays it to the screen.
The task_3.cpp file also contains two openFile() functions, one each to open the input and output files. Each openFile() function should provide the following functionality:
Attempts to open the passed in file name.
If there is an error when opening the provided file name the function should throw an exception, passing whatever information is required to the exception handler. Please use the error messages shown in the sample runs below.
The exception handler should display an appropriate error message and prompt the user to provide a new file name, again please use the prompts shown in the sample runs below. The exception handler should then recursively call openFile() passing the new file name. The openFile() function will continue to be recursively called until a file is successfully opened. In practice you would put a limit on the number of potential calls, in order to avoid infinite recursion. For this assignment please disregard this problem.
The relevant exception class for the two openFile() functions are shown below. o string openFile(ifstream& in, string str): Input file exception class is Readfile_error : public logic_error. o string openFile(ofstream& out, string str): Output file Exception class is Writefile_error : publiclogic_error. Return the name of the opened file.
You may also find it convenient to include separate functions to perform required conversions from string to integer and dates to strings. exception.cpp, exception.h
The required exception class definitions are shown below. Implement the required exception functions in exception.cpp. Include code in exception.h to prevent multiple inclusion of the file. class Argc_error : public logic_error{ public: Argc_error (string reason); }; class Readfile_error : public logic_error{ public: Readfile_error (string reason); }; class Digit_error : public logic_error{ public: Digit_error (string reason); }; class Writefile_error : public logic_error{ public: Writefile_error (string reason); };
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