1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <fstream>
void output_to_file(std::ofstream &, double [], int [], size_t );
int main ()
{
std::ifstream infile ("input.txt");
std::ofstream outfile ("output.txt");
double number;
double data[15]{0};
int format[]{0,3,6,7,8, 1,4,9,10,11, 2,5,12,13,14};
size_t length = sizeof(format)/sizeof(int);
int count = 0;
int index = 0;
if (infile.is_open() && outfile.is_open())
{
while (infile >> number)
{
index = count % length;
data[index] = number;
count++;
if(count % length == 0)
{
output_to_file(outfile, data, format, length);
}
}
infile.close();
outfile.close();
}
else std::cout << "Unable to open file(s)";
return 0;
}
void output_to_file(std::ofstream &anOutFile, double anArray[], int aFormat[], size_t aLimit)
{
int count = 0;
for (size_t index = 0; index < aLimit; index++)
{
anOutFile << anArray[ aFormat[index] ] << ' ';
count ++;
if(count % 5 == 0)
anOutFile << '\n';
}
}
|