This is my project:
Read the data one line at a time and store them in two different arrays.
Pass the first array to a function that sorts the array in ascending
order using selection sort.
Pass the second array to a function that sorts the array in descending
order using selection sort.
(Use your functions from the previous assignment to sort.)
Print each array before and after sorting.
my main problem is that im having much trouble reading the numbers from the .dat file and storing them in an array, any help you could give me would be great...thanks
void ascendingsort(int list[], int length)
{
int index, smallestindex, minindex, temp;
for (index = 0; index < length - 1; index++)
{
smallestindex = index;
for (minindex = index + 1;minindex < length; minindex++)
if (list[minindex] < list[smallindex])
smallestindex = minindex;
temp = list[smallestindex];
list[smallestindex] = list[index];
list[index] = temp;
}
}
void descendingsort(int list[], int length)
{
int index, smallestindex, minindex, temp;
for (index = 0; index < length - 1; index++)
{
smallestindex = index;
for (minindex = index + 1;minindex < length; minindex++)
if (list[minindex] > list[smallindex])
smallestindex = minindex;
temp = list[smallestindex];
list[smallestindex] = list[index];
list[index] = temp;
}
}
int main()
{
double num1, num2, num3;
ifstream fin;
ofstream fout;
fin.open("scores.dat");
fout.open("results", ios::trunc);
}