Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are working in a company that collects payments from customers of other comp

ID: 3543136 • Letter: Y

Question

You are working in a company that collects payments from customers of other companies. Your company receives a file from your clients containing records for each of their customers.


Ideal Format:

When you get a new client, you give the specification for the file format. Here is what you tell them:

Every file has 30 lines. If a clients needs more accounts processed, they send multiple files.

Each line of the file should be in this format:

      FIRST_NAME LAST_NAME CUSTOMER_ID PAY1 PAY2 PAY3 TOTAL

The CUSTOMER_ID starts with a C and a dash followed by an integer number. For example, C-19283

The PAY1, PAY2, and PAY3 represent payments. Every line should have three payments. Each payment should be an integer. If no payment is received, that column should contain a 0. All payment values should be 0 or larger. No negative numbers are allowed for a payment.

The TOTAL is the sum of the three payments and can be an integer or a double value. Its value should be correct, i.e. the correct sum of PAY1 + PAY2 + PAY3.

All items on a line are separated by a single space.


In an ideal situation, lines will look something like this:

   HARRY POTTER   C-9123  123   123   0   293   416

   ALBUS DUMBLEDORE   C-QWERTY -3   5   12   134

Remember, those last numbers are the sum of the first three. So 123 + 0 + 293 = 416 for Harry.


Unfortuately, your clients - the companies that send this file to your company - don't have the best quality control and they will often send you files with data that does not fit the correct format. For example, you may get this:

   HERMOINE GRANGER 111 123 empty 293 416

Here, the customer id for Hermoine does not have the required C-, and the second payment is not a number. On the second line, the id for Albus does not have an integer after the C-, and the first payment is negative.


Your task is to write a program that can read and process the files. Your program should find the good lines in the input files and extract them. The good data will be sent on for further processing in your company. Your program will also create an error report identifying each line in the input file that has one or more errors. The error report will be returned to the clients so that they can clean up the data and resend it to you at a later date.


Create a C++ file. This program should prompt the user for a file name. Your program should then open the file and process it according to the directions below. Under no circumstances should your program crash.

                      Open the file and process it

                      Create two output files correct.dat and error.dat

                            the line number with the error. The first line in the file is line 1, not line 0

                            A short description of the problem. For example, invalid customer id

                            The thing that caused the error. For example, if the problem was a bad customer id, you should write out what  you                              actually read.

If a line has more than one error, just print a message about the first error on the line.

When a line has an error, do not print any part of that line in the correct.dat file.

Basically, when you find an error on a line, write the error message to the error file and the console, and then skip the remainder of the information on the file and go to the next line.

When you finish processing a file, print the number of lines in the file that had errors on the console.


Keep reading and processing files until the user types quit.

Clear the correct.dat and error.data each time a new input file is processed.

Explanation / Answer

see here

http://pastebin.com/MYd9PR8v

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote