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

You have a disk file samples of a recorded sign The signal.dat which time-stampe

ID: 3838332 • Letter: Y

Question

You have a disk file samples of a recorded sign The signal.dat which time-stamped the time file has two contains first being columns of numbers, the stamps, and the second is the at the start of the file which use. There is single integer of which follow acts as a header, identifying two columns the length of the Write a complete C++ program which will read in this file, then write the data it out in reverse order to a new file called reverse. reverse dat should have the same two columns dat. Thus in order as compared as signal.dat but each should be reversed to the original file should have the same header as signal data. The reverse. dat dat. For brevity, your solution may omit both error checking on tests) and alignment formatting on the output etc.). (i.e. setw, the files (i.e. s-open

Explanation / Answer

Note:

As i dont know the exact contents signal.dat file,I took some data in signal.dat file

________________

signal.dat ((Save this file under D Drive.Then the path of the file pointing to it is D:\signal.dat)

5
2012-05-19:15:22:45 456
2011-02-22:23:19:23 122
2006-01-01:23:21:01 536
2008-05-23:09:22:06 877
2009-11-12:05:45:37 12

________________

Program:


#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
// Declaring variables
int size;
string timestamp;
int signal;
// defines an input stream for the data file
ifstream dataIn;

// Defines an output stream for the data file
ofstream dataOut;


// Opening the input file
dataIn.open("D:\signal.dat");

// creating and Opening the output file
dataOut.open("D: everse.dat");

// Reading the size from the file
dataIn >> size;
dataOut << size << endl;

/* Read timestamps and signal values from input file
* and write in reverse order in output file
*/
for (int i = 0; i < size; i++)
{
dataIn >> timestamp >> signal;
dataOut << signal << " " << timestamp << endl;
}

// Closing the intput file
dataIn.close();

// Closing the output file.
dataOut.close();

return 0;
}

_____________________

outputfile:

reverse.dat(We can See this file under D Drive.As we specified the path of the output file as D: everse.dat)

5
456   2012-05-19:15:22:45
122   2011-02-22:23:19:23
536   2006-01-01:23:21:01
877   2008-05-23:09:22:06
12   2009-11-12:05:45:37

_________________Thank You

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