Lab #6 Sub Procedures, Functions, looping, structures and files A retail store h
ID: 3624479 • Letter: L
Question
Lab #6 Sub Procedures, Functions, looping, structures and filesA retail store has five bins, numbered 1 to 5, each containing a different commodity. At the beginning of a particular day, each bin contains 50 items. The table below shows the cost per item for each of the bins, and the quantity sold during that day.
Write a program to
(a) read sales data from a file (cis14l6.txt)
(b) Place the cost per item and the quantity sold for each bin into an array of structures;
(c) Display a table giving the inventory at the end of the day and the amount of revenue obtained from each bin;
(d) Compute the total revenue for the day;
(e) List the number of each bin that contains fewer than 25 items at the end of the day.
(f) Sort the list from least sold to most sold, and output that result.
Format of cis14l6.txt
Column 1 is the bin number, column two is the price, and column 3 is number sold for the day.
The cis14l6.txt data is
1,13.00,20
2,2.25,35
3,7.45,19
4,17.49,42
5,34.95,17
Explanation / Answer
A) Use System.IO.StreamReader & its ReadLine function B) You'll need to parse the lines; use the string.Split function - you'll want to split on the comma character. You can populate each structure by calling the TryParse functions of the int and double classes with the split strings. C) To display the table, make a function that will accept one 'bin' structure and print it, then loop through your array of structures, using this function to print each one. (or, if you want to impress your teacher, override the ToString function) D) Loop through your array of bin structures and keep a running total of the # sold per bin times the cost of the item in that bin. E) Loop through your array of bin structures and display a warning for each bin that has less than 25 items remaining F) You have a couple choices here; the easiest way is to move the array of structures into a linked list, then use a for loop going from 0 to the structure array's length and have an integer (initially set to # sold in struct 0) to track the current 'least sold' number. Loop through the entire array; at the end of the loop, add the structure with the lowest quantity sold to the end of a second linked list, while removing it from the first linked list. Continue to loop until the first linked list is empty - at this point, the second list contains your sorted bin quantities.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.