Final answer:
To remove an Address object from the Postal Service's catalog, iterate through the vector using an iterator, check each Address object's zipcode, and remove the matching object using vector's erase method.
Step-by-step explanation:
You are looking to implement a member function in the Postal Service class that removes an Address object with a matching zipcode from a catalog. To achieve this, the function should iterate over the catalog of Address objects, checking each object's zipcode against the provided parameter. If a match is found, the Address object should be removed from the vector.
The following is a possible implementation of this function:
void PostalService::removeByZipcode(const std::string& targetZipcode) {
for (auto it = catalog.begin(); it != catalog.end(); ++it) {
if (it->getZip() == targetZipcode) {
catalog.erase(it);
return;
}
}
}
Notice that we iterate through the catalog using an iterator. We use the getZip member function of each Address object to compare with the target zip code. Once a matching zipcode is found, we use the erase method of vector to remove the element, and then we use return to exit the function.