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

Question #157247

Display record of all the students greater than X marks in final exam (in ascending 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-21T04:25:48-0500
#include <iostream>
#include <bits/stdc++.h>
using namespace std;


struct student
{
    char name[50];
    float marks;
    int rank;
};
bool compare(student a, student b)
{
    if (a.marks != b.marks)
        return a.marks < b.marks; 
}

void computeRanks(student a[], int n)
{
    for (int i = 0; i < n; i++)
 
    sort(a, a + 5, compare);
 
    for (int i = 0; i < n; i++)
        a[i].rank = i + 1;
}
int main() 
{
    student s[10] = {{"Jake", 25},{"Dan",2},{"Rachel",90},{"Bea",70},{"Ram",45},{"Stec",66}}; /*List of students*/
    float marks;
    int arrSize = sizeof(s)/sizeof(s[0]);
    
    cout << "\nEnter marks to check: ";
    cin>>marks;
    computeRanks(s, arrSize);
    cout<< "Students With Marks Above "<<marks<<endl;
    for(int i = 0;i<arrSize;i++){
        if (s[i].marks>marks){ 
            cout<< s[i].name<<"    "<<s[i].marks<<endl;
        }
    }
    return 0;
}

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
New on Blog