I am doing this assignment for my C++ class, and we have to instantiate 4 objects of the Student class, set the data members and then sort them according to the GPA variable. Ive whittled down the errors to just one, and I am stumped. Here is the error:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Student' (or there is no acceptable conversion)
It happens in the for-loop at the end of main... anyone please help?
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class Student
{
private:
int stuID;
string stuName;
char stuGender;
string stuDOB;
string stuMajor;
int stuCredits;
double stuGPA;
public:
void setStudent(int i, string n, char g, string d, string m, int c, double p)
{
stuID = i;
stuName = n;
stuGender = g;
stuDOB = d;
stuMajor = m;
stuCredits = c;
stuGPA = p;
}
int getCredits() const
{
return stuCredits;
}
void getStudent()
{
}
};
bool sortingMethod(const Student& credit1, const Student& credit2)
{
return credit1.getCredits() < credit2.getCredits();
}
int main()
{
Student s1, s2, s3, s4;
Student aStudents[4] = {s1, s2, s3, s4};
s1.setStudent(6984, "John Trovota", 'M', "1/1/1980", "CIS", 64, 3.75);
s2.setStudent(2323, "Britney Speer", 'F', "5/23/1984", "BIS", 78, 2.98);
s3.setStudent(1452, "Kathy Johnson", 'F', "12/25/1982", "CIS", 30, 3.33);
s4.setStudent(4321, "Bill Newton", 'M', "7/8/1976", "BIS", 100, 3.95);
sort(aStudents, aStudents + 4, sortingMethod);
for(int i; i < 4; i++)
{
cout << aStudents[i] << endl;
}
return 0;
}