I'm towards the end of my problem. I just need assistance when comparing classes. I'm trying to compare the two Grade point averages, and whoever has the highest, I would like to be announced or displayed. Any help or hint is appreciated...

#include<string>
#include<iostream>

using namespace std;
//class of type Student
class Student
{
      private:
       int Id;
       string LastName;
       double GradePoint;
       
       
       
public:
       void displayStudentData();
       void setId(int);
       void setLastName(string);
       void setGradePoint(double);
       
};
//initialize the class of type Student
void Student::displayStudentData()
{ 
     cout << "Student's id# is " << Id << " \n";
     cout << "last name is " << LastName<< " \n";
     cout<< "The grade point average for this student is " <<GradePoint << " \n";
     
}

void Student::setId(int num)
{
     const int Max_Num = 9999;
     if(num <= Max_Num)
            Id = num;
     else
            Id = Max_Num;
}

void Student::setLastName(string name)
{
     LastName = name;
}

void Student::setGradePoint(double gpa)
{
     const double Max_Gpa = 4.0;
     if(gpa <= Max_Gpa)
            GradePoint = gpa;
     else
            GradePoint = 0;
}



     

int main()
{
    Student xStudent;
    
    xStudent.setLastName("Johnson");
    xStudent.setId(1981);
    xStudent.setGradePoint(3.9);
    xStudent.displayStudentData();
    
    Student yStudent;
    
    yStudent.setLastName("Williams");
    yStudent.setId(3000);
    yStudent.setGradePoint(2.5);
    yStudent.displayStudentData();

    
   
   if(xStudent.GradePoint() > yStudent.GradePoint())
   {
   cout << "Johnson has higher gpa " << endl;
   else
   cout << "Williams has higher gpa " << endl;
}
    
    
    
    
   
system("PAUSE");
    return EXIT_SUCCESS;
    
}

line 77: your class does not have a GradePoint() method. You need to add that.

If you have learned about overloaded operators yet you could also do it by overloading the > operator so that you can do this: if( xStudent > yStudent )

Please post your resolution as I am very interested in how you resolved the compairson of the two students

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.