1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

could anybody help

Discussion in 'C' started by 00vampire, Nov 7, 2007.

  1. 00vampire

    00vampire New Member

    hello everybody ,,
    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;
    }
    
    and tanx :)
     
    Last edited by a moderator: Nov 8, 2007

Share This Page