Question: Question 5 ( 20 marks ) A supermarket is a self-service shop offering a wide variety of food and household products. A file named Compare.txt

 Question 5 ( 20 marks ) A supermarket is a self-service

Question 5 ( 20 marks ) A supermarket is a self-service shop offering a wide variety of food and household products. A file named Compare.txt contains unknown number of products records in two giant supermarkets (maximum number of records is 100). Each line in the file consists of product name (string), product price in supermarket one (float), product price in supermarket two (float) respectively. Write a program that reads the data from the file into 3 parallel arrays. Your program should calculate and display the following (see sample file and screen output below): The number of products in supermarket one priced cheaper priced higher and priced equal to same products in supermarket two. Calculate Avgi to equal the average price for all products in supermarket one. Calculate Avg2 to equal the average price for all products in supermarket two. Find the highest product price of both stores. Find all product names to have a price (supermarket one or supermarket two) higher than Total average price. Total average price is calculated as follows: Total average price = (Avg1 + Avg2) = 2 = Compare.txt (Input file) Shampoo_1 2.050 Potato_SA 0.245 Chicken_FZ 1.400 Galaxy 0.300 Fairy_LRG 0.980 2.100 0.250 1.350 0.300 1.050 Screen Output Cheaper 3 Higher 1 Equal 1 The average price in one 0.995 The average price in two 1.010 The highest product price is 2.1 Product Name Shampoo_1 Chicken_FZ Fairy_LRG

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!