Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how can ı sort a student list from a text file like StudentList.txt according to students' surname and id number.can ypu help me?
Posted

Do it in this way.. Read the file using File I/O Strems and then when you display the student information on screan you sort it.. For it you need to read the file into two string variables for this you have to use read method that reads only till a space or end of line occurs and then in a for loop or while loop read the file save the the first line into the first variable and second line in second variable. compare the values using stringcompartion method then save it into an array in sorted way. then You display the whole array. Its Like Sorting tecnique(Buble sort etc)...
You better Sort by Student ID. It is the perfect way.
 
Share this answer
 
v5
Actualy i am an c#.net Student but i too had the same doubt i have asked my faculty they gave me the sample in c#.
 
Share this answer
 
This'll hand the id number as it, then adapt it to use the ascii value of the surname array.

<<integer array="" sort="">>=
static void bubble_sort( int[] array )
{
long right_border = array.Length - 1;

do
{
long last_exchange = 0;

for (long i = 0; i < right_border; i++)
{
if (array[i] > array[i + 1])
{
int temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;

last_exchange = i;
}
}

right_border = last_exchange;
}
while (right_border > 0);
}
 
Share this answer
 
hi oakman firstly thank you for your answer but ı cannot do take list of students from file..other parts are difficult for me but i think if ı try ı can do but dont now how ı can take from file the list...
 
Share this answer
 
The most logical way to do this, is to create a student class, read your students into it ( with the iostream extension code I linked to for you ), and then write a function object that sorts however you like, so you can create a vector of students and use the STL:sort methods on it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900