Question: #ifndef CONTACTBOOK _ H #define CONTACTBOOK _ H #include #include #include #include class Contact { public: / / Parameterized Constructor Contact ( const std::string& name,

#ifndef CONTACTBOOK_H
#define CONTACTBOOK_H
#include
#include
#include
#include
class Contact {
public:
// Parameterized Constructor
Contact(const std::string& name, const std::string& number)
: name(name), number(number){}
// 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 MAX_SIZE =100;
// Default Constructor
ContactBook()= default;
// Add a single contact
void Add(const Contact& contact){
if (contacts.size()< MAX_SIZE){
contacts.push_back(contact);
}
}
// Remove a contact
void Remove(const Contact& contact){
contacts.erase(std::remove_if(contacts.begin(), contacts.end(),
[&contact](const Contact& c){
return c.getName()== contact.getName()||
c.getNumber()== 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* Find(const std::string& identifier){
for (auto& contact : contacts){
if (contact.getName()== 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::sort(contacts.begin(), contacts.end(),[](const Contact& a, const Contact& b){
return a.getName()< b.getName();
});
}
private:
std::vector contacts; // Use vector to manage contacts
};
#endif // CONTACTBOOK_H

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!