In: Computer Science
DO NOT ANSWER THIS QUESTION[Write a program that the owner of Chica Chic could use to store data about her inventory in a text file. The program should prompt her to input the name, cost price, and quantity of each item of inventory. Each of these three data has to be written to its own line in the file. The program should loop to enable any number of inventory items to be stored and end when the item name is left blank (see Sample Output. User inputs are shown in blue). The program should end by closing the file and printing a file status message. Sample Output Enter the name of the inventory item or ENTER to quit tops Enter the cost price of this item 24.99 Enter the quantity in stock of this item 10 A record was written to file Enter the name of the inventory item or ENTER to quit shorts Enter the cost price of this item 29.95 Enter the quantity in stock of this item 12 A record was written to file Enter the name of the inventory item or ENTER to quit sandals Enter the cost price of this item 19.79 Enter the quantity in stock of this item 8 A record was written to file Enter the name of the inventory item or ENTER to quit The file was created successfully and closed] DO NOT ANSWER THIS QUESTON
Now write another program that reads her inventory file,
displays all data for each item, and reports on the inventory
value. The cost value of each item and the
cost value of the total inventory should be
reported. Strive to duplicate the Sample Output
below.
Sample Output
Chica Chic Inventory
tops, $24.99 each, 10 in stock, value $249.90
shorts, $29.95 each, 12 in stock, value $359.40
sandals, $19.79 each, 8 in stock, value $158.32
End of file
Total inventory value $767.62
********This require a lot of effort so please give a thumbs up if you are satisfied with the content***********
You have not specified any programming language so I have written it using python for ease and less lines of code
Storing Inventory File Code:
import os.path # In below path change the ----- text \Users\----\Desktop to your username so that # the file saves on your desktop savePath = "C:/Users/THE__INFINITY/Desktop" nameOfTheFile = "Inventory" completeName = os.path.join(savePath, nameOfTheFile + ".txt") f = open(completeName, "a+") # Code for Storing the inventory while (1): print("Enter the name of the inventory item or ENTER to quit") name = input() if (len(name) > 0): print("Enter the cost price of this item:") cost = input() cost = float(cost) print("Enter the quantity in stock of this item") quantity = input() quantity = float(quantity) value = str(format("%.2f" % (quantity * cost))) f.write(name + " $" + str(cost) + " value:" + value + "\n") else: print("The file was created successfully and closed") break f.close()
*******The file will be created on desktop please go through the comments in the code to set the path where you want to store the file ******
Inventory Reading File Code:
import os.path try: savePath = "C:/Users/THE__INFINITY/Desktop" nameOfTheFile = "Inventory" completeName = os.path.join(savePath, nameOfTheFile + ".txt") totalValue = 0 f = open(completeName, "r") fileContents = f.read() inventory = fileContents.split("\n") print("Chica Chic Inventory") for eachRecord in inventory: value = eachRecord.split(":") if (len(value) == 2): print(eachRecord) totalValue = totalValue + float(value[1]) print("End of file") print("Total inventory value $%.2f" % totalValue) f.close() except OSError: print("file not found please create a file first")