Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91297363
  • Price:- $70

Priced at Now at $70, Verified Solution

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As