Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ ( I need help writing the program) Using command line arguments for an input file and output file name (see command line argument slides

C++ ( I need help writing the program)

Using command line arguments for an input file and output file name (see command line argument slides and page 3), print out the command line input file name. Verify that the file opened successfully (file stream is valid). If it did not open successfully, enter a while loop that outputs an error message, resets the input file stream being opened and prompts the user to enter another input file name. This file name is read, echo printed and opened. The loop continues until the input file is successfully opened. If the input file is successfully opened, print out the command line output file name and open the output file provided. Verify that the output file opened successfully. If it did not open successfully, enter a while loop that outputs an error message, resets the output file stream being opened and prompts the user to enter another output file name. This file name is read, echo printed and opened. The loop continues until the output file is successfully opened. Use the filename Bad/file to cause the open function to fail for the output file.

The input file contains three lines. The first line is a header line containing the name of the person submitting the grades. The second line consists of 4 integer grades separated by white space. The last line is an information line that is to be used when writing to the output file. This information line is a phrase similar to Test scores for section 01:. See the sample input files for further information.

When reading the data from the file, the first line is ignored (no information is required from it). Then the four scores are read and stored in integer variables. After reading the scores, the status of the input stream is tested to verify that it is still valid. If the input stream is in the fail state mode, an appropriate error message is printed to the terminal AND the output file, and the program is terminated.

If the input stream is valid, the scores are tested to ensure that they have positive values. If any score is less than 0, then the program prints out a message and the scores read to the terminal AND to the output file. The program is then terminated.

If all scores read are greater than or equal to 0 and the input stream is still valid, the scores read are analyzed to determine their sum, average, letter grade for the average, variance and standard deviation. Formulas for performing these math functions are shown on the next page. The cmath header file may be needed for some of the math functions in the formulas. The letter grade for the average is based on the following scale for the average.

Lastly, the information line is read and used in the output as shown by the sample solution. After reading the information line, the input stream is tested to verify that it is still valid. If the input stream is in the fail state mode, then an appropriate error message is printed to the terminal AND the output file. The program is then terminated.

The output is to be written to the output file as shown in the sample output on page 1. The top row has 17 asterisks and three spaces on either side of the word Statistics. Line 2 has the information line read from the input file. The last row consists of 50 asterisks. The solution uses setw(32) for establishing the fields in which the descriptions are written left justified. Output of all floating-point numbers is 2 decimal places. The test scores are read into integer variables and all calculated values are floating-point values.

Test the operation of your program using the sample data files provided. Compare results from your program to those of the sample solution. You may need to create your own files to test all possible conditions Several header files are required: string, iomanip, fstream, cmath and cstdlib. To terminate a program at a specific point, put in the statement: return 1; If you use exit (1); instead of return 1; you will have to close your output file before executing the exit statement and use the header file cstdlib. When test scores are output, they are left justified in a field width of 6 (use with all 4 scores ). Be sure to test your program with all of the input files supplied and invalid input/output file names. Run the comparison script once you believe your program is working correctly The row of asterisks on all the error messages consist of 47 asterisks The bottom row of asterisks on the statistics output contains 50 asterisks. To print out 50 asterisks, you can use string(50,*) If desired, you can modify the makefile from project 5 for use with this project. File Open and File Read Error messages have 47 *s across the bottom and 15 *s on the sides of the top line Output for all floating point values is to be 2 decimal places

Be sure to look at the command line argument slides For this program, instead of int main() use: int main(int argc, char *argv[ ])

To run your program, type the following at the command line: ./Project_06 input_file_name output_file_name

In your program, assign argv[1] to a string variable (inFileName=argv[1];) that is to hold the input file name and argv[2] to a string variable(outFileName = argv[2]) that is to hold the output file name. Use these string variables in the open function when opening the files

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

LO 7-2 Why diversity is becoming more important.

Answered: 1 week ago

Question

Create a workflow analysis.

Answered: 1 week ago