Question
CSC 1101 Problem Solving and Programming Laboratory Lab 22 [your name] 25 points a) Save this document with your name and the homework number somewhere
CSC 1101 Problem Solving and Programming Laboratory
Lab 22 [your name]
25 points
a) Save this document with your name and the homework number somewhere in the file name.
b) Type/paste your answers into the document.
c) Submit this document and your .cpp file(s) to the Blackboard item where you downloaded this document. Do not submit a zip file but individually attach your files.
PROGRAMMING LANGUAGE C++
You've been hired again by Bookstore Barnacles to update the C++ console application that manages product inventory. You may start with your own Lab 20 application, or start with the Lab 20 application key. Updates to the application are highlighted in yellow. Attempt to open input file ProductInventoryIn2.txt. If the file doesnt open, show an error message and end the application. Remember that input files are placed (and output files appear) in folder
45 Umbrella 6 21.00 28.00
57 Water_Bottle 42 11.00 15.00
64 Cuff_Hat 21 17.00 20.00
72 Diploma_Frame 17 100.00 120.00
89 Key_Ring 36 4.00 6.00
Read the data into one array of structs of size 5. The struct has the following fields:
code (int)
name (string)
inventory (int)
cost (double)
price (double)
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, sale revenue (price * quantity), 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, amount of order (cost * quantity), 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 five columns, one for each struct field. Also, show the total inventory after the list.
? Exit logic for this option is placed after the sentinel loop. Attempt to open output file ProductInventoryOut2.txt. If the file doesnt open, show an error message and end the application. If the file opens, write the updated data in the same layout as the input file.
Here is a sample program run:
Welcome to Bookstore Barnacles
------------------------------
5 line(s) read from file 'ProductInventoryIn2.txt'.
Bookstore Barnacles Menu
1-Sell product
2-Order product
3-List products
9-Exit
Enter an option: 3
Product Inventory
Code Product Inventory Cost ($) Price ($)
45 Umbrella 6 21.00 28.00
57 Water_Bottle 42 11.00 15.00
64 Cuff_Hat 21 17.00 20.00
72 Diploma_Frame 17 100.00 120.00
89 Key_Ring 36 4.00 6.00
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
Sale revenue ($): 56.00
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 Cost ($) Price ($)
45 Umbrella 4 21.00 28.00
57 Water_Bottle 42 11.00 15.00
64 Cuff_Hat 21 17.00 20.00
72 Diploma_Frame 17 100.00 120.00
89 Key_Ring 36 4.00 6.00
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 'ProductInventoryOut2.txt'.
End of Bookstore Barnacles
Use these same inputs for your last run:
Option | Value(s) |
---|---|
3 |
|
1 | 99 |
1 | 89, 40, 10 |
3 |
|
1 | 64, 4 |
3 |
|
2 | 57, 8 |
3 |
|
9 |
|
[your program code here]*
If possible, format your code like this:
Font Courier New
Font size 9s
Bold
[your program output here]**
[your ProductInventoryOut.txt file here]***
* Copying-and-pasting application code to a Word document
1) From the program editor window, press CTRL-A and press CTRL-C.
2) From within the Word document, press CTRL-V.
** Copying-and-pasting application output to a Word document
1) From the Eclipse main screen, maximize the Console window.
2) From the Console window, press ALT-PrintScreen.
3) From within the Word document, press CTRL-V.
*** Copying-and-pasting text file to a Word document
1) From a text editor, open the file and maximize the window.
2) From the text editor window, press ALT-PrintScreen.
3) From within the Word document, press CTRL-V.
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