using function prototype to sort array from a file containing 2 columns

Hi
I am trying to do a program that can sort array data from a file containing two columns.After sorting the data, the program should print the two sorted arrays to a single output file.
Sorting should occur in a function that has this prototype:
void sortTwoArraysBasedonFirst(double x[], double y[], int numPoints);
Also i had two prototypes below,which should be for input and output respectively.Such that the output should be called three times. The first time will be to display the unordered list to the screen. The second and third times will display the arrays to the screen and print them to the output file.

void readTwoArrays(double x[], double y[], int& numPoints, ifstream& fin);
void displayTwoArrays(double x[], double y[], int numPoints, ostream& fout);

So far i did the program but i could only display the data as it is in the file and know the number of rows of data.The code is as follows.Urgent please.

[
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>


using namespace std;
void sortTwoArraysBasedonFirst(double x[], double y[], int number_of_lines);
void readTwoArrays(double x[], double y[], int& number_of_lines, ifstream& fin);
void displayTwoArrays(double x[], double y[], int number_of_lines, ofstream& fout);

int number_of_lines=0;
int v;
int main()
{

ifstream fin;
fin.open("sensorRawData.txt");
ofstream fout;
fout.open("sensorRawData_out.txt");
string line;
double x[number_of_lines];
double y[number_of_lines];
readTwoArrays(x,y,number_of_lines,fin);
displayTwoArrays(x,y,number_of_lines,fout);



sortTwoArraysBasedonFirst( x, y, number_of_lines);

for( int i = 0; i < number_of_lines; i++)
{
for( int j = 0; j < number_of_lines; j++)
{
if(x[number_of_lines]>x[number_of_lines+1])


{
int temp = x[number_of_lines+1];
x[number_of_lines+1] = x[number_of_lines];
x[number_of_lines] = temp;


}
}
}


fin.close();
fout.close();
system("PAUSE");
return 0;
}
void readTwoArrays(double x[], double y[], int& number_of_lines, ifstream& fin)

{


string line;
int capacity=100;
while (fin.good ())
{
if (number_of_lines<capacity)
{

getline(fin, line);
cout << line << endl;

++number_of_lines;
}
}

cout << "Number of lines is "<<number_of_lines<< endl;
}

void displayTwoArrays(double x[], double y[], int number_of_lines, ofstream& fout)

{

int v;
fout.open("sensorRawData_out.txt");
fout<<x[v]<<setw(10)<<y[v]<<endl;
cout<<x[v]<<" "<<y[v]<<endl;

}

void sortTwoArraysBasedonFirst(double x[], double y[], int number_of_lines)
{

for( int i = 0; i < number_of_lines; i++)
{
for( int j = 0; j < number_of_lines; j++)
{
if(x[number_of_lines]>x[number_of_lines+1])


{
int temp = x[number_of_lines+1];
x[number_of_lines+1] = x[number_of_lines];
x[number_of_lines] = temp;


}

if(y[number_of_lines]>y[number_of_lines+1])


{
int temp = y[number_of_lines+1];
y[number_of_lines+1] = y[number_of_lines];
y[number_of_lines] = temp;


}
}
}

}


]
Last edited on
Before anything else make sure everything is in [Code] tags so it is readable.
James2250 can you please tell me how ,am just new in the forum so i don't know much how to put it in code tags.I just include [ ] ,but don't know if its what you talking about
Last edited on
Topic archived. No new replies allowed.