The input file salesin. txt contains a series of lines with three numbers on each line. Each line corresponds to a certain item which has been bought and then subsequently sold. The first number is the buying price of the item, the second number is the selling price of the item, and the third number is the quantity sold (integer). We are interested in keeping track of the total profit and total loss over all of the items listed in the file. For example, if a line in the $2.12 and this file contains 1.34 1.87 4, then that item yielded a profit of 4(1.87 - 1.34) number should be added to the total profit. Similarly, if another line reads 3.22 2.87 6, then that item had a loss of 6(3.22 - 2.87) = $2.10 and this number should be added to the total loss. Write a program which repeatedly reads the buying, selling, and quantity values from salesin.txt and reports the information to an output file salesout.txt along with the item profit and total running profit, or the item loss and total running loss. For example, if salesin. txt contains the following lines: 2.56 3.44 8 1.24 1.69 5 8.44 7.32 3 3.67 4.12 8. 4.33 4.01 5 then salesout.txt should contain 2.56 3.44 8: profit = 7.04, total profit 7.04 1.24 1.69 5: profit 2.25 total profit = 9.29 8.44 7.32 3: loss 3.36, total loss = 3.36 3.67 4.12 8: profit 3.60 total profit - 12.89 1.60 4.33 4.01 5: loss 1 total loss 4.96 man -

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question
Using c++ programming, plz complete the coding shown below.
#include<stdio.h>
int main(void) {
while (fscanf(fin, "%f %f %d",&v1, &v2, &v3) !=EOF) {
return 0;
Transcribed Image Text:#include<stdio.h> int main(void) { while (fscanf(fin, "%f %f %d",&v1, &v2, &v3) !=EOF) { return 0;
The input file salesin. txt contains a series of lines with three numbers on each line. Each
line corresponds to a certain item which has been bought and then subsequently sold. The
first number is the buying price of the item, the second number is the selling price of the item,
and the third number is the quantity sold (integer). We are interested in keeping track of the
total profit and total loss over all of the items listed in the file. For example, if a line in the
file contains 1.34 1.87 4, then that item yielded a profit of 4(1.87 1.34) = $2.12 and this
number should be added to the total profit. Similarly, if another line reads 3.22 2.87 6, then
that item had a loss of 6(3.22 - 2.87) $2.10 and this number should be added to the total
loss.
Write a program which repeatedly reads the buying, selling, and quantity values from salesin.txt
and reports the information to an output file salesout.txt along with the item profit and
total running profit, or the item loss and total running loss.
For example, if salesin.txt contains the following lines:
2.56 3.44 8
1.24 1.69 5
8.44 7.32 3
3.67 4.12 8
4.33 4.01 5
-
then salesout.txt should contain
profit = 7.04
profit = 9.29
2.56 3.44 8: profit = 7.04, total
1.24 1.69.5: profit = 2.25, total
loss
3.36, total loss = 3.36
profit = 3.60 total profit = 12.89
1.60, total loss
8.44 7.32 3:
3.67 4.12 8:
4.33 4.01 5: loss
4.96
Transcribed Image Text:The input file salesin. txt contains a series of lines with three numbers on each line. Each line corresponds to a certain item which has been bought and then subsequently sold. The first number is the buying price of the item, the second number is the selling price of the item, and the third number is the quantity sold (integer). We are interested in keeping track of the total profit and total loss over all of the items listed in the file. For example, if a line in the file contains 1.34 1.87 4, then that item yielded a profit of 4(1.87 1.34) = $2.12 and this number should be added to the total profit. Similarly, if another line reads 3.22 2.87 6, then that item had a loss of 6(3.22 - 2.87) $2.10 and this number should be added to the total loss. Write a program which repeatedly reads the buying, selling, and quantity values from salesin.txt and reports the information to an output file salesout.txt along with the item profit and total running profit, or the item loss and total running loss. For example, if salesin.txt contains the following lines: 2.56 3.44 8 1.24 1.69 5 8.44 7.32 3 3.67 4.12 8 4.33 4.01 5 - then salesout.txt should contain profit = 7.04 profit = 9.29 2.56 3.44 8: profit = 7.04, total 1.24 1.69.5: profit = 2.25, total loss 3.36, total loss = 3.36 profit = 3.60 total profit = 12.89 1.60, total loss 8.44 7.32 3: 3.67 4.12 8: 4.33 4.01 5: loss 4.96
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT