Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program that saves prices in a sequential access file. Save the prices

ID: 3544373 • Letter: C

Question

Create a program that saves prices in a sequential access file. Save the prices in fixed-point notatio with two decimal places. Name the sequential access file Introductory20.txt and open the file for append. Use a negative number as teh                sentinel value. Save and then run the program. Enter the following prices an sentinel value: 10.50, 15.99, and -1. Now, run the program again. This time, enter the                following pries and sentiel value: 20, 76.54, 17.34,and -1. Open the Introductory20. txt file in a text editor. The file should contan five prices, with each prices appearing on a                seperate line in the file. Close the Introductory20.txt file

Explanation / Answer

#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
ofstream outfile;
outfile.open("Introductory20.txt",ios::app);
double value = 0;
while(value>=0)
{
cout <<"Enter an integer to write to file.(negative value to stop) :";
cin >>value;
if(value<0) break;
outfile << fixed << setprecision(2) << value << endl;
}
outfile.close();
//uncomment below line to see command window.
//system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote