0

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);

}

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
4
Views
12 Years
Discussion Span
Last Post by jasweb2002
0

so what have you actually done to read the data?
You've declared the file, but that doesn't read the data...

Show some initiative first, try it yourself.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.