Question: IN C++ thank you String nameOfFile is read from input. The opened file named nameOfFile contains counts of peaches ordered by a grocery store, and

IN C++ thank you

String nameOfFile is read from input. The opened file named nameOfFile contains counts of peaches ordered by a grocery store, and is associated with the stream inFS. Integers are read from the opened file and output, before being subtracted from remainingQuantity. Output "Remaining: " followed by remainingQuantity if the end of the file has been reached. Otherwise, output "Read operation failed" if a read operation fails before the end of the file is reached. End with a newline.

Ex: If the input is data4.txt, then the output is:

32 34 82 39 69 Remaining: 219 

Ex: If the input is data6.txt, then the output is:

80 Read operation failed

Contents of file data1.txt Contents of file data2.txt Contents of file data3.txt Contents of file data4.txt Contents of file data5.txt Contents of file data6.txt
89 97 62 31 90 97 12 bad 42 51 32 34 82 39 69 29 74 28 80 bad 69 21 60 94

#include

#include

#include

using namespace std;

int main() {

ifstream inFS;

string nameOfFile;

int peachQuantity;

int remainingQuantity;

cin >> nameOfFile;

inFS.open(nameOfFile);

if (!inFS.is_open()) { cout << nameOfFile << ": failed to open file" << endl; return 1; }

remainingQuantity = 294;

inFS >> peachQuantity;

while (!inFS.fail()) { cout << peachQuantity << endl; remainingQuantity = remainingQuantity - peachQuantity; inFS >> peachQuantity; }

/* Your code goes here */

inFS.close();

return 0;

}

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!