Question
My program has to have 9 outputs and each output is supposed to be different. in the picture is all the outputs. I need to
My program has to have 9 outputs and each output is supposed to be different. in the picture is all the outputs. I need to make a code where for example if I type "in0.txt" in the "enter input file:" It should only give me the output for in0.txt. The outputs of all the input files are posted above.
These are the input files I need for the assignment. please use these:
In.txt:
A001 Apples 1 0.90 21 A002 Peaches 1 0.82 11 A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
in0.txt
A001 Apples 1 0.90 21 A00% Peaches 1 0.82 11 A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
in1.txt
A001 Apples 1 0.90 21 A002 [eaches 2 0.82 11 A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
in2.txt
A001 Apples 1 0.90 21 A002 Peaches 11 0.82 11 A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
in3.txt
A001 Apples 1 -0.90 21 A002 Peaches 1 0.823 11 A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
in4.txt
A001 Apples 1 0.90 21 A002 Peaches 1 0.82 11. A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
in5.txt
A001 Apples 1 0.90 21 A002 Peaches 1 0.82 11 &^ A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
in6.txt
A001 Apples 1 0.90 A002 Peaches 1 0.82 11 A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
in7.txt
A001 Apples 1 0.907 21 A002 Peaches 1 0.825 11 A009 Strawberries_Case 0 12.50 8 4261 Rice_1_LB_Bag 0 0.49 107
2.3 HW3 This honework assignment gives you the opportunity to practice strings (C+string class) and chars. HW3 (Graded out of 100) Write a program that performs input validation when reading grocery product records from a file. Each grocery product record consists of the following 5 items: PLU code: Product Look Up Code. Unique for cach product, stored as a string Product Name, stored as a string Product Sales Type 0-per unit, 1-per pound Price per Pound or price per unit, Current Inventory Level (pounds or units) Below is an example of file content. In this example, there are four records, and each line corresponds to a record. A001 Apples 1 0.90 21 A002 Peaches 1 0.82 11 A006 Avccados 0 1.54 27 A008 Mangos 0 1.69 19 Your program should read a file and performs input validation on the items read, then print the outcome of the input validation: File has valid content if all the dala is valid File has invalid content otherwise, along with the reason To contain valid data, the file must have only valid records. A record is valid if It has exactly 5 items on the same line The first item should be a PLU.It is valid if and only if it contains only letters or digits, and is 4 characters long .The second item should be product name. It is valid if and only if the first character is a letter The third item should be a sales type. It is valid if and only if it is only one character, and the character is a 1 ora0 The fourth item should be a unit price. It is valid if and ornly if it contains only digits and at most one dot. If there is a dot, there are at most two digits after the dot The fith item should be the inventory level. It is valid if and only if it contains only digits In order to validate the individual items, each line has first to be broken into tokens, where a token is a string that corresponds to an item. The tokens are separated by one or more delimiters, where a delimiter is a space, a tab, a new line or a carriage return. To take the line A001 Apples 1 0.90 21 as an example, the first token would be A001, the second token would be Apples, and so on. You may assume cach line contains at most only one record. 1. Additional Requirements Make sure you meet all the requirements to avoid losing points a) Functions You are required to implement your program with these functions. You may implement more functions to make your program more modular if you wish /1 Returns true if the string a valid pLu, false otherwi 3e bool isvalidPLU (string) /+Retuns Leue if the string is a valid product name, false otherwise bool isValidName(string) *Returns true if the atring is a valid salea type, false otherwiae bool iaValidType (atring) Returns true if the string is a valid price, false otherwisc bool SValidPrice (string); * Return true if the string is a valid inventory level, fa!e otherwise bool iavalidInventory (atring) Takes as refereace parameter a string to be tokenized and returns the first token found Returns the empty string if no token is found The function deletes any leading delimiter and the first token found from the original string Tokenization is based on a delimiter, where a delimiter is the 't' (tab)(space), n (new line) or 'r' (carriage return) character Example: if the atring a ia "t abed\tit 3451t 75 ", the function returna "abod" aa the firat token found, and modifies the string s to become "tit 3451t 7S" string tokenize (string ) b) Outline of main Prompt the user to enter a file name Read from the file and repeatedly call tokenize to extract the items Print the item and perform the appropriate validation. For example, for the first token which should be the PLU, porform PLU validation. For the second token, porform name validation, etc. Print the result of the validation. If an item is invalid, determine that the file is invalid and close the file. Check every line haa the correct number of items. if the number of items ia not 5, print an error message, determine that the file is invalid and close the file. If all validations are successful, the file is determined to be valid. Print a message to indicate if the file is valid or invalid c) Style Make sure you follow the style requirements, especially regarding the comment header for functions, to avoid losing points. 2. Implementation Suggestions- You are not required to implement the suggestions You are allowed to use any of the existing library functions in chapter 10 of the Gaddis textbook. a) bool isFileValid(string file Open file // Check that open is successful Read line by line. For each line: Repeatedly call tokenize to extract the items Print the item and perform the appropriate validation. Print the result of the validation. If an item is invalid, close the file and return false Check the line ha the correct number of items. if the number f item 15 not 5, print an error message, close the file and return falae At end of file, close the file and return true Notes: To read line by line, you can use getline(inFile, stringRead) Detect end of file when getline returns an empty string b) string tokenize(string& s) Loop over the characters of s as long as they are a delimiter and the end of s is not reached// Remove any leading del Loop over the remaining character a3 long as they are not a delimiter and the end of i3 not reached Extract the Lirst token ound imiter (s) store the characters into token Delete the first n character from above loops is the number of characters looped over in the two 2. Grading criteria Source code inspection (grader) Style: 5 points (reter to the Homework Notes" for the style requirements) .Code compilation and execution (zylabs) . Source code inspection (grader) Style: 5 points (refer to the Homework Notes" for the style requirements) Code compilation and execution (zylabs) Oulput les-1- Valid file Outpul exacly malches oulpul-1:9 points Output test-2- File with invalid PLU Output exactly matches output-2:9 points Output test-3- File with invalid product name Output exactly matches output-3: 9 points Output test-4 File with invalid sales type Output exactly matches output-4:9 points Output test-5 File with invalid price Output exactly matches output-5: 9 points Output test-6- File with invalid inventory Output exactly matches output-6:9 points Output tost-7- File with cxcessive number of items Output exactly matches output-7:9 points Output test-8 File with insufficient number of items Output exactly matches output-8: 9 points Output test-9 File with invalid price Output exactly matches output-9: 9 points Unit test-1 tokenize: 9 points Unit test-2 - isValidPrice: 5 points 3. Screen outputs Enter input file:in.tx: Checkinc in.txt. Token tl A001, PLUs valid Token t2 is Apples, Product name is valid Token 13 is 1, Sales type is valid Token t4 is 0.90, Price valid Token 5 is 21, Inventory i3 valid Token is Peaches, Product name is valid Toren #3 i 1, Sales type 1 valid Enter input file:in.txt Checking in.txt Token #2 is Apples, Product name i valid Token #3 is 1, sales type is valid Token #4 lg 0.90, Price is valid Token f5 13 21, Inventory is valid Token f1 ia A002, PLU is valid Token f2 is Peaches, Product. name is valid Token t3 8 1, sales type is valid Token t4 is 0.82, Pricc is valid Token #5 is 11, Inventory is valid Token #1 1 A009, PLU iy valid Token #2 i Strawberrie Ca3e, Product name i= valid Token #3 is 0, sales type is valid Token #4 is 12.50, Price is valid Token f5 13 8, Inventory i3 valid Token f1 is 4261, PLU is valid Token f2 1 Rice-1-1.8-Hag, Product name i valid Token f3 8 0, sales type i8 valid Token t4 is 0.49, Price is valid Token t5 is 107, Inventory is valid y 23. HW3 -My Grades-MATH 241 e Get Homework Hepw eind deer cludeorch GH 315 edat OfK einducercludeainck e Get Homework HelpWi e "rouce.ncl deorch best way to screers ot + https://eenybooks.co." otokiUTDALLAS01337CS1337TE1.)I7ueskerg20190h aple'/2 edina zyBooks My library >CE 1337/CS 1337/TE 1337 Computer Science I home 2.3: HW:3 E 7yBooks catalog @ Help/FAQ safan ali Enter input file:ino.txt Checking ino.txt Token #1 is A001, PLU 3 valid Token t2 is pples, Product name is valid Token #3 is 1, sales type is valid Token #4 0.90, Price valid Token f5 ia 21, Invent.ory is valid Token 1 ia A0OS, PLU is invalid Output-2 Enler input file:inl.xL Checking inl.txt Token 1 A001, PLU is valid Token #2 ia Apples, product name is valid 'Loken 43 1, sales type ig valid Token f4 ig 0.90, Price 1 valid Token #5 ig 21, Inventory 10 valid Token #1 is A002, PLU is valid Token #2 is [eaches, Product name i invalid O lype hene to search y 23. HW3 -My Grades-MATH 241 e Get Homework HelpWi eind deer clueorch GH 31ra edat Of 1( e.noucench deainck e Get Homework Help wi e "r cuce. due@ich pest way tos eers ot zyBooks My library >CE 1337/CS 1337/TE 1337 Computer Science I home 2.3: HW:3 E zyBooks catalog Help/AQ safan ali Enter input tile:in2.txt Checking in2.txt Tokon t1 is A001 PLU is valid Token #2 8 Apples, Product name is valid Token #3 i 1, sales type is valid Token ig 0.90, price i a valid Token #5 ia 21, Inventory 1g valid Token 1 ia A002, PLU is valid Token #2 13 Peaches, Product name ig Valid Token #3 is 11, Salea type is invalid Output-4 Enter input file:in3.txt Checking in3.txt. Token 1 ia A001, PLU is valid Token #2 ig Apple, Product name is valid Token #3 is 1, Sales type is valid roken #4 is -0.90, Price invalid O lype hene to search Enter input file:in4.txt Checking in4.txt Token #1 is A001, PLU is valid Token #2 is Apples, Product name is valid Token #3 is 1, sales type is valid Token #4 is 0.90, Price is valid Token #5 is 21-Inventory is valid Token #1 is A002, PLU is valid Token #2 is Peaches, Product name is valid Token #3 is 1, sales type is valid Token #4 is 0.82, Price is valid Token #5 is 11., Inventory is invalid # # # # # # # # in4. txt has invalid content # # # # # # # Output-6 Enter input file:in5.txt Checking in5.txt Token fl ig A001, PLU 3 valid Token +2 ia Applea, Product name is valid Token 3 ia l, Sales type is valid Token +4 ia 0.90, Price is valid Token 45 ia 21, Inventory is valid Token 1 ia A002, PLU is valid Token f2 ia peaches, Product name i, valid Token 3 ia 1, salea type is valid Token +4 ia 0.82, Price is valid Token 5 ia 11, Inventory is valid 'l'oken f6 1g , 'l'oo many items in record in5.txt has invalid content. Output-7 Knter input file:in6.txt Checking in.t.xt Token #1 is A001, PLU g valid Token 2 is Apples, Product name is valid Token #3 is 1, sales type is valid Token #4 is 0.90, price i8 valid Tnventory is invalid, record has missing items tititit in6.txt. has invalid content tt Output-8 Knter input file:in7.txt Checking in7.txt. Token is A001, pLUis valid Token #2 is Apples, Prodiet name is valid Token 3 s 1, Sales type is valid Token #4 is 0.907, Price is invalid tHtttt in7.txt. has invalid content ttitttt Output-9Step 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