Im pretty new to coding in C++ and Im a student at devry unversity. I have to sort this class by credit hours in ascending order and Im having some trouble. If anyone could help it would be greatly appreciated.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Student
{
private:
int id;
string name;
string lname;
char gender;
string dob;
string major;
int credits;
double gpa;
public:
int getcredits() const {
return credits;
}
Student();
void setStudent(int, string, string, char, string, string, int, double);
void getStudent();
};
Student::Student()
{ id=6984; name="John"; lname="Trovota"; gender='M'; dob="1/1/1980"; major="CIS"; credits=64; gpa=3.75; }
void Student::setStudent(int i, std::string n, std::string l, char g, std::string d, std::string m, int c, double p)
{ id=i; name=n; lname=l; gender=g; dob=d; major=m; credits=c; gpa=p; }
void Student::getStudent()
{ cout<<id<<" "<<name<<" "<<lname<<" "<<gender<<" "<<dob<<" "<<major<<" "<<credits<<" "<<gpa<<endl; }
bool cmp( const Student * a, const Student * b ) {
return a->getcredits() < b->getcredits() ;
}
int main()
{
vector <Student*> v;
sort( v.begin(), v.end(), cmp );
Student s1;
s1.getStudent();
Student s2;
s2.setStudent(2323, "Brittney", "Speer", 'F', "5/23/1984", "BIS", 78, 2.98 );
s2.getStudent();
Student s3;
s3.setStudent(1452, "Kathy", "Johnson", 'F', "12/25/1982", "CIS", 30, 3.33 );
s3.getStudent();
Student s4;
s4.setStudent(4321, "Bill", "Newton", 'M', "7/8/1976", "BIS", 100, 3.95 );
s4.getStudent();
system ("pause");
return 0;
}