1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#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;
}
friend ostream & operator<<(ostream & stream, Student &);
};
bool sortingMethod(const Student& credit1, const Student& credit2)
{
return credit1.getCredits() < credit2.getCredits();
}
ostream & operator<<(ostream & stream, Student & out)
{
stream << out.stuID << out.stuName << out.stuGender << out.stuDOB << out.stuMajor << out.stuCredits << out.stuGPA << endl;
return stream;
}
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=0; i < 4; i++)
{
cout << aStudents[i] << endl;
}
return 0;
}
|