Calculate the total as well as the average payment

Assignment Help C/C++ Programming
Reference no: EM13750287

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 0-9. 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.

o A sample input data file, data.txt, is shown below and provided in your A3 zip file. 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.

-  Line 1 has an error as "l2"has an alphabetic ‘l';
- Line 3 has an error as "34s6" has an alphabetic ‘s';
- Line 6 has an error as ‘67o" has an alphabetic ‘o';
- 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.
- See the sample runs below for the expected results for the data.txt file provided.
- Calculates the total as well as the average payment. Writes the results to the output file and displays it to the screen.
o See the sample runs below for the expected output for the data.txt file provided.

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 : public logic_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.


Attachment:- Code.zip

Reference no: EM13750287

Questions Cloud

Particular analytical measures : The particular analytical measures chosen to analyze a company may be influenced by all of the following except:
Dmv case study : Using the DMV Case Study and the Stakeholder Analysis Exercise spreadsheet provided, you will complete the three columns of the spreadsheet for each of the ten stakeholder groups listed on the spreadsheet
Change model assignment : Imagine that you are an executive for XYZ, Inc., a high-end retail chain that sells luxury watches, jewelry, and hand bags. You've just been put in charge of the company's first international expansion
Companys ratio of liabilities to stockholders equity : The following information was taken from Slater Company's balance sheet: Determine the company's ratio of fixed assets to long-term liabilities. Determine the company's ratio of liabilities to stockholders' equity.
Calculate the total as well as the average payment : 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.
Consolidated statement of retained earnings : On January 2, Year 1, Pool Co. acquired 75% of Kale Co.'s outstanding common stock. The balance sheet data at December 31, 20x1, show retained earnings of $200,000 per company. During 20x1, Pool and Kale paid cash dividends of $25,000 and $5,000, res..
Common measure of liquidity : A common measure of liquidity is
What is the amount of cash received : Buehler Company on June 15 sells merchandise on account to Chaz Co. for $1,000, terms 2/10, n/30. On June 20, Chaz Co. returns merchandise worth $300 to Buehler Company. On June 24, payment is received from Chaz Co. for the balance due. What is t..
Conduct a swot analysis of tesla motors : Conduct a SWOT analysis of Tesla Motors with specific discussion about what you think are the main strengths, weaknesses, opportunities, and threats facing Tesla

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Use object oriented design to create a program to shuffle

Use object oriented design to create a program to shuffle and deal a deck of cards. Deal two, five card hands.

  Write a function to sum a list of numbers

Write a function to sum a list of numbers: (sum '(1 2 3 4))

  Where s is any string

Write a function detab(s, stop), where s is any string, and stop is a positive integer called tabstop size. This function should return a string which is like s.

  Program that evaluates a infix expression

Program that evaluates a infix expression using stacks terminated by an equal sign. for example: (4-2)-5)/(2+1)-2))=the expression will contain single digit and the operators +, -, *,/. Make sure to consider the operator precedence.

  Write a program which accepts the total of food and drink

Write a program which accepts the total of food and drink purchased for a restaurant bill as input. The output should be adjusted bill with a sales tax of six percent 6% and a tip (gratuity) of 15%.

  How can we definean instance of this class

How can we definean instance of this class?

  Show the contents of the id array

Show the contents of the id array after each union operation when you use the quick find algorithm (Program below) to solve the connectivity problem for the sequence 0-2, 1-4, 2-5, 3-6, 0-4, 6-0, and 1-3.

  Write the output of the program

Design a C++ program that will interactively prompt for and read the name of the input file interactively prompt for and read the name of a file to write the output of the program to write the following to the specified output file your name, sect..

  Review structured programming concepts

Review structured programming concepts - Describe the main concepts of the object-oriented programming paradigm.

  Create a program, using at least one for loop

Create a program, using at least one For loop, that displays the Sales Amounts made in each of 4 regions (North, South, East, and West) during a three month period.

  Create a program that outputs the result of the formula

Create a program that outputs the result of the formula f = (a - b)(x - y) using the printf() functions.

  Allow a user to manage the inventory of a small store

Write a C++ program that will allow a user to manage the inventory of a small store.  The inventory for the small store will contain the following information for each product in the inventory:

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd