#include<iostream.h>
#include<conio.h>
class student
{
private:
                int *rn,*tm,sz;
public:
                void stu(int size)
                {
                                sz=size;
                                rn=new int[size];
                                tm=new int[size];
                }
                void setdata();
                void sort();
                void display();
};
void student::setdata()
{
                int i=0;
                for(i=0;i<sz;i++)
                                {
                                cout<<"Enter Roll Number:- ";
                                cin>>rn[i];
                                cout<<"Enter Total Marks:- ";
                                cin>>tm[i];
                                }
}
void student::sort()
{
                int i,j,temp;
                for(i=0;i<sz-1;i++)
                                for(j=i+1;j<sz;j++)
                                                if(tm[i]<tm[j])
                                                                {
                                                                temp=rn[i];
                                                                rn[i]=rn[j];
                                                                rn[j]=temp;
                                                                temp=tm[i];
                                                                tm[i]=tm[j];
                                                                tm[j]=temp;
                                                                }
}
void student::display()
{
                for(int i=0;i<sz;i++)
                                {
                                cout<<"Roll No:- "<<rn[i]<<endl;
                                cout<<"Total Marks:- "<<tm[i]<<endl;
                                }
}
void main()
{
                int x;
                student s;
                clrscr();
                cout<<"Enter Size of Array:- ";
                cin>>x;
                s.stu(x);
                cout<<endl;
                s.setdata();
                s.sort();
                cout<<endl;
                s.display();
                getch();
}

 

Advertisements