Click on prof.h to get source.
// File: C++Examples/Lists/prof.h
#ifndef __prof
#define __prof
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <iterator>
using namespace std; // is default but should be referred explicity
class PROF {
private:
basic_string<char> lname;
// concept demo'd: basic_string<T> template class
// avoid the use of char[] altogether
basic_string<char> fname;
char MI;
double salary;
int rank;
float TPA; // ``teaching point average''
public:
/* needed if explictly instantiating list<PROF> */
PROF(void) { }
/* */
PROF(const basic_string<char>& LN,
const basic_string<char>& FN,
const char M, const double S, int R, float T)
: lname(LN), fname(FN), MI(M), salary(S), rank(R), TPA(T) {}
// constructor initializes fields
bool operator<(const PROF& professor) const
{return lname < professor.lname; }
// needed in STL lower_bound algo
bool operator==(const PROF& professor) const // needed in hire
{return lname == professor.lname; }
class comp_w_lastname {
// needed by find_if in fire
// concepts demo'd: predicate object, encapsulated class
basic_string<char> last_name;
public:
comp_w_lastname(const basic_string<char>& name)
: last_name(name) {}
bool operator()(const PROF& professor) const
{return professor.lname >= last_name;}
}; // end class comp_w_lastname
// friend class PROF::comp_w_lastname; // accesses lname
friend ostream& operator<<(ostream&, const PROF&);// accesses lname,fname
friend class PROFLIST; // needed in fire
}; // end class PROF
class PROFLIST : std::list<PROF> {
// note: PROFLISTCELL is internal to list<PROF>, STL's list container
// concept demo'd: STL list container
// note: as the code for hire/fire is generic, you can use other containers:
// vector, set (you must change lower_bound in hire to a member fun),...
public:
// concept demo'd: adaption of base class functionality.
// hire and fire have special purpose interfaces
int fire(const basic_string<char>&);
int hire(const PROF&);
friend ostream& operator<<(ostream&, const PROFLIST&);
}; // end class PROFLIST
#endif