Display record of all the students greater than X marks in final exam (in descending order with respect to marks obtained in final exam). The value of X will be entered by the user.
Here is answer to your question, if you need to fix something, just write me.
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<string, int>& a,
pair<string, int>& b)
{
return a.second < b.second;
}
int main(){
vector<pair<string, int>> Students;
int n;
cout << "Input number of students: ";
cin >> n;
cout << "Input students Surnames and Test Results (format: <Surname> <Result>)\n";
for(int i = 0; i < n; i++)
{
pair<string, int> temp;
cin >> temp.first >> temp.second;
Students.push_back(temp);
}
int X;
cout << "Input X: ";
cin >> X;
std::sort(Students.begin(), Students.end(), cmp);
for(int i = 0; i < n; i++)
{
if(Students[i].second > X)
cout << Students[i].first << ' ' << Students[i].second << '\n';
}
}
Comments
Leave a comment