Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this project, you will write a complete C++ program that performs all of the following tasks Use variables of Data Type flost to contain
For this project, you will write a complete C++ program that performs all of the following tasks Use variables of Data Type flost to contain all numerical values. (1) Because command ine arguments are used, first action of the program is to test to make sure that 2 file rnames were provided. Use the test if (argc!3). f the arge value is nat 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 fie name (see command line argument sides ard page 3), apen the input file provided as the first command line argument Venify that the file apened successfully. If it cid not open successfuly, output an error message and terminate the program-See page 4 for intormation on this test (3) If the input file is successtully opened, open the output tile provided as the second command ine argument Verity that the output le opened suocessfully. If it did not open successfully output an error message and terminate. Use the filename "Bad/tile to cause the open function to tail tor the output tie (4) For steps 1 and 2 output a statement staing the name of the file being opered-see the solution (5) The upper case letters A, B and C appear on the first, seoond and third line of the input e respectively. The input le contairs a si each letter is a floating paint number characters after the numbers on each line e occurrence of these letters. Immediately after which must be read, and there may or may not be more (8) Read in the three numbers and then test to see if any of them are less than O. It 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 it the average is High (average >75), Medium (average When all numbers are posibve, make sure output is to the output file-including the output statements that set up the formattng. . All error messages are written to the terminal . For a program written expecting command line arguments, a segmentation fault will occur if command line arguments are not provided. Run the sample solution (rot the comparison scnipt) to see what the program writes to the terminal and to the output file, and the order in which the information is written Look at the contents of an input file (see page 3) to see what has to be read. . Be sure to look at the command line argument slides For this program, instead of int main) use: int main(int argc, char argvt 1) To run your pragram, type the tollowing at the command line: Project 05 input file name output file name In your program, assign argv 1] to a string variable (i.e. inFileName argvi1:) that is to hold the irput fie name and arg 2] to a string variablefi.e. outFileName argv[2) that is to hold the output file name. Use these string variables in the open function when opering the files. When running the sample solution (not the comparison script), you must provice the input and output file names as command line arguments. The following code is used to test the number of arguments provided on the command line. When nring project 5, the following command is used: maject 05 rpu FileName outputFileName The first value counted and stored in argvo) is Project 05, the second value counted and stored in argv 1) is inputFileName and the third value counted and stored in argv 21 is outputFileName So for this project, there are 3 arguments and arge should have the value of 3 Code for your pragram is the following if (arge 1-3) cout ./Project-05 inputFileName outputFileName " cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started