i have made a program with a vector that is a instance of a class student with three variables. i have stored the information and calculated the class average. what I want to do is get the person with the highest test score and output "this student has the highest score with". This is where im lost and need some help to go in the right direction.
here is my code
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Student {
public:
virtual void print();
Student(string,string,double);
Student();
virtual ~Student();
double score;
protected:
string firstName;
string lastName;
//double score;
};
void Student::print() {
std::cout<<firstName<<" "<<lastName<<" "<<score<<std::endl;
}
Student::Student(string first,string last,double x) {
firstName = first;
lastName = last;
score = x;
}
Student::~Student() {
firstName = "";
lastName = "";
score = 0;
}
int main() {
vector <Student*> list;
double average;
double total;
list.push_back(new Student("Louis","Radske",90));
list.push_back(new Student("Bill","Collins",88));
list.push_back(new Student("Ted","Blood",78));
list.push_back(new Student("Tim","Sails",98));
list.push_back(new Student("Ed","Goodson",85));
for(int z=0;z<list.size();z++)
{
total+=list[z]->score;
}
average = total/list.size();
std::cout<<"The class average is "<<average<<std::endl;
//std::cout<<"MAX " << *max_element(list.begin(),list.end())<<std::endl;
for(int x=0;x<list.size();x++)
{
list[x]->print();
}
//list.front()->print();
return(0);
}
thanks.