could anybody help

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

  1. 00vampire

    00vampire New Member

    Joined:
    Nov 7, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice