954,170 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

fin troubles

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

}

toadie2004
Newbie Poster
2 posts since Nov 2004
Reputation Points: 10
Solved Threads: 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.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Oh, how about

fin >> some_array[whatever_index];

I think you can fill in the right names.

jasweb2002
Junior Poster in Training
56 posts since Sep 2004
Reputation Points: 11
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You