Students with maximum average score of three subjects | C ++ program to find the list of students having maximum average score ; Function to find the list of students having maximum average score Driver code ; Variables to store average score of a student and maximum average score ; List to store names of students having maximum average score ; Traversing the file data ; finding average score of a student ; Clear the list and add name of student having current maximum average score in the list ; Printing the maximum average score and names of students having this maximum average score as per the order in the file . ; Driver code ; Number of elements in string array
#include <bits/stdc++.h> NEW_LINE using namespace std ; void getStudentsList ( string file [ ] , int n ) { int avgScore ; int maxAvgScore = INT_MIN ; vector < string > names ; for ( int i = 0 ; i < n ; i += 4 ) { avgScore = ( stoi ( file [ i + 1 ] ) + stoi ( file [ i + 2 ] ) + stoi ( file [ i + 3 ] ) ) / 3 ; if ( avgScore > maxAvgScore ) { maxAvgScore = avgScore ; names . clear ( ) ; names . push_back ( file [ i ] ) ; } else if ( avgScore == maxAvgScore ) names . push_back ( file [ i ] ) ; } for ( int i = 0 ; i < names . size ( ) ; i ++ ) { cout << names [ i ] + " ▁ " ; } cout << maxAvgScore ; } int main ( ) { string file [ ] = { " Shrikanth " , "20" , "30" , "10" , " Ram " , "100" , "50" , "10" } ; int n = sizeof ( file ) / sizeof ( file [ 0 ] ) ; getStudentsList ( file , n ) ; }