Title Sorting of a structure data. Author: Faseeh Visitor Submitted Source Code Author Email: master_02@hotmail.com Description: You see in this program that you can sort the data of structure type array. This sorting is to be done with out using built in sorting function................ Hits: 3487 Since 25th November, 2003 Code: Select and Copy the Code #include<iostream.h> #include<conio.h> #include<stdio.h> #include<iomanip.h> struct rec {char name[50]; int r_no; int p_no; double gpa; int sem; char lo_full; char ba; }; void main() {rec d[10]; int a,b[10],s_no,hold1,hold2,hold3,hold5; char hold6[50],get; double hold4; cout<<"Enter the total no of students : "; cin>>s_no; for(a=0;a<s_no;a++) { cout<<"\n***************************************************************** ***************\n"; cout<<" Enter the Name : "; cin>>d[a].name; cout<<"\n\n\n\n\n\n\n\n\n\n"; cout<<" ------------------------------------------------------------------ ---------------"; cout<<"\n| Entering data of "<<d[a].name<<" |"; cout<<"\n ---------------------------------------------------------------- -----------------"; cout<<" Enter the Registration No : "; cin>>d[a].r_no; cout<<" Enter the Phone No : "; cin>>d[a].p_no; cout<<" Enter the Semister No : "; cin>>d[a].sem; cout<<" Enter the Batch No : "; cin>>d[a].ba; cout<<" Enter the G.P.A : "; cin>>d[a].gpa; if(d[a].sem>1) {cout<<"May the student is with full load : "; cin>>d[a].lo_full; } } for(int p=0;p<s_no-1;p++) for(int j=0;j<s_no-1;j++) if(d[j].r_no>d[j+1].r_no) {hold1=d[j].r_no; d[j].r_no=d[j+1].r_no; d[j+1].r_no=hold1; hold2=d[j].p_no; d[j].p_no=d[j+1].p_no; d[j+1].p_no=hold2; hold3=d[j].ba; d[j].ba=d[j+1].ba; d[j+1].ba=hold3; hold4=d[j].gpa; d[j].gpa=d[j+1].gpa; d[j+1].gpa=hold4; hold5=d[j].lo_full; d[j].lo_full=d[j+1].lo_full; d[j+1].lo_full=hold5; for(a=0;a[d].name[50]!='\0';a++) { hold6[a]=d[j].name[a]; d[j].name[a]=d[j+1].name[a]; d[j+1].name[a]=hold6[a]; } } for(a=0;a<s_no;a++) { cout<<"Result of "<<d[a].name; cout<<"\nRegistration No"<<d[a].r_no; cout<<"\nPhone No"<<d[a].p_no; cout<<"\nSemister"<<d[a].sem; cout<<"\nBatch No"<<d[a].ba; cout<<"\nGPA"<<d[a].gpa; cout<<"\nFull Load : "<<d[a].lo_full; cout<<"\nName : "<<d[a].name<<"\t"; cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\npress any key to continue:"; cin>>get; getch(); } }