Answer to Question #155913 in C++ for Abdul Rehman

Question #155913

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.


1
Expert's answer
2021-01-15T08:25:59-0500

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';
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS