Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You\'ve been hired by Bookstore Barnacles to write a C++ console application tha

ID: 3703294 • Letter: Y

Question

You've been hired by Bookstore Barnacles to write a C++ console application that manages product inventory. Attempt to open input file ProductInventoryIn.txt. If the file doesn’t open, show an error message and end the application. Remember that input files are placed (and output files appear) in folder <project-name><project-name>. If the file opens, read the following inventory data:

45        Umbrella            6

57        Water_Bottle       42

64        Cuff_Hat           21

72        Diploma_Frame      17

89        Key_Ring           36

Read the data into three parallel arrays each of size 5:

           codes (int)

           products (string)

           inventories (int)

Note that each token within the file contains no spaces so you may use

     inFile >> …

to read each token into the appropriate array element.

Present the following menu to the user:

           Bookstore Barnacles Menu

           1-Sell product

           2-Order product

           3-List products

           9-Exit

           Enter an option:

Create function menuOption that presents the menu and returns the option selected as an integer. Continue to read an option, process it, and display the menu until the user enters the sentinel value of 9. Here are the option descriptions:

           ? Sell product – prompt for and get a product code. If the code is not in the codes array, print an error message. Use a linear search for this. If the code is in the codes array, use a validation loop to get a quantity to sell in the range 1 to the inventory level for that product. Update the inventory level and print the product code, product name, quantity sold, and new inventory level. Format the outputs in two columns with the first column containing a label and the second column containing the value. Show one output per line.

           ? Order product – prompt for and get a product code. If the code is not in the codes array, print an error message. Use a linear search for this. If the code is in the codes array, use a validation loop to get a quantity to order >= 1 for that product. Update the inventory level and print the product code, product name, quantity sold, and new inventory level. Format the outputs in two columns with the first column containing a label and the second column containing the value. Show one output per line.

           ? List products – print the product inventory formatted in three columns, one for each array. Also, show the total inventory after the list. The output should look like this:

           ? Exit – logic for this option is placed after the sentinel loop. Attempt to open output file ProductInventoryOut.txt. If the file doesn’t open, show an error message and end the application. If the file opens, write column headers and data per the above specification. The start of your ProductInventoryOut.txt file should look like this:

Here is a sample program run:

Welcome to Bookstore Barnacles

------------------------------

5 line(s) read from file 'ProductInventoryIn.txt'.

Bookstore Barnacles Menu

1-Sell product

2-Order product

3-List products

9-Exit

Enter an option: 3

Product Inventory

Code      Product         Inventory

45        Umbrella                6

57        Water_Bottle           42

64        Cuff_Hat               21

72        Diploma_Frame          17

89        Key_Ring               36

Total inventory:                122

Bookstore Barnacles Menu

1-Sell product

2-Order product

3-List products

9-Exit

Enter an option: 1

Enter product code to sell: 55

ERROR: code '55' not in list.

Bookstore Barnacles Menu

1-Sell product

2-Order product

3-List products

9-Exit

Enter an option: 1

Enter product code to sell: 45

Enter product quantity to sell: 8

ERROR: quantity to sell must be between 1 and 6.

Enter product quantity to sell: 2

Product Sale

Code:                           45

Product:                  Umbrella

Quantity sold:                   2

Inventory after sale:            4

Bookstore Barnacles Menu

1-Sell product

2-Order product

3-List products

9-Exit

Enter an option: 3

Product Inventory

Code      Product         Inventory

45        Umbrella                4

57        Water_Bottle           42

64        Cuff_Hat               21

72        Diploma_Frame          17

89        Key_Ring               36

Total inventory:                120

Bookstore Barnacles Menu

1-Sell product

2-Order product

3-List products

9-Exit

Enter an option: 9

5 line(s) written to file 'ProductInventoryOut.txt'.

End of Bookstore Barnacles

Explanation / Answer

ScreenShot

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Program

//Header file
#include<iostream>
#include<string>
#include <iomanip>
#include <fstream>
using namespace std;
//Menu display function
void menu();
//Main function
int main()
{
   //variable declaration
   int codes[5], inventories[5],x,z,ch,total = 0,pCode, pQuantity;;
   string products[5],y,choice="true";
   //file object creation
   ifstream inFile;
   //Open fie for reading
   inFile.open("C:/Users/deept/Desktop/Inventory.txt");
   //check the file can open or not
   if (!inFile) {
       cout << "Unable to open file";
       exit(1); // terminate with error
   }
   //File read
   while (!inFile.eof()) {
       //store dat into an array
       for (int i = 0; i < 5; i++) {
           inFile >> x >> y >> z;
           codes[i]=x;
           products[i] = y;
           inventories[i]=z;
       }
   }
   //loop through the menu
   while (choice == "true") {
       //Menu display
       menu();
       //option enter
       cout << "Enter an option:";
       cin >> ch;
       //Option error check
       while (ch != 1 && ch != 2 && ch != 3 && ch != 9) {
           cout << "Please enter an option (1-3 or 9) " << endl;
           cout << "Enter an option:";
           cin >> ch;
       }
       //Each option selection
       switch (ch) {
           //Sell product case execution
       case 1:
          
           cout << "Enter product code to sell:";
           cin >> pCode;
           for (int i = 0; i < 5; i++) {
               if (pCode == codes[i]) {
                   cout << "Enter product quantity to sell: ";
                   cin >> pQuantity;
                   if (inventories[i] >= pQuantity) {
                       inventories[i] -= pQuantity;
                       cout << "Product Sale" << endl << "Code:     " << pCode << endl << "Product : " << products[i] << endl << "Quantity sold : " << pQuantity << endl << "Inventory after sale : " << inventories[i] << endl;
                   }
                   else {
                       cout << "ERROR: quantity to sell must be between 1 and " << inventories[i] << endl;
                       cout << "Enter product code to sell:";
                       cin >> pCode;
                       cout << "Product Sale" << endl << "Code:    " << pCode << endl << "Product : " << products[i] << endl << "Quantity sold : " << pQuantity << endl << "Inventory after sale : " << inventories[i] << endl;
                   }
                   break;
               }
               cout << "ERROR: code '" << pCode << "' not in list." << endl;
           }

          
           break;
           //Order product case execution
       case 2:
           cout << "Enter product code to sell:";
           cin >> pCode;
           for (int i = 0; i < 5; i++) {
               if (pCode == codes[i]) {
                   cout << "Enter product quantity to sell: ";
                   cin >> pQuantity;
                   if (pQuantity >= 1) {
                       inventories[i] += pQuantity;
                       cout << "Product                  Quantity" << endl;
                       for (int i = 0; i < 5; i++) {
                           cout << " " << products[i] << "       " << inventories[i] << endl;
                       }
                   }
                   else {
                       cout << "ERROR: quantity to sell must be between 1 and " << inventories[i] << endl;
                      
                   }
                   break;
               }

           }

           cout << "ERROR: code '" << pCode << "' not in list." << endl;

           break;
           //List all product details
       case 3:

           cout << "Product Inventory" << endl;
           cout << "Code      Product         Inventory" << endl;
           for (int i = 0; i < 5; i++) {
               cout << " " << codes[i] << "   " << products[i] << "              " << inventories[i] << endl;
               total += inventories[i];
           }
           cout << "Total inventory:                " << total << endl;
           break;
           //Exit from the program
       case 9:
           exit(0);
           choice = "false";
           break;

       }
   }

    return 0;
}
//Menu function definition
void menu() {
   cout << " Bookstore Barnacles Menu"<< endl;
   cout << "1-Sell product 2 - Order product 3 - List products 9 - Exit" << endl;
}


---------------------------------------------------------------------------------------------------------------------------------------

Note:-

You have to provide order details in example.

As per my understanding, i add inventory according to the order.

If any clarification,Let me know.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote