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.
#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;
}
Comments
Leave a comment