iam new in this forum and new in C++
so iam starting with problem here if anyone could help
i have file which is contain of name, ID ,Marks and i want to sort it ascending by the Marks
so i dont know how to move the names and Ids when i move the move the marks so could anybody help
""i think maybe if i use another array and use it as index or sth like this but i couldnt figure it out""
and this is my code
Code:
#include <iostream.h>
#include <fstream.h>
struct sort
{
char names [20];
long ids;
int marks;
}result;
main()
{
int temp;
sort nafek [5],index[5];
fstream file;
file.open("data.dat",ios::in);
for (int i=0;i<3;i++)
{
file>>nafek [i].ids>>nafek[i].marks>>nafek[i].names;
}
for (i=0;i<3;i++)
{
for (int j=i+1;j<=3;j++)
{
if (nafek[j].marks<nafek[i].marks)
{
temp=nafek[i].marks;
nafek[i].marks=nafek[j].marks;
nafek[j].marks=temp;
}}
}
for (i=0;i<3;i++)
{
cout<<nafek[i].marks<<" "<< nafek[i].names<<nafek[i].ids<<'/n';
file.close();
}
return 0;
}
