The class should also have a function named compareTo which compares the Employee object to an Employee object passed to it and returns 0 if they are equal, <0 if the current object is less than the passed object, and >0 if the current object is greater than the passed object. Use the strcmp function to compare the strings. The comparison should compare last names first, then first names (if the last names are equal), and finally ID# (if both names are equal).
class Record {
public:
int id;
char fname[20];
char lname[20];
int compareTo(const Record& r) const { //2nd const wont change member variables
int ln = strcmp(lname, r.lname);
int fn = strcmp(fname, r.fname);
if (ln == 0)
if (fn == 0)
if (ln <0)
if (ln >0)
return 0;
}
};
My question is am I using the strcmp correctly, for when it comes to comparing the lnames to each other? I know it is not complete, but I want to know if I am at least on the correct track or not.
All I want is a yes or no.