Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create C++ file to match the output style/format of your program to that produced by the provided sample solution. Your program should work for all

Create C++ file to match the output style/format of your program to that produced by the provided sample solution. Your program should work for all provided input files. Use iostream, fstream, string, iomanip, climits only. Don't use arrays, loop & global variables!

image text in transcribed

image text in transcribed

image text in transcribed

The input files ex.)

image text in transcribed

image text in transcribed

For this project, you will write a complete C++ program that performs all of the following tasks. Use variables of Data Type float to contain all numerical values. (1) Because command line arguments are used, first action of the program is to test to make sure that 2 file names were provided. Use the test if (argc 3). If the argc value is not 3, print out an error message and what the correct format should be for running the program and terminate the program. (see page 4) (2) Using command line arguments for an input file and output file name (see command line argument slides and page 3), open the input file provided as the first command line argument. Verify that the file opened successfully. If it did not open successfully, output an error message and terminate the program. See page 4 for information on this test. (3) If the input file is successfully opened, open the output file provided as the second command line argument. Verify that the output file opened successfully. If it did not open successfully output an error message and terminate. Use the filename Bad/file" to cause the open function to fail for the output file. (4) For steps 1 and 2 output a statement stating the name of the file being opened-see the solution (5) The upper case letters A, B and C appear on the first, second and third line of the input file respectively. The input file contains a single occurrence of these letters. Immediately after each letter is a floating point number which must be read, and there may or may not be more characters after the numbers on each line (6) Read in the three numbers and then test to see if any of them are less than 0. If any are negative, determine which ones are negative, output a message as shown in the sample solution and terminate the program. (7) If all numbers are greater than or equal to 0, add them up and determine their average. From the average determine if the average is High (average75), Medium (average The program is to have error messages for the following conditions. Each of these tests results in termination of the program Two file open error message: one for the input file and one for the output file o 15 s on either side of the heading and 47 s across the botton - rest of message comes from looking at sample solution output .Error output block for when one or more numbers are negative. 15 s on either side of the heading and 47 s across the bottom. Rest of message comes from looking at the sample solution Run the sample solution to see the various error messages. See page 4 for more details. Be sure to look at the command line argument slides For this program, instead of int main0 use: int main(int argc, char *argv[ ]) To run your program, type the following at the command line JProject 05 input file name output file name In your program, assignargv] to a string variable (i.e. inFileName-argv[1]:) that is to hold the input file name and argv[2] to a string variable(i.e. outFileName- argv[2]) that is to hold the output file name. Use these string variables in the open function when opening the files. When running the sample solution (not the comparison script), you must provide the input and output file names as command line arguments. The following code is used to test the status of a file stream. Replace the file stream variable indicated (your file stream) with the actual name of the file stream used in your program. Also, replace the file name string variable (filename) with the actual name of the variable that holds the name of the file entered by the user if (your file stream.fail)) cout Input file failed to open properly!n cout Attempted to open file: " Terminating program!n" cout The following code is used to test the number of arguments provided on the command line. When running project 5, the following command is used: JProject 05 inputFileName outputFileName The first value counted and stored in argv[O] is /Project 05, the second value counted and stored in argv[1] is inputFileName and the third value counted and stored in argvI2 is outputFileName So for this project, there are 3 arguments and argc should have the value of 3 Code for your program is the following if (argc -3) cout Incorrect number of Command Line Arguments! "; cout Command for running the program is: " cout The program is to have error messages for the following conditions. Each of these tests results in termination of the program Two file open error message: one for the input file and one for the output file o 15 s on either side of the heading and 47 s across the botton - rest of message comes from looking at sample solution output .Error output block for when one or more numbers are negative. 15 s on either side of the heading and 47 s across the bottom. Rest of message comes from looking at the sample solution Run the sample solution to see the various error messages. See page 4 for more details. Be sure to look at the command line argument slides For this program, instead of int main0 use: int main(int argc, char *argv[ ]) To run your program, type the following at the command line JProject 05 input file name output file name In your program, assignargv] to a string variable (i.e. inFileName-argv[1]:) that is to hold the input file name and argv[2] to a string variable(i.e. outFileName- argv[2]) that is to hold the output file name. Use these string variables in the open function when opening the files. When running the sample solution (not the comparison script), you must provide the input and output file names as command line arguments. The following code is used to test the status of a file stream. Replace the file stream variable indicated (your file stream) with the actual name of the file stream used in your program. Also, replace the file name string variable (filename) with the actual name of the variable that holds the name of the file entered by the user if (your file stream.fail)) cout Input file failed to open properly!n cout Attempted to open file: " Terminating program!n" cout The following code is used to test the number of arguments provided on the command line. When running project 5, the following command is used: JProject 05 inputFileName outputFileName The first value counted and stored in argv[O] is /Project 05, the second value counted and stored in argv[1] is inputFileName and the third value counted and stored in argvI2 is outputFileName So for this project, there are 3 arguments and argc should have the value of 3 Code for your program is the following if (argc -3) cout Incorrect number of Command Line Arguments! "; cout Command for running the program is: " cout

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

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

Students also viewed these Databases questions

Question

How are general obligation bonds sold on the primary market?

Answered: 1 week ago

Question

Identify the job expectancy rights of employees.

Answered: 1 week ago