I've created my code in Microsoft Visual Studio Express 2013 and it compiles and runs fine. I've moved this over to Linux and had compile errors. To fix it, I had to add in #include <cstring> on my student.h file and it compiles fine. However now it does not give me the correct input. Is there a difference between the strcmp and strncpy in Linux? Or am I missing a step to make it work on Linux?
#include "student.h"
//implement the required 3 functions here
Student::Student(constchar initId[], double gpa) : gpa(gpa)
{
// initialize a newly created student object with the passed in value
strncpy_s(id, initId, Student::MAX_CHAR - 1);
id[Student::MAX_CHAR - 1] = '\0';
}
bool Student::isLessThanByID(const Student& aStudent) const
{
// compare the current student object with the passed in one by id.
if (strcmp(id, aStudent.id) > 0)
{
returntrue;
}
else
{
returnfalse;
}
}
bool Student::isLessThanByGpa(const Student& aStudent) const
{
// compare the current student object with the passed in one by gpa
if (gpa < aStudent.gpa)
{
returntrue;
}
else
{
returnfalse;
}
}
void Student::print() const
{
cout << id << '\t' << gpa << endl;
}
This seems like a good question but in order to get better feedback you should move this file to the LINUX/UNIX questions instead of the beginners questions that way you and others can get help