Write a modularized, menu-driven program to read a file with an unknown number of inventory records using an array of structs/objects Menu (use a switch statement)  options to print valid items in the inventory unsorted print invalid records from an error file quit the program Menu A user  should be able to run as many times as the user wants; print the menu every time do not call menu recursively;  use recursion only when it is necessary menu should be called in a loop, use enum value to control the loop Implement the menu as a switch statement using enum;  Although it is recommended to use enum classes instead of enum, for the purpose of this lab  and considering that many students in the class  are taking CS 216  this semester, use enum All items are unique in the input file Record Item Id must be 5 characters long; must be alpha-numeric The name may contain only alpha characters Quantity and price may be zero (a promotional item, an item is not in stock) status value is not in the input file< Formatting output ( screen and error file)  records to be printed in a table format with headers Reading from the input file and storing the records should be done in a function, not main()  do not pass files to the function, you do not need them in main, you only  need them in  the function The input file has an unknown number of records of inventory items one record per line in the following  order: item ID, item name (one word), quantity on hand, and a price  All fields in the input file are separated by a tab (‘\t’) or a blank (up to you) the input file may be empty or has more records that your array can store- output the appropriate messages to the user check for the array boundaries when storing the records Only go through the file once - do not  read the file once to count the number of the records, close it, and then read it again Store all invalid records along with the error messages in a separate file print the record first and then print the list of all errors on the same line  print the  bad record once only, for example:  /123 candy -5 3.8   ID must be 5 characters and alphanumeric only    qty must be  at least 0 one bad record = one entry/line in the error file; do not print bad records more than once could create a local variable to store error messages and keep appending to it if more errors found                                              string errMessage="" ;                                              if( Id length !=MAX_ID_LENGTH)                                                       errMessage= errMessage + " ID must be 5 characters"; could create a const string errList{" ID must be 5 characters", " ID must be alphanumeric"...} and a parallel enum  Use an array of structs if you do not know how to write classes yet. Use classes if you have completed CS 216 or similar; do not store bad records in the array of records create only one array for valid records, no need to store all records or bad records read a record from  a file into a temp struct; error-check the record and only store the record in the array of records if it is valid if you choose to create a class for an inventory item write one function to set a record, call this functions in all c'tor and other setter functions ( if any); it reduces code redundancies, and modifications will be reduced to updating of one function only;           for example, class Record has only two member vars: m_id and m_name                      setRecord( string id, string name) { m_id=id; m_name=name;}                      setName(string name) {setRecord(m_id, name)}                      Record() {setRecord("", "')}; create a toString()  function to return the record as a formatted string, then you can use this function to output a record to  a screen or file ( cout<

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

9/15/21 updates are in blue

Write a modularized, menu-driven program to read a file with an unknown number of inventory records using an array of structs/objects

  • Menu (use a switch statement)  options to
    • print valid items in the inventory unsorted
    • print invalid records from an error file
    • quit the program
  • Menu
    • A user  should be able to run as many times as the user wants; print the menu every time
    • do not call menu recursively;  use recursion only when it is necessary
    • menu should be called in a loop, use enum value to control the loop
    • Implement the menu as a switch statement using enum;  Although it is recommended to use enum classes instead of enum, for the purpose of this lab  and considering that many students in the class  are taking CS 216  this semester, use enum
  • All items are unique in the input file
  • Record
    • Item Id must be 5 characters long; must be alpha-numeric
    • The name may contain only alpha characters
    • Quantity and price may be zero (a promotional item, an item is not in stock)
    • status value is not in the input file<
  • Formatting output ( screen and error file)
    •  records to be printed in a table format with headers
  • Reading from the input file and storing the records
    • should be done in a function, not main()
    •  do not pass files to the function, you do not need them in main, you only  need them in  the function
    • The input file has an unknown number of records of inventory items
    • one record per line in the following  order: item ID, item name (one word), quantity on hand, and a price 
    • All fields in the input file are separated by a tab (‘\t’) or a blank (up to you)
    • the input file may be empty or has more records that your array can store- output the appropriate messages to the user
    • check for the array boundaries when storing the records
    • Only go through the file once - do not  read the file once to count the number of the records, close it, and then read it again
    • Store all invalid records along with the error messages in a separate file
      • print the record first and then print the list of all errors on the same line 
      • print the  bad record once only, for example:  /123 candy -5 3.8   ID must be 5 characters and alphanumeric only    qty must be  at least 0
      • one bad record = one entry/line in the error file; do not print bad records more than once
      • could create a local variable to store error messages and keep appending to it if more errors found
                                                     string errMessage="" ;
                                                     if( Id length !=MAX_ID_LENGTH)
                                                              errMessage= errMessage + " ID must be 5 characters";
      • could create a const string errList{" ID must be 5 characters", " ID must be alphanumeric"...} and a parallel enum 
    • Use an array of structs if you do not know how to write classes yet. Use classes if you have completed CS 216 or similar;
    • do not store bad records in the array of records
    • create only one array for valid records, no need to store all records or bad records
    • read a record from  a file into a temp struct; error-check the record and only store the record in the array of records if it is valid
    • if you choose to create a class for an inventory item
      • write one function to set a record, call this functions in all c'tor and other setter functions ( if any); it reduces code redundancies, and modifications will be reduced to updating of one function only; 
                 for example, class Record has only two member vars: m_id and m_name
                             setRecord( string id, string name) { m_id=id; m_name=name;}
                             setName(string name) {setRecord(m_id, name)}
                             Record() {setRecord("", "')};
      • create a toString()  function
        • to return the record as a formatted string, then you can use this function to output a record to  a screen or file ( cout<<rec.toString(); outfile<<rec.toString()) 
        • use stringstream to format the string
          string toString() {
               stringstream ss;
               ss<<setw(20)<<m_id<<setw(25)<<name; 
               return ss.str() }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY