MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Thursday, May 2, 2013

sort using class of c++ program

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
class node
{
    public:
    string name;
    int age;
    int roll;
    float marks;
};
bool com(const node as,const node k)
{
    if(as.name<k.name)
    return true;
    if((as.name<k.name)||(as.age<k.age))
    return true;
    if(as.marks>k.marks)
    return true;
}
int main()
{
    int n;
    string s;
    int a;
    int r;
    double m;
    node g;
    while(cin>>n)
    {
        vector<node>v;
        for(int i=0;i<n;i++)
        {
        cin>>s;
        cin>>a;
        cin>>r;
        cin>>m;
        g={s,a,r,m};
        v.push_back(g);
        }
    sort(v.begin(),v.end(),com);
    for(int i=0;i<v.size();i++)
    cout<<v[i].name<<" "<<v[i].age<<" "<<v[i].roll<<" "<<v[i].marks<<endl;
    }
    return 0;
}

No comments:

Post a Comment