We're Open
+44 7340 9595 39
+44 20 3239 6980

CREATE A C APPLICATION WHICH WILL READ A FILE OF DAILY PAYMENTS

  100% Pass and No Plagiarism Guaranteed

CREATE A C APPLICATION WHICH WILL READ A FILE OF DAILY PAYMENTS

This assignment is marked out of 100 marks. It is worth 10 % of your overall course mark. Submit your assignment on‐line using the link to Assignment 3 on the course web page.

Assignment 3 consists of one task. For Assignment 3 you must submit all four files listed below in a single ZIP file (not RAR).   All four files must be in pure text format. No PDF, HTML, Word files, Open Office files, RTF etc. and no compression or archiving such as zip, rar, tar etc.  Please name your files to match the names listed.

 

    task_3.cpp – holds main() function,

    exception.cpp – class file for exception handler functions,

    exception.h – class definition file for exception handler functions, and

    task_3.txt – copy of compilation messages and sample runs.

 

      If you are using Codelite, the compilation messages can be copied and pasted with the usual crtl‐c and crtl‐v. For output of sample runs, right click the title bar of the command window, select EDIT/MARK and then highlight the output. With the output selected, right click the title bar of the command window, select EDIT/COPY. Position your cursor to a (new) text file opened in a text editor such as Notepad, and crtl‐v will paste the copied output to the text file.

      If you are using MinGW, right click the title bar of the command window; select EDIT/MARK and then high light the output. With the output selected, right click the title bar of the command window, select EDIT/COPY. Position your cursor to a (new) text file opened in a text editor such as Notepad, and crtl‐v will paste the copied output to the text file.

      If you are using Linux, you can cut and paste the output on the terminal window into a text such as vim.

 

NOTE: MinGW 4.7.1 will be used to compile and test your assignment.  Please ensure that your solution will compile without errors. If necessary comment out erroneous code.

 

Other files you should download:

 

o sample_isdigit.cpp

o data.txt

o data_c.txt

 

Background information

 

bool isdigit()

Thelibrary provides a function isdigit() to test if a char is one of the decimal digits from 0 ‐9. The function will return false when the char is not one of the digits; and true when char is a digit. The code below for Sample_isdigit.cpp illustrates how isdigit() can be used:

 

#include

#include

 

using namespace std;

 

int main(){

char a = `A`; char b = `3`; char c = ` `;

 

if (isdigit(a)){

cout << a << " is a digit!" << endl;

} else {

cout << a << " is not a digit!" << endl;

}

 

if (isdigit(b)){

cout << b << " is a digit!" << endl;

} else {

cout << b << " is not a digit!" << endl;

}

 

if (isdigit(c)){

cout << c << " is a digit!" << endl;

} else {

cout << c << " is not a digit!" << endl;

}

 

return 0;

}

/*

Sample output c>a

A is not a digit!

3 is a digit!

is not a digit!

*/

 

 

NOTE: isdigit() will consider a space to be a non‐digit.

 

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.

 

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.

 

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);

};

 

 

Testing

Test your program to ensure it handles the following scenarios. Compare your program’s output to the sample runs provided.

 

    error in command line argument list

 

    error in input file name

    error in the payment field of some lines in the data file

 

Record your sample output and compilation message(s) to task_3.txt. Please note: the dates displayed in the sample runs below are the actual dates at run time; your results will be different.

 

Sample runs for task_3.cpp:

 

    Incorrect usage of command line arguments:

C:csc2402>g++ -Wall task_3.cpp exception.cpp

 

C:csc2402>a

Usage: app_name data_file_name output_file_name.

    Cannot open input file, do not proceed with processing:

C:csc2402>a dat.txt out.txt

Cannot open data file dat.txt. Please input the correct data file name: daat.txt Cannot open data file daat.txt. Please input the correct data file name: dtta.txt Cannot open data file dtta.txt. Please input the correct data file name: data.txt Cannot open dat.txt, data.txt opened instead.

Do you want to proceed? (`y` to proceed)n

Cannot proceed further. Program is closing down.

 

    Cannot open input file, proceed with processing, invalid data in file:

C:csc2402>a dat.txt out.txt

Cannot open data file dat.txt. Please input the correct data file name: data.txt

Cannot open dat.txt, data.txt opened instead. Do you want to proceed? (`y` to proceed)y

Number contains non digits: l2

Current line will be skipped!

 

Number contains non digits: 34S6

Current line will be skipped!

 

 

 

    Cannot open output file: [test by setting the permissions on your output file to Read only]

C:csc2402>a data_c.txt out.txt

Cannot open data file out.txt. Please input the correct data file name: out2.txt

Cannot open out.txt, out2.txt opened instead. Do you want to proceed? (`y` to proceed)y

 

 

    Sample run for a perfect data file – i.e. remove invalid lines from the data.txt file:

C:csc2402>a data_c.txt out.txt

 

 

 

Marking Criteria

Marks

Command line argument (and use of exception)

15

Open file (and use of exception)

15

Read file

5

Extract payment

5

Check payment (and use of exception)

15

Calculations

5

Write to file

15

Display

5

 

 

Exception classes

10

Compilation messages and sample run outputs (if the program runs correctly)

10


100% Plagiarism Free & Custom Written,
Tailored to your instructions


International House, 12 Constance Street, London, United Kingdom,
E16 2DQ

UK Registered Company # 11483120


100% Pass Guarantee

STILL NOT CONVINCED?

View our samples written by our professional writers to let you comprehend how your work is going to look like. We have categorised this into 3 categories with a few different subject domains

View Our Samples

We offer a £ 2999

If your assignment is plagiarised, we will give you £ 2999 in compensation

Recent Updates

Details

  • Title: CREATE A C APPLICATION WHICH WILL READ A FILE OF DAILY PAYMENTS
  • Price: £ 119
  • Post Date: 2018-11-10T07:17:30+00:00
  • Category: Assignment
  • No Plagiarism Guarantee
  • 100% Custom Written

Customer Reviews

CREATE A C APPLICATION WHICH WILL READ A FILE OF DAILY PAYMENTS CREATE A C APPLICATION WHICH WILL READ A FILE OF DAILY PAYMENTS
Reviews: 5

A masterpiece of assignment by , written on 2020-03-12

I ordered the literature review for my research project in rush delivery. I was not expecting that they would complete my order 2 hours before my chosen time. The quality is also nice. Thank you for help.
Reviews: 5

A masterpiece of assignment by , written on 2020-03-12

Writing is not my field. I take help from this website for my accounting assignment. The work is good and I scored good grades in it. Thank you from the bottom of my heart.