Question: C++ Create a program that will read data from a file called prog1.txt. The data will consist of the product item name, quantity, location and
C++
Create a program that will read data from a file called prog1.txt. The data will consist of the product item name, quantity, location and price for products in an inventory. You do not know how many data items there will be in the file and should read the file until no more data is found. Some strings will contain a space (use getline). All of the output for the program will go to the screen. Have the main call a function to input the data from the file prog1.txt and store the data in four parallel arrays, item, qty, location and price. The max number of elements should be set to 30 utilize a globally declared named constant. However, the input function will keeps track of the number of products actually read from the file and return that count to main(). It is possible that the data file contains more than 30 items in it, handle that in your function knowing that you only have room for 30 in your arrays. The main() should: 1. Declare all arrays and variables needed 2. Call the ReadData function to read the data and populate the arrays a. Pass the arguments needed b. Open the file prog1.txt inside this function. c. Use a while loop to read data into the arrays until EOF is reached and you have room in the arrays. d. close the file 3. Print raw data, i.e., in order it appears in the file (before sorting). 4. Call the BSort function to sort all four arrays from lowest to highest by quantity. (WORRY ABOUT THIS FUNCTION LAST, IN THE MEANTIME, USE A STUB) a. Use the bubble sort to sort all four arrays simultaneously using the qty array as the key. 5. Call the PrintArrays function that prints the four arrays in tabular form with column headers a. Print the arrays in tubular form using formatting via the setw function 6. Call the Restock function to print each product that is under stock. A product is under stock if it has fewer than 100 items in stock. Display the product item name and quantity in tabular form. 7. Call the LoPrice function to return the subscript of the lowest price product in stock via the return statement. 8. Call the AverWarehouse function to return the average price for each of the three warehouses (see data). (Hint: You will need three sets of counters and accumulators. Lastly, the function will return all three averages via reference parameters). 9. Add code in your main to display the item name, location and price of the lowest price product in stock. (Output: The lowest priced item is , located in warehouse with a price of $ ). 10. Add code in your main to display the average prices for all three warehouses.
Prog1.txt looks have this in its files
Zip Drive 89 Warehouse C 75.89 Keyboard 133 Warehouse C 25.95 Blu Ray 54 Warehouse J 34.87 Iphone 90 Warehouse M 850.00 Ipod 174 Warehouse M 180.99 DVD Player 85 Warehouse J 124.91 Heat Sink 157 Warehouse C 138.45 Ext Drive 245 Warehouse C 152.87 Speakers 187 Warehouse J 163.55 Camera 147 Warehouse J 138.97 SD Card 100 Warehouse C 18.87 Router 148 Warehouse C 115.28 Printer 125 Warehouse M 145.87
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
