Answered step by step
Verified Expert Solution
Question
1 Approved Answer
c++ Project 5 error messages This program requires the ublization of concepts in Chapter 4, 5 and 6. Information regarding the tes soores for a
c++
Project 5 error messages
This program requires the ublization of concepts in Chapter 4, 5 and 6. Information regarding the tes soores for a class is sored in an input fie. The est soores and some supporting information is read from the input fie. This information is then processed and written to an output file (see the sample output shown above) Using command line arguments for an inpu: file and output le name (see command ine argument slides and page 3), print out the command line, input file narme, Csee gn, sample, selut on for theousut use) and open the input fie provided. Verty that the file opened successfully (fle stream is vald)iid not open successtully, enter a while lcop that cutputs an error message, resets the input file stream being opened and prompts the user to enter another input file name. This le name is read, echo printed and opened. The lcop continues uncil the input file is supcessully opened. See project 5 for the error message information-the while loop is the exact same (without the return 1)-just replace if with while. If the input file is successfully opened, print out the command line output fie name and open the output fle provided. Verily that the output file opened successlully If it did net open supoessuly, enter a while lcop that outputs an error message, rosets the ouput ile stream being eponed and prompis the user to enter another output file namo. This file, narme is read, ocho primou and opened The loop continues unti the output file is successfully opened. Use the lename "Bad/tilo to couse the epen function to fail fer the The input file conrtains three lines. The first ine is a tHeader line containing the name of the parson submiting the grades. The second line consists of 4 integer grades separated by white space, The lat line is an information line itia: is be used: when writing %, the Dusut 51e This milar to-Test scores for section 01:". See the sample inpu: fies for further information. ine is a phrase When reading the data from the file, the first ine is ignared (no information is required from it). Then the our seores are read and stored in ircager variables. After reading the scores,he status of the input 1ream is tosed to vtrify 2at it is sti. valid. If the inpu: stream is in tht, fail state mode, an appropriate arror message is printed to the terminal AND the output file, and the prograrm is teminated If the input stream i& valid, the sceres are tested o ensure that they have postive values. If any score is ess than G, then he program prints out a message and the scores read to the terminal AND to the output file. The program is hen terminated If all scores read are greater than or equal to O and the input stream &sill vald, the scores read are analyzed to determine their sum, average, letter grade for the average, variance and standard deviation. Farmulas for performing hese math functions are shown on the next page. The cmath header file may be needed for some of the math functicns in the formulas. The letter grade for the average is based on the following scale for the average 90 60 Lastly, the information line is read and used in the output as shown by the sample solution. After reading the information ine, the input stream is tested to venify hat it is still valid. If the inpu: stream is in the fail state mode, then an appropriate error message is printed to the terminal AND the output file The program i then Serminated. The output is to be written to the cutput le as shown in the sample cutput 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 le. The last row consists of 50 asterisiks. The soluion uses setw32) for establishing the fields in which the descriptions are written leftlusified. Ou ut of all floating-port numbers is 2 decrmal places. The test scores are read into integer variables and all calculated values are floating-point values. Input is to tollow the same order as that illustrated by the provided solution executable. Output is to match that shown by the provided solution executable. C++ Concepts Explaine are included or introduced in this The cmath header file: This header fle contains definitions for various math functions including the powixy) function. The powxy) function calculates the value ofx. If powlx.y) is used when calculating the variance, y mus be the integer value af 2 Formulas Required Average X 72 variance var-XX,-Xang)2 Standard Deviation - var There are two ways to terminate a program in main belare it reaches the return 0; at the ed of main One method requires pacing a return 1; (number can be anything but 1 is typicaly used) statement at the point where the program is to be terminated. The other method is to use the exit(1); statement. If the ext(1) statement is used, all output files must be closed before executing te exit(1) statement. Ciosing the output file will empty its buffer before the program terminates. To use the exit function, the header file estd11b must be used. Project 6 Hints Test the cperation of your pragram using the sample data files provided. Compare results from your program to thoee of the sample solution. You may need so create your own files to test all possible conditions Several header fles are required: string, iomanip, fstream, cmath and cstdlib. To terminate a program at a specific point, put in the statement: return If you use exi (1) instead of return 1;you will have to close your output file before executing the exit statement and use the header fle cstdib. When test soores are cutput, they are let justified in a field width of (use wicth all 4 scores Be sure to test your program with all of the input fles supplied and invalid inputibutput fle names Run the comparison script ance you believe your program is warking correctly The row of asterisks on all the error messages consist of 47 asterisks The bottom row of asterisks on he statistics cutput contains 50 asterisks To print out 50 asterisss, you can use string(50,' If desired, you can modify the makele from peoject & for use with this project Fle Open and File Read Eror messages have 47 's across the bottom and 15 ''s on the sides of the top Ine Output for all floating point values is to be 2 decimal places uments Be sure to look at the command ine argument slides For this program, instead of int main) use: int main(int argc, char argv 1) To run your program, type the folowing at the command line: Project 06 input file name output file name In your program, assign argv 1 to a string variable (inFileName argv1that is to hold the input ile name and argv121 to a string variable(outFileName-argv121) that is to hold the output le name. Use these string variables in the open function when opening the iles When running the sample solution (not the comparison script), you must provide the input and output tile names as command line arguments. De sure to test far the correct number of command line arguments in your program-see project 5 CP Makefilep A makefile has been provided that you can use to compile your program. For information on makefiles, ook at the makefile slides and lock at material in Projec Project 5 Error Messages 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 15 *'s on either side of the heading and 47 .'s across the bottom-rest of message comes from looking at sample solution output o 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. 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 E(your file stream.fail() cout Input file failed to open properly|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 argvIO) is Project 05, the second value counted and stored in argv1] is inputFileName and the third value counted and stored in argv2 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 (arge1-3) cout Command for running the program is: "; coutStep 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