i need to sort these arrays after they've read the input file. in that file (i'll post it at the bottom) the first column of numbers needs to be sorted numerically, ascending. (and all the rows need to kept together as well) i know i need to use a temporary variable to pass information from one array to another, but i don't know what to do with multiple arrays and mulitple columns and rows of data. i figure i would need to use a for loop in the process, possibly two... but really i'm quite confused about how to do this. i've got the basic function in there but i don't know what to do.
Code:
#include <iomanip>
#include <iostream>
#include <fstream>
#include <ctype.h>
using namespace std;
const int LENGTH = 30;
int family[LENGTH];
int item[LENGTH];
int quantity[LENGTH];
double price[LENGTH];
int buildArrays (int family[], int item[], int quantity[], double price[])
{
double num;
ifstream inFile;
inFile.open( "data7.txt" );
if( inFile.fail() )
{
cout << "text failed to open";
exit( -1 );
};
int i=0;
while (inFile)
{
inFile>>num;
family[i]=num;
inFile>>num;
item[i]=num;
inFile>>num;
quantity[i]=num;
inFile>>num;
price[i]=num;
i++;
}
inFile.close();
return (i);
}
void printArrays (int family[], int item[], int quantity [], double price[])
{
cout<<"Annual Garage Sale";
cout<<"\nFamily Item Id # Sale Price Quantity Sold Sale Amount";
cout<<"\n-------------------------------------------------------------------";
int i;
for(i=0;i<30;i++)
{
family[i];
item[i];
price[i];
quantity[i];
cout<<"\n"<<family[i]<<" "<<item[i]<<" "<<price[i]<<" "<<quantity[i]<<" ";
};
}
void sortarrays(int family[], int item[], int quantity [], double price[])
{
}
int main()
{
buildArrays(family, item, quantity, price);
printArrays(family, item, quantity, price);
return 0;
}
this is the text file
Code:
3 12345 1 15.95
2 67800 3 50.00
4 32145 2 4.50
6 98765 1 75.00
1 44496 2 11.30
0 67356 4 3.50
5 54862 1 52.50
4 14541 1 4.25
2 64488 2 1.00
0 34945 3 7.40
6 74322 1 6.50
1 39240 10 0.75
3 52525 15 1.00
0 60002 1 12.00
5 31579 2 2.50