Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need someone to write this program in C++ Instructions; Objectives : Read and write to and from data files. Make use of Sentinel values, while

Need someone to write this program in C++

Instructions;

Objectives:

  • Read and write to and from data files.
  • Make use of Sentinel values, while reading data
  • Understand the usefulness of .eof() method

Setup:

Create a data file of the following integers:

10 20 30

17 21 18

30 20 49

40 25 35

55 45 35

25 55 5

-1 -1 -1

Make sure to leave a blank line at the end of the file.

In Visual Studio 2012:

Right click on Source Folder, add, new item, Click on Utility on the side of the panel. Then select text file, make sure to give it a name. If you want to name is input.txt, please just type input, Visual Studio will automatically add the .txt. If you name it input.txt, the file will actually be called input.txt.txt (Do not double click on it until you name it.)

In C++, you just have to copy and paste the text data file into the same folder that the program is in and name it something like input. The .txt will automatically be placed after the name.

Instructions:

Create an input file (see above). The output file will be created when the program runs. Read in the data, three (3) values at a time, from the input file. You will continue to do this until you read the sentinel data line (-1,-1,-1). Arrange the three values that have been read in order from lowest to highest, and then write the set of three numbers to the output file in this ascending order. Use a series of if statements to find the smallest, the middle, and the largest value. When all lines of data have been processed, close both files.

Then reopen the output file as input. (fin.open(output.txt);) Read the data back into your program and print it to the screen. Make sure to use while not End of File to determine when you are done reading data from the file (instead of the sentinel value you used above.) The Sentinel Values (-1,-1,-1) should NOT appear in your output file.

Run:

Run the program as normal; verify that the results on the screen are correct. You should NOT see -1 -1 -1 in either your output file or on the screen.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

2. Describe how technology can impact intercultural interaction.

Answered: 1 week ago