Calculate the total as well as the average payment

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

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.

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.

International Business Management l2 Consultation fee // error

Imperial Chemical 234 Pest control chemicals

National Home Appliances 34S6 Coffee machines // error

MicroHeart Software Consultancy 45678 Security audit

University of Silver Quartet 5678 Facility management

Telstar Satellite Communication 67O Connection fee // error

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

Reference no: EM13739022

Questions Cloud

Writing a story on bible : I need help writing a story bible. Details in the descriptions. This is called a story bible. Minimum Word Count is 2000 words.
Advantages and disadvantages of incentive pay : List and explain the advantages and disadvantages of incentive pay, and describe how companies can overcome the disadvantages. (75 Words)
Discuss overchoice and assortment type : Rubbermaid's record of new product innovation is remarkable. With almost 5, 000 products, the firm continues to crank out a new one almost everyday - and with great success. It looks like traditional wisdom teaches us that a company may win market..
Write a one page single spaced regional overview paper : Write a one page single spaced regional overview paper.Writer Perspective: You are outsiders working closely with an established company
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
Explain the nature structure types of products : Specify the nature, structure, types of products or service of your chosen organization, and two (2) key factors in the organization's external environment that can affect its success. Provide explanation to support the rationale
Human resources in a global technological environment : Now let us take a look at what it takes to put it all together. How do you manage human resources in a global technological environment? How can an organization be strategic with their most important resource - their people? Explain your answer. Y..
How did the arrival of european explorers : How did the arrival of European explorers and Christian missionaries alter the course of history in East Asia? Did these Europeans cause positive or negative changes?
Why did the united states become involved in world war one : Why did the United States become involved in World War One? How did the Second World War impact the American home front?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Static field holds rent due date for an office

// static field holds rent due date for an office - // rents are due on the 1st

  Rational class performs operations on fractions

Write a C++ program that, using the rational class performs operations on fractions. Test your class thoroughly.

  Write code in a client program

prompt use to enter a name and read it from the standard input device.

  Write an input validation loop

write an input validation loop that asks the user to enter a number in the range of 1 through 4.

  Write a function named digit_name

Write a function named "digit_name" that takes an integer argument in the range from 1 to 9 , inclusive, and prints the English name for that integer on the computer screen.

  Pseudocode for constructing the reverse of an input string

For each position of the string starting at the end working backwards - Append the character at that position to the reverse of the string.

  An expression whose value depends upon the evaluation

Give an example in C++ of an expression whose value depends upon the evaluation order. Show the orders that produce different values and the values they produce. Explain what side effect is the expression contains.

  Write a function to sum a list of numbers

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

  Program that prints the statement

Write a program that prints the statement "Learning new topics is Fun!" in a function called writeThoughts that is called by the main function.

  Prepare the program to calculate the future investment value

Write a C++ program that reads in investment amount, annual interest rate, and number of years in this order, and displays the future investment value using the subsequent formula:

  What is the output

Suppose that x and y are int variables, z is a double variable, and ch is a char variable. Suppose the input statement is.

  Create program to input miles driven and gallons used

Create a program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and display the miles per gallon

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