Compile and run your code to verify it works correctly. When run, you should see the following data in the file neat.txt:

12.34
-9.88
2.31
-89.51
12.33
92.88
-123.46

If you have problems, ask a classmate or the instructor for help as needed.

Save your program source code file to submit to Canvas as part of assignment 12.

Listing of readwrite.cpp

When finished developing your code, click here to compare your solution to mine. After you have completed your own solution, reviewing another is often helpful in learning how to improve your programming skills.

Save the file products.txt to the same directory as your program source code.

We will read from this file after writing our program.

Write a function with the following signature:

void readFile(string filename);

Inside the function readFile(), add code to declare an input stream named fin and to connect the stream to the input file using the string fileName parameter. Make sure you connect the stream without calling open() (see lesson 12.2.1).

Add the following code to function readFile() that reads all the values from the input file.

Implement the readFile() function using the declared prototype from the starter code and the following pseudocode.

void readFile(vector<Product>& list, string filename) {
// open an input file stream
// test if the stream failed to open
// while the file stream is good
// construct a temporary object
// call the read() function on the object
// if no error during read()
// then push onto back of vector
// close the stream after the loop ends
}

Implement the writeFile() function using the declared prototype from the starter code and the following pseudocode.

void writeFile(vector<Product>& list, string filename) {
// open an output file stream
// test if the stream failed to open
// for each object in the vector
// call the write function
// close the stream after the loop ends
}

Write an endl after each output command. See section 12.3.6 for more information.

Call writeFile() from main() by uncommenting the menu code like:

writeFile(list, "saved.txt");

Compile and run your code to verify it works as before. Select menu 3 to write to a file. Open the "saved.txt" output file and verify it is the same as the original "products2.txt" file.

Submit your program source code (productfile.cpp) to Canvas as part of assignment 12.