Answered! struct StudentInfo {      string name;      int grade;      //need to overload the > operator here }…

struct StudentInfo
{
string name;
int grade;

//need to overload the > operator here
}

Use the following StudentInfo structure type to store student record: name and grade.

In a function named populateStudentRecord(), use a list data structure to populate the student data. Make up the data by yourself using some constant name and grade values in the function (do not ask the user to provide data).

In the main() function:

Create a list of objects of StudentInfo type.

Call the populateStudentRecord() to populate the list object.

Use the built-in sort algorithm from STL to sort the list by name and display the information in this format “name – grade”. Remember, you need to overload the < operator for the structure so that the StudentInfo structure type variables can be compared.

Calculate the maximum and minimum grades and the class average and display them.

Expert Answer

#include “stdafx.h”
#include<iostream>
#include<list>
#include<algorithm>
#include<string>
using namespace std;
struct StudentInfo
{
string name;
int grade;
//need to overload the > operator here
friend bool operator > (StudentInfo &s1, StudentInfo &s2) {
return s1.name>s2.name;
}
friend bool operator<(StudentInfo &s1, StudentInfo &s2) {
return s1.name<s2.name;
}
};

void populateStudentRecord(list<StudentInfo > &array) {
StudentInfo S = { “tAmos”,94 };
array.push_back(S);
S.name = “tBecca”; S.grade = 87;
array.push_back(S);
S.name = “tAdalynn”; S.grade = 79;
array.push_back(S);
S.name = “tOlivia”; S.grade = 88;
array.push_back(S);
S.name = “tSierra”; S.grade = 84;
array.push_back(S);
}
// In the main() function:
int main() {
// Create a list of objects of StudentInfo type.
cout << “nt—————————–” << endl;
cout << “ttStudent Info” << endl;
cout << “t—————————–” << endl;
list<StudentInfo> array;
// Call the populateStudentRecord() to populate the list object.
populateStudentRecord(array);
// Use the built-in sort algorithm from STL to sort the list by name and display the information in this format “name – grade”. Remember, you need to overload the < operator for the structure so that the StudentInfo structure type variables can be compared.
array.sort();
// Calculate the maximum and minimum grades and the class average and display them.
list<StudentInfo>::iterator it = array.begin();
int max = (*it).grade;
int min = (*it).grade;
double sum = 0;
int count = 0;
for (it = array.begin(); it != array.end(); it++) {
cout << (*it).name << ” – ” << (*it).grade << endl;
if ((*it).grade > max) max = (*it).grade;
else if ((*it).grade < min) min = (*it).grade;
sum += (*it).grade;
count++;
}
cout << “ntMaximum grade is ” << max << endl;
cout << “tMinimum grade is ” << min << endl;
cout << “tAverage is ” << (sum / count) << endl;
cout <<“t=============================n”<< endl;

system(“pause”);
return 0;
}

Still stressed from student homework?
Get quality assistance from academic writers!