Custom compare class

If marks of two student is equal give priority to Roll or Math marks or Biology marks we have to tell it to computer .

include

using namespace std;
class Student{
public:
string name ;
int roll ;
int marks ;
Student(st…


This content originally appeared on DEV Community and was authored by Mujahida Joynab

If marks of two student is equal give priority to Roll or Math marks or Biology marks we have to tell it to computer .

include

using namespace std;
class Student{
public:
string name ;
int roll ;
int marks ;
Student(string name , int roll , int marks){
this->name = name ;
this->roll =roll ;
this->marks = marks ;
}
};

class cmp{
public:
bool operator()(Student l , Student r )
{
if(l.marks < r.marks)
return true ;
else
return false ;

}

};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
priority_queue,cmp> pq;
int n ;
cin >> n ;
for(int i = 0 ; i < n ; i++){
string name ;
int roll , marks ;
cin >> name >> roll >> marks ;
Student obj(name,roll , marks) ;
pq.push(obj) ;
}

while(!pq.empty()){
cout << pq.top().name << " " << pq.top().roll << " " << pq.top().marks() << endl ;

}
return 0 ;

}


This content originally appeared on DEV Community and was authored by Mujahida Joynab


Print Share Comment Cite Upload Translate Updates
APA

Mujahida Joynab | Sciencx (2025-02-23T14:17:47+00:00) Custom compare class. Retrieved from https://www.scien.cx/2025/02/23/custom-compare-class/

MLA
" » Custom compare class." Mujahida Joynab | Sciencx - Sunday February 23, 2025, https://www.scien.cx/2025/02/23/custom-compare-class/
HARVARD
Mujahida Joynab | Sciencx Sunday February 23, 2025 » Custom compare class., viewed ,<https://www.scien.cx/2025/02/23/custom-compare-class/>
VANCOUVER
Mujahida Joynab | Sciencx - » Custom compare class. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/23/custom-compare-class/
CHICAGO
" » Custom compare class." Mujahida Joynab | Sciencx - Accessed . https://www.scien.cx/2025/02/23/custom-compare-class/
IEEE
" » Custom compare class." Mujahida Joynab | Sciencx [Online]. Available: https://www.scien.cx/2025/02/23/custom-compare-class/. [Accessed: ]
rf:citation
» Custom compare class | Mujahida Joynab | Sciencx | https://www.scien.cx/2025/02/23/custom-compare-class/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.