Calculate the total as well as the average payment

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

Assignment

Assignment consists of one task.

The steps to copy the compilation messages and sample runs for the task_3.txt file are software dependent:

- 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()
The <cctype> library 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 <iostream>
#include <cctype>
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!

Number contains non digits: 67O Current line will be skipped!

Date: 05/12/15 16:57:40
Total payment: $51590 Average payment: $17196.67

- 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 Date: 05/18/15 13:45:32
Total payment: $51590 Average payment: $17196.67

- 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 Date: 05/12/15 16:57:40
Total payment: $51590 Average payment: $17196.67

Attachment:- Data.rar

Verified Expert

The task was to read from a file and write the output to another file and throw exceptions during reading/writing of file or in case of wrong no. of command line arguments.The main aim was to learn Exception handling in C++.A header file was created to handle exceptions.

Reference no: EM131517723

Questions Cloud

How will it benefit individuals businesses and society : What is the Internet of Things? How will it benefit individuals, businesses, and society? Support your views with one or two examples
Recent organizational change at school : 1. Think about a recent organizational change at school, at work, or someplace else that you were part of.
Describe the major adjustment issues discussed in story : Discuss why you recommend the strategy you chose.On what do you base your assertions?
Health care supply and demand : You are the director for an integrated delivery system (IDS) materials-management department. Use the library, course materials, and Web resources.
Calculate the total as well as the average payment : CSC2402 - Create a C++ application which will read a file of daily payments, calculate the total as well as the average payment.
Compare spreadsheet solution to answer to the given problems : A piece of equipment is purchased for $110,000 and has an estimated salvage value of $10,000 at the end of the recovery period. Prepare a depreciation schedule.
What is the expected rate of return of the ten year : what is the expected rate of return of the 10 year, 1000$ par value bond paying 7 percent interest annuallu
Calculate the depreciation for residential real estate : Prepare a spreadsheet to calculate the depreciation for residential (27.5-year recovery period) and commercial (39-year recovery period) real estate using the s
Determine the amount of anny brums capital as of first june : Determine the amount of Anny Brum's capital as of June 1. Prepare an income statement for June, a statement of owner's equity for June, and a balance sheet.

Reviews

inf1517723

6/27/2017 5:27:39 AM

A day ago was left to present my task and was quite strained. While surfing web I came to think about you. Due to you just I could present my assignment before due date and one thing which i enjoyed the most is you didn't requested any additional cost to make my pressing undertaking. I'm enthusiast of yours!!

inf1517723

6/27/2017 5:24:35 AM

A number of issues have been noticed. Please read the full assignment. The task_3.cpp file also contains two openFile() functions, one each to open the input and output files. They are listed in the assignment and what functionality they both require are also listed. I have attached what the exception.h with the proper class definitions is in it just as is stated in the assignment task I provided. Please use this as the exception.h file. Please READ THE ASSIGNMENT INSTRUCTIONS CAREFULLY AND MAKE SURE YOU DO EXACTLY WHAT IT SAYS TO DO. 23885929_1exception.h

len1517723

6/5/2017 3:11:51 AM

The steps to copy the compilation messages and sample runs for the task_3.txt file are software dependent: • 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.

len1517723

6/5/2017 3:11:40 AM

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.

len1517723

6/5/2017 3:11:06 AM

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

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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