Question: #ifndef CONTACTBOOK _ H #define CONTACTBOOK _ H #include #include #include #include class Contact { public: / / Parameterized Constructor Contact ( const std::string& name,
#ifndef CONTACTBOOKH
#define CONTACTBOOKH
#include
#include
#include
#include
class Contact
public:
Parameterized Constructor
Contactconst std::string& name, const std::string& number
: namename numbernumber
Getters
std::string getName const return name;
std::string getNumber const return number;
Display method
void Display const
std::cout name number std::endl;
private:
std::string name;
std::string number;
;
class ContactBook
public:
static const int MAXSIZE ;
Default Constructor
ContactBook default;
Add a single contact
void Addconst Contact& contact
if contactssize MAXSIZE
contacts.pushbackcontact;
Remove a contact
void Removeconst Contact& contact
contacts.erasestd::removeifcontactsbegin contacts.end
&contactconst Contact& c
return cgetName contact.getName
cgetNumber contact.getNumber;
contacts.end;
Display all contacts
void Display const
for const auto& contact : contacts
contact.Display;
Find a contact by name or number
Contact Findconst std::string& identifier
for auto& contact : contacts
if contactgetName identifier
contact.getNumber identifier
return &contact; Return pointer to the found contact
return nullptr; Return nullptr only after checking all contacts
Alphabetize contacts
void Alphabetize
std::sortcontactsbegin contacts.endconst Contact& a const Contact& b
return agetName bgetName;
;
private:
std::vector contacts; Use vector to manage contacts
;
#endif CONTACTBOOKH
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
