Jump in rank of a student after updating marks | C ++ implementation of the approach ; Function to print the name of student who stood first after updation in rank ; Array of students ; Store the name of the student ; Update the marks of the student ; Store the current rank of the student ; Print the name and jump in rank ; Driver code ; Names of the students ; Marks of the students ; Updates that are to be done ; Number of students
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Student { string name ; int marks = 0 ; int prev_rank = 0 ; } ; void nameRank ( string names [ ] , int marks [ ] , int updates [ ] , int n ) { Student x [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] . name = names [ i ] ; x [ i ] . marks = marks [ i ] + updates [ i ] ; x [ i ] . prev_rank = i + 1 ; } Student highest = x [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { if ( x [ j ] . marks >= highest . marks ) highest = x [ j ] ; } cout << " Name : ▁ " << highest . name << " , ▁ Jump : ▁ " << abs ( highest . prev_rank - 1 ) << endl ; } int main ( ) { string names [ ] = { " sam " , " ram " , " geek " } ; int marks [ ] = { 80 , 79 , 75 } ; int updates [ ] = { 0 , 5 , -9 } ; int n = sizeof ( marks ) / sizeof ( marks [ 0 ] ) ; nameRank ( names , marks , updates , n ) ; }