Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 (10points): Walmart Inventory Walmart has a list of its inventory in a file. Each line in the file contains the name of the

image text in transcribedimage text in transcribedimage text in transcribed

Question 1 (10points): Walmart Inventory Walmart has a list of its inventory in a file. Each line in the file contains the name of the product and its price separated by a comma. Write a program that reads the name of the file from the user, and then open the corresponding .txt file and output the following: The number of lines in the file (excluding empty lines) The name of the most expensive product in the file The name of the least expensive product in the file Edge cases: If multiple items qualify as the most/least expensive product, then print only the first product (found earlier in the file). The files have not been pre-processed. It might contain empty lines in the file. If the file cannot be opened, then print "Could not open file." Sample file(example_products.txt): Nintendo Switch, 299.99 Vizio 70" 4K SmartTV, 588.00 14" Chromebook, 249.00 Apple Watch Series 3, 169.00 Sample run 1 (bold is user input) Enter the file name: example_products.txt The number of lines: 4 The most expensive product: Vizio 70" 4K SmartTV The least expensive product: Apple Watch Series 3 Sample run 2 (bold is user input) Enter a filename: does-not-exist.txt Could not open the file. Note: You should use the split() function to split each line of the file. The file should be named as walmartInventory.cpp. Don't forget to head over to the code runner on Canvas and paste your solution in the answer box! Nintendo Switch, 299.99 Vizio 70" 4K Smart TV, 588.00 14" Chromebook, 249.00 Apple Watch Series 3, 169.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions