#include <iostream>
#include<vector>
using namespace std;
class student
{
private:
string studentName;
double studentGpa;
int studentRank, studentYear;
public:
void setName(string name)
{
studentName = name;
}
void setGpa(double gpa)
{
studentGpa = gpa;
}
void setRank(int rank)
{
studentRank = rank;
}
void setYear(int year)
{
studentYear = year;
}
string getName() const
{
return studentName;
}
double getGpa() const
{
return studentGpa;
}
int getRank() const
{
return studentRank;
}
int getYear() const
{
return studentYear;
}
};
void fillVector(vector<student>&);
double getHighestGpa(const vector<student>&);
void printHighestGpa(const vector<student>&, const double& hiGpa);
int main()
{
vector<student> allStudents;
fillVector(allStudents);
double hiGpa = getHighestGpa(allStudents);
printHighestGpa(allStudents, hiGpa);
return 0;
}
void fillVector(vector<student> & newAllStudents)
{
string name;
double gpa;
int year, rank;
cout << "How many students are there: " << endl;
int numStudents;
cin >> numStudents;
for (int i = 0; i < numStudents; i++)
{
cout << "Enter student name: " << endl;
cin >> name;
cout << "Enter student GPA: " << endl;
cin >> gpa;
cout << "Enter student year: " << endl;
cin >> year;
cout << "Enter student rank: " << endl;
cin >> rank;
student newStudent;
newStudent.setName(name);
newStudent.setGpa(gpa);
newStudent.setYear(year);
newStudent.setRank(rank);
newAllStudents.push_back(newStudent);
}
}
double getHighestGpa(const vector<student>& newAllStudents)
{
unsigned int size = newAllStudents.size();
double highestGpa = 0;
for (unsigned int i = 0; i < size; i++)
{
if (newAllStudents[i].getGpa() > highestGpa)
{
highestGpa = newAllStudents[i].getGpa();
}
}
return highestGpa;
}
void printHighestGpa(const vector<student>& newAllStudents,
const double& hiGpa)
{
unsigned int size = newAllStudents.size();
double highestGpa = 0;
cout << "The student(s) who won the scholarship is/are: " << endl;
for (unsigned int i = 0; i < size; i++)
{
if (newAllStudents[i].getGpa() == hiGpa)
{
cout << "Student name: " << newAllStudents[i].getName() << endl;
cout << "Student GPA: " << hiGpa << endl;
cout << "Student year and rank: "
<< newAllStudents[i].getYear() << "("
<< newAllStudents[i].getRank() << ")"
<< endl << endl;
}
}
}