Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* File: animalshelter.cpp
- * Course: CS216-005
- * Project: Lab 11
- * Purpose: AnimalShelter
- */
- #include "animalshelter.h"
- // add a new dog breed in the animal shelter
- // if the key (breed) exists, add the set of dognames to the values of the breed
- // otherwise add the key and the set of dognames to the map
- // breed is the new dog breed
- // dognames are the set of dog names of the breed
- void AnimalShelter::insert(string breed, set<string> dognames)
- {
- map<string, set<string> >::iterator i = BreedToNames.find(breed);
- if (i != BreedToNames.end()) {
- i->second.insert(dognames.begin(), dognames.end());
- }
- else
- BreedToNames.insert(make_pair(breed, dognames));
- }
- // person: the name of the person who wants to adopt a dog of breed
- // breed: the breed of the dog a person whats to adopt
- // if such breed exists, display the message: person is adopting <a dog's name> (breed)
- // and then delete the dog from the map
- // otherwise, display the message: person CANNOT adopt a breed.
- void AnimalShelter::validAdoption(string person, string breed)
- {
- if (BreedToNames.find(breed) != BreedToNames.end()) {
- cout << person << " is currently adopting " << *BreedToNames[breed].begin() << "a " << breed << endl;
- BreedToNames[breed].erase(BreedToNames[breed].begin());
- if (BreedToNames[breed].empty())
- BreedToNames.erase(breed);
- }
- else
- cout << person << " CANNOT adopt a that breed of dog, it doesn't exist" << endl;
- }
- // check if the animal shelter is empty
- // return true if it is
- // otherwise return false
- bool AnimalShelter::empty() const
- {
- if (BreedToNames.empty())
- return true;
- else
- return false;
- }
- // display all the animals currently in the shelter like this:
- // breed: [ dog_name1 dog_name2 ... ]
- void AnimalShelter::print() const
- {
- if (!(empty()))
- for (map<string, set<string> >::const_iterator i = BreedToNames.begin(); i != BreedToNames.end(); i++) {
- cout << i->first << " [";
- for (set<string>::const_iterator x = i->second.begin(); x != i->second.end(); x++) {
- cout << " " << *x;
- }
- cout << " ]" << endl;
- }
- else
- cout << "Sorry, there is currently no animal is in the shelter!" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement