Proszę zaimplementować klasy, których definicje przedstawiono na Listingach 1-3.
Listing 1 Definicja klasy Contact
class Contact {
public:
Contact (const char *name,const char *address, const char *tel);
~Contact (void);
const char* Name (void) const {return name;}
const char* Address (void) const {return address;}
const char* Tel (void) const {return tel;}
friend ostream& operator << (ostream&, Contact&);
private:
char *name; // contact name
char *address; // contact address
char *tel; // contact telephone number
};
Listing 2 Definicja klasy ContactDir
class ContactDir {
public:
ContactDir (const int maxSize);
~ContactDir(void);
void Insert (const Contact&);
void Delete (const char *name);
Contact* Find (const char *name);
friend ostream& operator << (ostream&, ContactDir&);
private:
int Lookup (const char *name); // returns index i such that contacts[i]->Name equals name
Contact **contacts; // list of contacts
int dirSize; // current directory size
int maxSize; // max directory size
};
Listing 3 Definicja klasy SmartDir, pochodnej klasy ContactDir
class SmartDir : public ContactDir {
public:
SmartDir(const int max) : ContactDir(max) {recent = 0;}
Contact* Recent (void);
Contact* Find (const char *name);
private:
char *recent; // the most recently looked-up name
};
Metoda SmartDir::Find jest reimplementacją ContactDir::Find, która, oprócz znalezienia obiektu klasy Contact, którego pole Name ma wartość name, ustawia wartość pola recent.