Question: C++ // Write a program to read a file called products.txt, which contains an arbitrary number of lines of products in the format While reading

C++ // Write a program to read a file called products.txt, which contains an arbitrary number of lines of products in the format While reading the products determine what is the max and min total price (total price = price * quantity) among the products.

Programs must be fully commented add a comment in the beginning describing what your program does and how! Also add any other comments where necessary.

Sample file (this is just a sample file, your program should work correctly with file with 2 or any number of lines!):

10.5 10

4.5 20

1.5 100

A sample output of the program, for the above input, as shown below:

Max total price is: 150

Min total price is: 90

Explanation: The total prices for the products in the file are 10.5 * 10 = 105, 4.5 * 20 = 90 and 1.5 * 100 = 150, so max is 150, min is 90.

Note: If the opening of the file fails for some reason (not existing file was passed to the open function, etc.) print the message Failed to open the file! and terminate the program.

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!