program代做、代写C++程序设计
- 首页 >> Python编程 Assignment 3 Pet Adoption Center Management System (PACMS)
Introduction
In this assignment, we will make use of the C++ concepts learned in the lectures:
binary search tree (BST)and hashing to create a database system to manage pets
for adoption. Using this system the user is be able to see the list of different pets
available for adoption, each with several attributes such as species, age, health
condition, vaccination status, special needs, etc. The user can sort and filter the
options based on different criteria, similar to lab 1 exercise.
Code overview
You are provided the following files in the skeleton code:
● adoptionCenter.h/.cpp
● animal.h/.cpp
● bst.h/.cpp
● datatypes.h/.cpp
● randomAnimalGenerator.h/.cpp
● main.cpp/main_test.cpp
This section will give a brief description of the classes, in the order you will need to
implement/use.
IMPORTANT: After reading the overview of classes, please refer to this example to
understand how the adoption center manages 4 different binary search trees at
once, as well as how the BSTs should handle different cases of element
insertion/deletion.
Data Types
The files datatypes.h and datatypes.cpp define data structures that provide a
comprehensive way to represent animal information in the adoption center system.
struct Species {
std::string name;
std::string breed;
};
struct HealthCondition {
std::string description;
unsigned int severity;
};
struct VaccinationStatus {
std::string vaccineHashTable[VACCINE_TABLE_SIZE];
unsigned int numVaccines;
VaccinationStatus();
void addVaccine(const std::string& v);
bool hasVaccine(const std::string& v) const;
unsigned int getTotalHashValue() const;
};
These structures represent information about animal species, health conditions, and
vaccination status.
Structure: Species
● This structure defines a way to store information about an animal's species. It
has two members:
○ name: A string containing the animal's species name (e.g., "Cat",
"Dog").
○ breed: A string containing the animal's breed (e.g., "Siamese",
"Labrador Retriever"), or "N/A" if breed is not applicable.
Structure: HealthCondition
● This structure defines a way to represent an animal's health condition. It has
two members:
○ description: A string describing the animal's health condition (e.g.,
"Healthy", "Fair", "Poor").
○ severity: A value between 0 (no severity) and 1000 (most severe)
representing the severity of the health condition.
● A constant NORMAL_HEALTH is defined with a description of "Healthy" and a
severity of 0, used as a default health condition for animals.
Structure: VaccinationStatus
● This structure defines a way to manage an animal's vaccination records. It
has three members:
○ vaccineHashTable[VACCINE_TABLE_SIZE]: An array of strings
with a fixed size (VACCINE_TABLE_SIZE) to store vaccine names
using a hash table approach.
○ numVaccines: An unsigned integer variable keeping track of the
number of vaccines currently stored in the hash table.
● The structure has member functions for managing the hash table:
○ addVaccine(const std::string& v): Adds a new vaccine name
(v) to the vaccination records.
○ hasVaccine(const std::string& v) const: Checks if a
specific vaccine (v) is present in the vaccination records.
○ getTotalHashValue() const: Calculates a value representing the
vaccination record of this animal for comparison.
Animal
The files animal.h and animal.cpp define a class representing pets in the system,
allowing for detailed information storage and manipulation.
class Animal {
private:
unsigned int id;
Species species;
unsigned int age;
HealthCondition healthCondition;
VaccinationStatus vaccineStatus;
std::string specialNeeds;
public:
Animal(
unsigned int id, const Species& s, unsigned int a,
const HealthCondition& h = NORMAL_HEALTH,
const VaccinationStatus& v = VaccinationStatus(),
const std::string& n = ""
): id(id), species(s), age(a), healthCondition(h),
vaccineStatus(v), specialNeeds(n) {}
Animal(const Animal&) = delete;
Animal& operator=(const Animal&) = delete;
unsigned int getID() const { return id; }
std::string getSpecies() const { return species.name +
" (" + species.breed + ")"; }
unsigned int getAge() const { return age; }
const HealthCondition& getHealthCondition() const {
return healthCondition; }
const VaccinationStatus& getVaccinationStatus() const
{ return vaccineStatus; }
std::string getSpecialNeeds() const { return
specialNeeds; }
void incrementAge() { ++age; }
void setHealthCondition(const HealthCondition& h) {
healthCondition = h; }
void setSpecialNeeds(const std::string& n) {
specialNeeds = n; }
void addVaccine(const std::string& v) {
vaccineStatus.addVaccine(v); }
void display(unsigned int& ignoreCount, unsigned int&
displayCount) const;
};
The class Animal represents an animal in the adoption center system. It stores
information about the animal and provides methods to access and modify its data. It
has already been fully implemented for you.
Member Variables (Private)
● id: An unsigned integer variable that holds a unique identifier for the animal.
● species: An object of type Species that stores information about the animal's
species, including breed.
● age: An unsigned integer variable that keeps track of the animal's age.
● healthCondition: An object of type HealthCondition that represents the
animal's current health status.
● vaccineStatus: An object of type VaccinationStatus that stores the animal's
vaccination records.
● specialNeeds: A string variable that can hold information about any special
needs the animal might have.
Constructor (Public)
The Animal class has a single constructor that initializes an animal object with the
following properties:
● id: The unique identifier for the animal (required).
● species: A const reference to a Species object specifying the animal's
species and breed (required).
● age: The animal's age (required).
● healthCondition: The animal's initial health condition (optional, defaults to
NORMAL_HEALTH if not provided).
● vaccineStatus: The animal's initial vaccination status (optional, defaults to
an empty VaccinationStatus object if not provided).
● specialNeeds: Any special needs of the animal (optional, defaults to an
empty string if not provided).
Additionally, the copy constructor and assignment operator are deleted, prohibiting
the creation of Animal copy objects.
Member Functions (Public)
The Animal class provides various functions to access and modify the animal's
information:
● get[...]() const: Accessor functions to retrieve the animal's data.
● incrementAge(): This function increments the animal's age by one.
● setHealthCondition(const HealthCondition& h): This function
allows updating the animal's health condition with a new HealthCondition
object.
● setSpecialNeeds(const std::string& n): This function allows
setting any special needs for the animal as a string.
● addVaccine(const std::string& v): This function adds a new vaccine
(represented by a string v) to the animal's vaccination records stored in the
VaccinationStatus object.
● display(unsigned int& ignoreCount, unsigned int&
displayCount) const: A provided function for displaying an Animal.
Parameters are used to show the animals in different pages.
○ ignoreCount: If this value is non-zero, decrement it without printing
the Animal.
○ displayCount: If this value is zero, do nothing. Otherwise, print the
Animal and decrement it.
Binary Search Tree (BST)
The files bst.h and bst.cpp defines data structures and provide the foundation for
organizing and managing animal data in the adoption center system.
Since the adoption system should eventually be able to sort and display the pets
using different criteria, we would like to use Binary Search Tree (BST) data structure
to support the sorting algorithm. This BST is implemented in a similar way to the
lecture notes version, with one important change: The value data type T is replaced
with a linked-list of Animal pointers. This allows two important things:
● The BST can support storing multiple values with the same sorting criteria
(e.g. animals with the same age).
● We can have multiple BSTs pointing to the same Animal objects, differing only
in the sorting order of the animals.
The following section describes each data type required to implement the BST:
Structure: Filter
struct Filter {
std::string speciesFilter {""};
std::string healthFilter {""};
std::string vaccineFilter[VACCINE_TABLE_SIZE] {};
bool match(const Animal& a) const;
};
● This structure defines a filter object used to narrow down the search for
animals. It contains three members:
○ speciesFilter: A string of terms the animals' species name may
contain (e.g., searching for "dog" should match all animals with species
name "Dog").
○ healthFilter: A similar search term as above, for the health
condition description.
○ vaccineFilter: An array of vaccine names that the animals should
contain. By default all entries are empty strings.
● The struct contains one member function match() that returns true if the
Animal parameter matches with the filter values. For example, consider an
Animal with species name "Cat (British Shorthair)", age 20, health condition
"Very poor", having taken 3 vaccines: "FPV", "FCV", "FIP". A Filter with the
values speciesFilter = "cat short", healthFilter = "Poor",
and vaccineFilter = {"FCV", "FPV"} will return true for the animal
above.
Structure: AnimalLLnode (Linked List Node)
struct AnimalLLnode {
const Animal* animal;
AnimalLLnode* next;
AnimalLLnode(const Animal* a, AnimalLLnode* next =
nullptr): animal(a), next(next) {}
~AnimalLLnode() = default;
void print(unsigned int& ignoreCount, unsigned int&
displayCount, const Filter& filter) const;
};
● This structure defines a node for a linked list. It stores:
○ animal: A pointer to a constant Animal object.
○ next: A pointer to the next node in the linked list. If there are no more
nodes, this points to nullptr.
● The destructor of this struct is default, since we do not want to delete the
Animal object in this struct (similar to lab 3).
● The struct contains one member function print() for printing all animals in
this linked list, if they match with the provided Filter.
Structure: BSTnode (Binary Search Tree Node)
struct BSTnode {
AnimalLLnode* head;
BST left;
BST right;
BSTnode(const Animal* a, const AnimalComparator c) :
head(new AnimalLLnode(a, nullptr)), left(c), right(c) { }
BSTnode(const BSTnode&) = delete;
BSTnode& operator=(const BSTnode&) = delete;
~BSTnode();
void addAnimal(const Animal* a);
void removeAnimal(const Animal* a);
};
● This structure defines a node in a Binary Search Tree (BST). It stores:
○ head: A pointer to an AnimalLLnode, the head of a linked list
containing animals with the same sorting criteria.
○ left: A BST object representing the left subtree.
○ right: A BST object representing the right subtree.
● Similar to Animal, the copy constructor and assignment operator are deleted
to disable copying.
● The destructor will need to perform deallocation of all nodes in the linked list.
● addAnimal(const Animal* a) and removeAnimal(const Animal*
a) are member functions to add or remove Animals in the linked list.
AnimalComparator
typedef int (*AnimalComparator)(const Animal*, const Animal*);
This is a function pointer type. An object of type AnimalComparator is actually a
function that has 2 parameters of type const Animal*, and returns an int
representing comparison between 2 animals.
Class: BST (Binary Search Tree)
class BST {
private:
BSTnode* root;
const AnimalComparator comparator;
BSTnode*& findMinNode();
public:
BST(const AnimalComparator comparator): root(nullptr),
comparator(comparator) {}
~BST();
bool isEmpty() const { return root == nullptr; }
void insert(const Animal*);
void remove(const Animal*);
void print(unsigned int& ignoreCount, unsigned int&
displayCount, const Filter& filter) const;
};
● This class represents a BST used to store and manage Animal objects. It has
3 private data members and member functions:
○ root: A pointer to the root node of the BST.
○ comparator: A function pointer to the AnimalComparator function for
comparing animals.
○ findMinNode(): Returns a pointer reference to the BSTnode with the
minimum value.
● It also has public member functions for various BST operations:
○ isEmpty(): Checks if the BST is empty.
○ insert(const Animal*): Inserts a new animal object into the BST.
○ remove(const Animal*): Removes an animal object from the BST.
○ A print() function similar to AnimalLLnode for displaying animals in
order.
Adoption Center
The files adoptionCenter.h and adoptionCenter.cpp define and offers a structured
approach to managing animals in an adoption center.
enum SortCriteria {
NAME,
AGE,
HEALTH,
VACCINE,
ID // equals to number of criterias
};
class AdoptionCenter {
private:
Animal** animals;
unsigned int numAnimals;
BST sortedAnimals[ID];
public:
AdoptionCenter();
AdoptionCenter(const AdoptionCenter&) = delete;
AdoptionCenter& operator=(const AdoptionCenter&) =
delete;
~AdoptionCenter();
void addAnimal(Animal* a);
bool removeAnimal(unsigned int id);
void incrementAge();
void setAnimalHealthCondition(unsigned int id, const
HealthCondition& h);
void addAnimalVaccine(unsigned int id, const
std::string& v);
void setAnimalSpecialNeeds(unsigned int id, const
std::string& n);
void display(unsigned int start, unsigned int stop,
const Filter& filter, SortCriteria criteria = ID) const;
void displayPetVaccines(unsigned int id) const;
};
This code defines a class named AdoptionCenter that manages the operations of an
animal adoption center. An additional enum is defined representing the different
sorting criterias of the animals.
Enumeration: SortCriteria
● This enumeration defines constants representing different criteria for sorting
animals. These include:
○ NAME: Sort by animal's species name (including breed).
○ AGE: Sort by animal's age.
○ HEALTH: Sort by animal's health condition.
○ VACCINE: Sort by animal's vaccination status.
○ ID: Sort by animal's unique identifier. Also used as the number of
sorting criterias (other than ID).
Member Variables (Private)
● animals: A dynamic-length array of dynamic Animal objects.
● numAnimals: An unsigned integer variable that keeps track of the number of
animals currently in the center.
● sortedAnimals[ID]: An array of BST (Binary Search Tree) objects, one for
each unique SortCriteria (except ID). Each BST should be initialized with the
comparison function corresponding to its sorting criteria. They contain
pointers to the Animals stored in the dynamic array.
Constructors and Destructor (Public)
● AdoptionCenter(): Default constructor, used to initialize an
AdoptionCenter object with default values.
● ~AdoptionCenter(): Destructor, used to clean up any memory allocated by
the AdoptionCenter object when it goes out of scope.
● Copy constructor and assignment operator are deleted to prevent copying.
Member Functions (Public)
The AdoptionCenter class provides several functions to manage the animals and
display information about them.
● addAnimal(Animal* a): Add a new animal (pointed to by a) to the center's
collection. It updates animals and numAnimals, as well as all BSTs,
accordingly.
● removeAnimal(unsigned int id): Remove an animal from the center
based on its ID. It returns a boolean value indicating success (true) or failure
(false) to remove the animal. Data members are also updated accordingly.
● incrementAge(): Increment the age of all animals in the center by one unit
(day, month, year - depending on the implementation).
● setAnimalHealthCondition(unsigned int id, const
HealthCondition& h): Set the health condition of a specific animal
(identified by ID) based on a HealthCondition object.
● addAnimalVaccine(unsigned int id, const std::string& v):
Add a new vaccine (represented by a string v) to the medical history of a
specific animal (identified by ID).
● setAnimalSpecialNeeds(unsigned int id, const std::string&
n): Set any special needs of a specific animal (identified by ID) as a string (n).
● display(unsigned int start, unsigned int stop, const
Filter& filter, SortCriteria criteria = ID) const: Display
information about animals in the center. It takes several parameters:
○ start, stop: Indices of animals to display, in order to show animals in
pages.
○ filter: A reference to a Filter object that allows filtering animals
based on certain search terms.
○ criteria: An optional parameter specifying the criteria to sort the
animals by before displaying them. The default sorting criteria is animal
ID.
● For criterias other than ID, the function utilizes the BSTs to efficiently traverse
and display animals based on the provided sorting criteria.
● displayPetVaccines(unsigned int id) const: Display the full
information about an animal's vaccine history.
randomAnimalGenerator.cpp/.h
These files are provided for you to simulate adding several animals to the system.
The random number generator is seeded to ensure consistent output between runs,
both on your machine and on ZINC.
main.cpp
The main code used in the sample program. To compile with this file, run make in the
terminal, which will generate PA3.exe. You can play with it and compare the
behaviour with the sample program.
main_test.cpp
Similar to PA1 and PA2, the testing program is provided. Run make test in the
terminal, which will generate PA3_test.exe, execute the program and type a number
from 1 to 50 to run the test case and compare with the output files.
End of Code overview
Tasks
Task 1: Datatypes
In this part, you will implement the member functions of VaccinationStatus in
datatypes.cpp.
Task 1.1:
VaccinationStatus::VaccinationStatus()
Default VaccinationStatus constructor, which should initialize the
vaccineHashTable array to all empty strings, and numVaccines to 0.
Task 1.2:
void VaccinationStatus::addVaccine(const string& v)
Add a vaccine to the hash table, following the quadratic probing open addressing
scheme:
● If the table is not at least half empty, output error message and return.
● Else, calculate the input string's equivalent key: k = sumStringChars(v),
where sumStringCharsis a provided helper function.
● Probe into the hash table using key k, hash function hash(k) = k %
VACCINE_TABLE_SIZE, and the quadratic probing formula.
○ If the same string as v is found, output error message and return, as
the hash table does not support duplicate values.
○ Else, if an empty string is found, set it to v and return.
Task 1.3:
bool VaccinationStatus::hasVaccine(const string& v) const
Check if vaccine v is stored in the hash table. Follow the same steps as above to
probe into the hash table, and return true if the string exists in the table.
Task 2: BST Helper Structs
In this part, you will implement the Filter, AnimalLLnode and BSTnode structs in
bst.cpp, which will be needed when implementing the BST in task 3.
Task 2.1:
bool Filter::match(const Animal& a) const
Return true if the Animal a matches with the filter strings:
● The string representing the animal's species (e.g. "Cat (British Shorthair)")
contains any of the words in speciesFilter. You may use the provided
helper function containAnyWords.
● The string describing the animal's health condition (e.g. "Healthy") contains
any of the words in healthFilter.
● The animal's vaccination record contains all of the vaccines in
vaccineFilter. The array contains some strings representing the vaccines
to filter, while the remaining entries are empty strings.
Task 2.2:
void AnimalLLnode::print(unsigned int& ignoreCount, unsigned
int& displayCount, const Filter& filter) const
Print the whole linked list of Animals (that matches the print counts and the filter),
starting from the current node as the head. You need to implement this function such
that the list of animals is printed in increasing ID order (Hint: task 2.4 should ensure
the linked list is in decreasing ID order).
Task 2.3:
BSTnode::~BSTnode()
Deallocate the linked list in the BSTnode.
Task 2.4:
void BSTnode::addAnimal(const Animal* a)
Add an Animal to the current linked list, such that the sequence of animals is in
decreasing ID order. In other words, the ID of node is larger than the ID of
node->next.
Task 2.5:
void BSTnode::removeAnimal(const Animal* a)
Remove an Animal from the current linked list.
● If the animal is not found, do nothing.
● If the linked list is empty after removing, head should be set to nullptr.
Task 3: BST
In this part, you will implement the member functions of BST in bst.cpp. As
mentioned, this class is implemented similar to the lecture notes example, with 2 key
differences:
● The value data is replaced with a linked list of Animals. This means we cannot
simply "assign" or "copy" pointer values between nodes, especially during
item removal, and you need to ensure there is no runtime errors such as
memory leak, double deletion or accessing memory that was already deleted.
● Comparison between Animals is done using the comparator data member.
This is a function that compares two Animals (via their pointers), a and b, and
returns an int value:
○ The return value is negative if a < b.
○ The return value equals 0 if a == b.
○ The return value is positive if a > b.
Task 3.1:
BST::~BST()
Deallocate dynamic memory in the BST.
Task 3.2:
BSTnode*& BST::findMinNode()
Return a reference to the BSTnode* pointing to the node with the lowest value. This
is similar to the lecture notes example's find_min() function, but the return value
is the node itself.
Note: This function is optional and will not be tested. However, it is recommended
that you implement this function to be used in task 3.4. Alternatively, you are free to
implement task 3.4 without using this function.
Task 3.3:
void BST::insert(const Animal* a)
Insert an animal to the BST. Note that unlike the lecture notes example, if a node
with the "same" value already exists, this animal should be added to its linked list.
Task 3.4:
void BST::remove(const Animal* a)
Remove an animal from the BST. The steps are similar to the lecture notes with a
few differences:
● If the node with the "same" value is found, remove it from the linked list.
● If the linked list becomes empty, the BSTnode needs to be removed from the
BST. This means:
○ If this node has 2 children, "move" the linked list from the
minimum-value node of the right BST to the current node, and remove
the old minimum-value node from the right BST.
○ Else, remove and deallocate this node similar to the lecture example.
Task 3.5:
void BST::print(unsigned int& ignoreCount, unsigned int&
displayCount, const Filter& filter) const
Print all animals in the BST (that matches the print counts and the filter) in increasing
"value" order.
Task 4: AdoptionCenter
For the final part, you will implement the class AdoptionCenter in
adoptionCenter.cpp.
Task 4.1:
AdoptionCenter::AdoptionCenter()
Initialize an empty AdoptionCenter with no animals. More specifically:
● Set animals to nullptr.
● Set numAnimals to 0.
● Initialize the sortedAnimals BSTs, which require a parameter of type
AnimalComparator. This can be achieved by supplying a lambda function
with the correct parameters and return value.
The sorting method for each BST:
● NAME: Sort by species name, in increasing lexicographic order. For example,
"Bird" is before "Cat".
● AGE: Sort by age, in increasing order.
● HEALTH: Sort by health condition severity, in increasing order.
● VACCINE: Sort by vaccine status total hash value, in increasing order.
Task 4.2:
AdoptionCenter::~AdoptionCenter()
Deallocate dynamic memory in the AdoptionCenter.
Task 4.3:
void AdoptionCenter::addAnimal(Animal* a)
Add an animal to the dynamic array by increasing the array size by 1, assign the new
Animal to the end of the array, and increment numAnimals accordingly. Then, add
the animal to all of the BSTs.
Task 4.4:
bool AdoptionCenter::removeAnimal(unsigned int id)
Remove the animal with the specified ID from the AdoptionCenter.
● If the ID does not exist, the function should do nothing.
● Otherwise, if the animal with the specified ID is found:
○ Remove it from the dynamic array. Reduce the dynamic array size by 1
and decrement numAnimals accordingly.
○ Remove it from all of the BSTs.
○ Deallocate the Animal object.
Finally, return true if an animal was successfully removed from the AdoptionCenter.
Task 4.5:
void AdoptionCenter::incrementAge()
Increment the age of all existing Animals by 1.
Note: The BST sorted by age does not need to be re-sorted.
Task 4.6:
void AdoptionCenter::setAnimalHealthCondition(unsigned int id,
const HealthCondition& h)
Find the animal with the specified ID and set its HealthCondition accordingly.
● If the ID does not exist, do nothing.
● Else, make sure the BST sorted by health severity remains sorted.
Task 4.7:
void AdoptionCenter::addAnimalVaccine(unsigned int id, const
string& v)
Add a vaccine to the animal with the specified ID. This is implemented in a similar
way to the above function.
Task 4.8:
void AdoptionCenter::setAnimalSpecialNeeds(unsigned int id,
const std::string& n)
Modify the special needs of the animal with the specified ID. This is implemented in a
similar way to the above function, but there is no need to modify any BSTs.
End of Tasks
Compile & Test
main.cpp
Compile the main program by running make. The main program is a simulation of the
user interface of the adoption system, where the user can view, sort, filter available
animals. There are also admin options to modify the list of animals. The available
options are briefly described in the program prompt:
1. View available pets. Pets are displayed in pages.
1. Information displayed for each pet: ID, Species (Breed), Age, Health
condition, Number of vaccines taken (Total hash value), Special needs.
2. While in the display menu, type < or > to move between pages. Type
any other character to exit.
2. Change the current filter (default: no filter).
1. The user may select the option to enter a string used for filtering
species name or health description.
2. The user may also add or remove vaccine names from the filter's
vaccine list.
3. Change the sorting order (default: ID).
4. Change the number of animals displayed per page (default: 20)
5. Display the full list of vaccines an animal has taken by providing its ID.
6. Admin options:
1. Add an animal to the database. The admin user types the information
of the animal as prompted.
2. Remove an animal from the database by providing its ID.
3. Increment the age of all animals.
4. Change an animal's health condition (description and severity).
5. Add a vaccine to an animal.
6. Change an animal's special needs description.
Note: If you type the wrong input type (e.g. the program expects an int, but a string
was entered instead), the program may encounter infinite loop. This is not relevant to
the tasks, you just need to pay attention when typing the input.
Example output:
Welcome to the Pet Adoption Center Management System.
Select your choice:
1. View available pets
2. Set filter (current filter: Species = None; Health Condition = None; Vaccines: None)
3. Change sort criteria (current criteria: ID)
4. Change display count (current display amount: 20)
5. View pet's taken vaccines
6. Admin options
7. Exit
1
ID Species (Breed) Age Health Condi... Vaccines Taken Special Needs
=========================================================================
============================
0 Bird (Budgerigar) 14 Healthy 0 (0 )
1 Cat (Persian) 19 Fair 0 (0 )
2 Cat (British Shorthair) 29 Healthy 3 (3735 )
4 Bird (Green-Cheeked Conure) 19 Healthy 1 (880 )
5 Rabbit (N/A) 14 Healthy 1 (1128 )
6 Reptiles (Ball Python) 9 Very poor 0 (0 )
7 Rabbit (Flemish Giant) 13 Healthy 4 (25348)
9 Rabbit (N/A) 20 Poor 5 (28400)
10 Reptiles (King Snakes) 7 Healthy 3 (9825 )
11 Reptiles (Crested Gecko) 13 Healthy 3 (12756)
12 Dog (Daschund) 2 Healthy 2 (5160 )
14 Reptiles (King Snakes) 19 Very poor 0 (0 )
15 Cat (Maine Coon) 9 Healthy 1 (598 )
16 Reptiles (King Snakes) 8 Healthy 0 (0 )
17 Bird (Cockatiel) 18 Poor 3 (7722 )
19 Reptiles (Corn Snakes) 14 Healthy 2 (4432 )
20 Cat (N/A) 25 Healthy 3 (3462 )
21 Reptiles (Corn Snakes) 15 Healthy 0 (0 )
22 Rabbit (Dwarf Hotot) 19 Healthy 3 (4959 )
24 Bird (Parrotlet) 29 Very poor 0 (0 )
=========================================================================
============================
Page 1
Enter < or > to go to previous or next page (enter anything else to exit)
>
ID Species (Breed) Age Health Condi... Vaccines Taken Special Needs
=========================================================================
============================
25 Cat (Siamese) 22 Healthy 1 (223 )
26 Reptiles (Leopard Gecko) 28 Healthy 2 (4460 )
27 Bird (Cockatiel) 4 Healthy 1 (1384 )
29 Rabbit (Dwarf Hotot) 22 Healthy 1 (1287 )
30 Rabbit (Rex) 9 Healthy 4 (16520)
31 Rabbit (Flemish Giant) 2 Healthy 0 (0 )
32 Cat (Siamese) 19 Bad 5 (14295)
34 Bird (N/A) 10 Healthy 3 (10719)
35 Reptiles (Crested Gecko) 10 Healthy 0 (0 ) Ear cleaning (infected)
36 Dog (Golden Retriever) 25 Very poor 3 (12975)
37 Cat (British Shorthair) 29 Healthy 3 (3147 )
39 Bird (Canary Finch) 0 Healthy 4 (15000)
40 Dog (Bulldog) 4 Healthy 4 (21468)
41 Bird (Hahn's Macaw) 17 Healthy 0 (0 ) Wound cleaning
42 Cat (Maine Coon) 20 Critical 3 (7167 )
44 Bird (Hahn's Macaw) 27 Poor 2 (5282 )
45 Dog (Bulldog) 18 Healthy 4 (19780)
46 Rabbit (English Lop) 23 Poor 4 (16288)
47 Reptiles (Hamster) 4 Critical 3 (16623)
49 Dog (Beagle) 9 Healthy 2 (6250 )
=========================================================================
============================
Page 2
Enter < or > to go to previous or next page (enter anything else to exit)
>
ID Species (Breed) Age Health Condi... Vaccines Taken Special Needs
=========================================================================
============================
50 Reptiles (Ball Python) 19 Healthy 0 (0 )
51 Dog (German Shepherd Dog) 6 Healthy 4 (16736)
52 Reptiles (Guinea pig) 18 Healthy 1 (1032 )
54 Bird (Green-Cheeked Conure) 9 Healthy 3 (9069 )
55 Dog (Siberian Huskey) 16 Healthy 1 (2030 )
56 Rabbit (N/A) 28 Healthy 1 (1287 )
57 Rabbit (Dutch) 28 Healthy 0 (0 )
59 Dog (Bulldog) 3 Healthy 2 (1822 )
60 Rabbit (English Angora) 28 Healthy 2 (4172 ) Antibacterial medicine
61 Bird (Cockatoo) 12 Healthy 0 (0 ) Ear cleaning (infected)
62 Cat (Siamese) 10 Healthy 5 (19615)
64 Cat (Maine Coon) 7 Healthy 4 (7008 )
65 Dog (Bulldog) 14 Healthy 4 (19996)
66 Cat (Ragdoll) 24 Healthy 4 (17852)
67 Reptiles (Guinea pig) 7 Healthy 0 (0 )
69 Dog (German Shepherd Dog) 0 Healthy 0 (0 )
70 Rabbit (Dutch) 8 Healthy 4 (23424) Hand feeding
71 Reptiles (Crested Gecko) 2 Healthy 2 (2810 )
72 Cat (Ragdoll) 8 Bad 0 (0 ) Antibacterial medicine
74 Reptiles (Crested Gecko) 20 Healthy 0 (0 )
=================================
Introduction
In this assignment, we will make use of the C++ concepts learned in the lectures:
binary search tree (BST)and hashing to create a database system to manage pets
for adoption. Using this system the user is be able to see the list of different pets
available for adoption, each with several attributes such as species, age, health
condition, vaccination status, special needs, etc. The user can sort and filter the
options based on different criteria, similar to lab 1 exercise.
Code overview
You are provided the following files in the skeleton code:
● adoptionCenter.h/.cpp
● animal.h/.cpp
● bst.h/.cpp
● datatypes.h/.cpp
● randomAnimalGenerator.h/.cpp
● main.cpp/main_test.cpp
This section will give a brief description of the classes, in the order you will need to
implement/use.
IMPORTANT: After reading the overview of classes, please refer to this example to
understand how the adoption center manages 4 different binary search trees at
once, as well as how the BSTs should handle different cases of element
insertion/deletion.
Data Types
The files datatypes.h and datatypes.cpp define data structures that provide a
comprehensive way to represent animal information in the adoption center system.
struct Species {
std::string name;
std::string breed;
};
struct HealthCondition {
std::string description;
unsigned int severity;
};
struct VaccinationStatus {
std::string vaccineHashTable[VACCINE_TABLE_SIZE];
unsigned int numVaccines;
VaccinationStatus();
void addVaccine(const std::string& v);
bool hasVaccine(const std::string& v) const;
unsigned int getTotalHashValue() const;
};
These structures represent information about animal species, health conditions, and
vaccination status.
Structure: Species
● This structure defines a way to store information about an animal's species. It
has two members:
○ name: A string containing the animal's species name (e.g., "Cat",
"Dog").
○ breed: A string containing the animal's breed (e.g., "Siamese",
"Labrador Retriever"), or "N/A" if breed is not applicable.
Structure: HealthCondition
● This structure defines a way to represent an animal's health condition. It has
two members:
○ description: A string describing the animal's health condition (e.g.,
"Healthy", "Fair", "Poor").
○ severity: A value between 0 (no severity) and 1000 (most severe)
representing the severity of the health condition.
● A constant NORMAL_HEALTH is defined with a description of "Healthy" and a
severity of 0, used as a default health condition for animals.
Structure: VaccinationStatus
● This structure defines a way to manage an animal's vaccination records. It
has three members:
○ vaccineHashTable[VACCINE_TABLE_SIZE]: An array of strings
with a fixed size (VACCINE_TABLE_SIZE) to store vaccine names
using a hash table approach.
○ numVaccines: An unsigned integer variable keeping track of the
number of vaccines currently stored in the hash table.
● The structure has member functions for managing the hash table:
○ addVaccine(const std::string& v): Adds a new vaccine name
(v) to the vaccination records.
○ hasVaccine(const std::string& v) const: Checks if a
specific vaccine (v) is present in the vaccination records.
○ getTotalHashValue() const: Calculates a value representing the
vaccination record of this animal for comparison.
Animal
The files animal.h and animal.cpp define a class representing pets in the system,
allowing for detailed information storage and manipulation.
class Animal {
private:
unsigned int id;
Species species;
unsigned int age;
HealthCondition healthCondition;
VaccinationStatus vaccineStatus;
std::string specialNeeds;
public:
Animal(
unsigned int id, const Species& s, unsigned int a,
const HealthCondition& h = NORMAL_HEALTH,
const VaccinationStatus& v = VaccinationStatus(),
const std::string& n = ""
): id(id), species(s), age(a), healthCondition(h),
vaccineStatus(v), specialNeeds(n) {}
Animal(const Animal&) = delete;
Animal& operator=(const Animal&) = delete;
unsigned int getID() const { return id; }
std::string getSpecies() const { return species.name +
" (" + species.breed + ")"; }
unsigned int getAge() const { return age; }
const HealthCondition& getHealthCondition() const {
return healthCondition; }
const VaccinationStatus& getVaccinationStatus() const
{ return vaccineStatus; }
std::string getSpecialNeeds() const { return
specialNeeds; }
void incrementAge() { ++age; }
void setHealthCondition(const HealthCondition& h) {
healthCondition = h; }
void setSpecialNeeds(const std::string& n) {
specialNeeds = n; }
void addVaccine(const std::string& v) {
vaccineStatus.addVaccine(v); }
void display(unsigned int& ignoreCount, unsigned int&
displayCount) const;
};
The class Animal represents an animal in the adoption center system. It stores
information about the animal and provides methods to access and modify its data. It
has already been fully implemented for you.
Member Variables (Private)
● id: An unsigned integer variable that holds a unique identifier for the animal.
● species: An object of type Species that stores information about the animal's
species, including breed.
● age: An unsigned integer variable that keeps track of the animal's age.
● healthCondition: An object of type HealthCondition that represents the
animal's current health status.
● vaccineStatus: An object of type VaccinationStatus that stores the animal's
vaccination records.
● specialNeeds: A string variable that can hold information about any special
needs the animal might have.
Constructor (Public)
The Animal class has a single constructor that initializes an animal object with the
following properties:
● id: The unique identifier for the animal (required).
● species: A const reference to a Species object specifying the animal's
species and breed (required).
● age: The animal's age (required).
● healthCondition: The animal's initial health condition (optional, defaults to
NORMAL_HEALTH if not provided).
● vaccineStatus: The animal's initial vaccination status (optional, defaults to
an empty VaccinationStatus object if not provided).
● specialNeeds: Any special needs of the animal (optional, defaults to an
empty string if not provided).
Additionally, the copy constructor and assignment operator are deleted, prohibiting
the creation of Animal copy objects.
Member Functions (Public)
The Animal class provides various functions to access and modify the animal's
information:
● get[...]() const: Accessor functions to retrieve the animal's data.
● incrementAge(): This function increments the animal's age by one.
● setHealthCondition(const HealthCondition& h): This function
allows updating the animal's health condition with a new HealthCondition
object.
● setSpecialNeeds(const std::string& n): This function allows
setting any special needs for the animal as a string.
● addVaccine(const std::string& v): This function adds a new vaccine
(represented by a string v) to the animal's vaccination records stored in the
VaccinationStatus object.
● display(unsigned int& ignoreCount, unsigned int&
displayCount) const: A provided function for displaying an Animal.
Parameters are used to show the animals in different pages.
○ ignoreCount: If this value is non-zero, decrement it without printing
the Animal.
○ displayCount: If this value is zero, do nothing. Otherwise, print the
Animal and decrement it.
Binary Search Tree (BST)
The files bst.h and bst.cpp defines data structures and provide the foundation for
organizing and managing animal data in the adoption center system.
Since the adoption system should eventually be able to sort and display the pets
using different criteria, we would like to use Binary Search Tree (BST) data structure
to support the sorting algorithm. This BST is implemented in a similar way to the
lecture notes version, with one important change: The value data type T is replaced
with a linked-list of Animal pointers. This allows two important things:
● The BST can support storing multiple values with the same sorting criteria
(e.g. animals with the same age).
● We can have multiple BSTs pointing to the same Animal objects, differing only
in the sorting order of the animals.
The following section describes each data type required to implement the BST:
Structure: Filter
struct Filter {
std::string speciesFilter {""};
std::string healthFilter {""};
std::string vaccineFilter[VACCINE_TABLE_SIZE] {};
bool match(const Animal& a) const;
};
● This structure defines a filter object used to narrow down the search for
animals. It contains three members:
○ speciesFilter: A string of terms the animals' species name may
contain (e.g., searching for "dog" should match all animals with species
name "Dog").
○ healthFilter: A similar search term as above, for the health
condition description.
○ vaccineFilter: An array of vaccine names that the animals should
contain. By default all entries are empty strings.
● The struct contains one member function match() that returns true if the
Animal parameter matches with the filter values. For example, consider an
Animal with species name "Cat (British Shorthair)", age 20, health condition
"Very poor", having taken 3 vaccines: "FPV", "FCV", "FIP". A Filter with the
values speciesFilter = "cat short", healthFilter = "Poor",
and vaccineFilter = {"FCV", "FPV"} will return true for the animal
above.
Structure: AnimalLLnode (Linked List Node)
struct AnimalLLnode {
const Animal* animal;
AnimalLLnode* next;
AnimalLLnode(const Animal* a, AnimalLLnode* next =
nullptr): animal(a), next(next) {}
~AnimalLLnode() = default;
void print(unsigned int& ignoreCount, unsigned int&
displayCount, const Filter& filter) const;
};
● This structure defines a node for a linked list. It stores:
○ animal: A pointer to a constant Animal object.
○ next: A pointer to the next node in the linked list. If there are no more
nodes, this points to nullptr.
● The destructor of this struct is default, since we do not want to delete the
Animal object in this struct (similar to lab 3).
● The struct contains one member function print() for printing all animals in
this linked list, if they match with the provided Filter.
Structure: BSTnode (Binary Search Tree Node)
struct BSTnode {
AnimalLLnode* head;
BST left;
BST right;
BSTnode(const Animal* a, const AnimalComparator c) :
head(new AnimalLLnode(a, nullptr)), left(c), right(c) { }
BSTnode(const BSTnode&) = delete;
BSTnode& operator=(const BSTnode&) = delete;
~BSTnode();
void addAnimal(const Animal* a);
void removeAnimal(const Animal* a);
};
● This structure defines a node in a Binary Search Tree (BST). It stores:
○ head: A pointer to an AnimalLLnode, the head of a linked list
containing animals with the same sorting criteria.
○ left: A BST object representing the left subtree.
○ right: A BST object representing the right subtree.
● Similar to Animal, the copy constructor and assignment operator are deleted
to disable copying.
● The destructor will need to perform deallocation of all nodes in the linked list.
● addAnimal(const Animal* a) and removeAnimal(const Animal*
a) are member functions to add or remove Animals in the linked list.
AnimalComparator
typedef int (*AnimalComparator)(const Animal*, const Animal*);
This is a function pointer type. An object of type AnimalComparator is actually a
function that has 2 parameters of type const Animal*, and returns an int
representing comparison between 2 animals.
Class: BST (Binary Search Tree)
class BST {
private:
BSTnode* root;
const AnimalComparator comparator;
BSTnode*& findMinNode();
public:
BST(const AnimalComparator comparator): root(nullptr),
comparator(comparator) {}
~BST();
bool isEmpty() const { return root == nullptr; }
void insert(const Animal*);
void remove(const Animal*);
void print(unsigned int& ignoreCount, unsigned int&
displayCount, const Filter& filter) const;
};
● This class represents a BST used to store and manage Animal objects. It has
3 private data members and member functions:
○ root: A pointer to the root node of the BST.
○ comparator: A function pointer to the AnimalComparator function for
comparing animals.
○ findMinNode(): Returns a pointer reference to the BSTnode with the
minimum value.
● It also has public member functions for various BST operations:
○ isEmpty(): Checks if the BST is empty.
○ insert(const Animal*): Inserts a new animal object into the BST.
○ remove(const Animal*): Removes an animal object from the BST.
○ A print() function similar to AnimalLLnode for displaying animals in
order.
Adoption Center
The files adoptionCenter.h and adoptionCenter.cpp define and offers a structured
approach to managing animals in an adoption center.
enum SortCriteria {
NAME,
AGE,
HEALTH,
VACCINE,
ID // equals to number of criterias
};
class AdoptionCenter {
private:
Animal** animals;
unsigned int numAnimals;
BST sortedAnimals[ID];
public:
AdoptionCenter();
AdoptionCenter(const AdoptionCenter&) = delete;
AdoptionCenter& operator=(const AdoptionCenter&) =
delete;
~AdoptionCenter();
void addAnimal(Animal* a);
bool removeAnimal(unsigned int id);
void incrementAge();
void setAnimalHealthCondition(unsigned int id, const
HealthCondition& h);
void addAnimalVaccine(unsigned int id, const
std::string& v);
void setAnimalSpecialNeeds(unsigned int id, const
std::string& n);
void display(unsigned int start, unsigned int stop,
const Filter& filter, SortCriteria criteria = ID) const;
void displayPetVaccines(unsigned int id) const;
};
This code defines a class named AdoptionCenter that manages the operations of an
animal adoption center. An additional enum is defined representing the different
sorting criterias of the animals.
Enumeration: SortCriteria
● This enumeration defines constants representing different criteria for sorting
animals. These include:
○ NAME: Sort by animal's species name (including breed).
○ AGE: Sort by animal's age.
○ HEALTH: Sort by animal's health condition.
○ VACCINE: Sort by animal's vaccination status.
○ ID: Sort by animal's unique identifier. Also used as the number of
sorting criterias (other than ID).
Member Variables (Private)
● animals: A dynamic-length array of dynamic Animal objects.
● numAnimals: An unsigned integer variable that keeps track of the number of
animals currently in the center.
● sortedAnimals[ID]: An array of BST (Binary Search Tree) objects, one for
each unique SortCriteria (except ID). Each BST should be initialized with the
comparison function corresponding to its sorting criteria. They contain
pointers to the Animals stored in the dynamic array.
Constructors and Destructor (Public)
● AdoptionCenter(): Default constructor, used to initialize an
AdoptionCenter object with default values.
● ~AdoptionCenter(): Destructor, used to clean up any memory allocated by
the AdoptionCenter object when it goes out of scope.
● Copy constructor and assignment operator are deleted to prevent copying.
Member Functions (Public)
The AdoptionCenter class provides several functions to manage the animals and
display information about them.
● addAnimal(Animal* a): Add a new animal (pointed to by a) to the center's
collection. It updates animals and numAnimals, as well as all BSTs,
accordingly.
● removeAnimal(unsigned int id): Remove an animal from the center
based on its ID. It returns a boolean value indicating success (true) or failure
(false) to remove the animal. Data members are also updated accordingly.
● incrementAge(): Increment the age of all animals in the center by one unit
(day, month, year - depending on the implementation).
● setAnimalHealthCondition(unsigned int id, const
HealthCondition& h): Set the health condition of a specific animal
(identified by ID) based on a HealthCondition object.
● addAnimalVaccine(unsigned int id, const std::string& v):
Add a new vaccine (represented by a string v) to the medical history of a
specific animal (identified by ID).
● setAnimalSpecialNeeds(unsigned int id, const std::string&
n): Set any special needs of a specific animal (identified by ID) as a string (n).
● display(unsigned int start, unsigned int stop, const
Filter& filter, SortCriteria criteria = ID) const: Display
information about animals in the center. It takes several parameters:
○ start, stop: Indices of animals to display, in order to show animals in
pages.
○ filter: A reference to a Filter object that allows filtering animals
based on certain search terms.
○ criteria: An optional parameter specifying the criteria to sort the
animals by before displaying them. The default sorting criteria is animal
ID.
● For criterias other than ID, the function utilizes the BSTs to efficiently traverse
and display animals based on the provided sorting criteria.
● displayPetVaccines(unsigned int id) const: Display the full
information about an animal's vaccine history.
randomAnimalGenerator.cpp/.h
These files are provided for you to simulate adding several animals to the system.
The random number generator is seeded to ensure consistent output between runs,
both on your machine and on ZINC.
main.cpp
The main code used in the sample program. To compile with this file, run make in the
terminal, which will generate PA3.exe. You can play with it and compare the
behaviour with the sample program.
main_test.cpp
Similar to PA1 and PA2, the testing program is provided. Run make test in the
terminal, which will generate PA3_test.exe, execute the program and type a number
from 1 to 50 to run the test case and compare with the output files.
End of Code overview
Tasks
Task 1: Datatypes
In this part, you will implement the member functions of VaccinationStatus in
datatypes.cpp.
Task 1.1:
VaccinationStatus::VaccinationStatus()
Default VaccinationStatus constructor, which should initialize the
vaccineHashTable array to all empty strings, and numVaccines to 0.
Task 1.2:
void VaccinationStatus::addVaccine(const string& v)
Add a vaccine to the hash table, following the quadratic probing open addressing
scheme:
● If the table is not at least half empty, output error message and return.
● Else, calculate the input string's equivalent key: k = sumStringChars(v),
where sumStringCharsis a provided helper function.
● Probe into the hash table using key k, hash function hash(k) = k %
VACCINE_TABLE_SIZE, and the quadratic probing formula.
○ If the same string as v is found, output error message and return, as
the hash table does not support duplicate values.
○ Else, if an empty string is found, set it to v and return.
Task 1.3:
bool VaccinationStatus::hasVaccine(const string& v) const
Check if vaccine v is stored in the hash table. Follow the same steps as above to
probe into the hash table, and return true if the string exists in the table.
Task 2: BST Helper Structs
In this part, you will implement the Filter, AnimalLLnode and BSTnode structs in
bst.cpp, which will be needed when implementing the BST in task 3.
Task 2.1:
bool Filter::match(const Animal& a) const
Return true if the Animal a matches with the filter strings:
● The string representing the animal's species (e.g. "Cat (British Shorthair)")
contains any of the words in speciesFilter. You may use the provided
helper function containAnyWords.
● The string describing the animal's health condition (e.g. "Healthy") contains
any of the words in healthFilter.
● The animal's vaccination record contains all of the vaccines in
vaccineFilter. The array contains some strings representing the vaccines
to filter, while the remaining entries are empty strings.
Task 2.2:
void AnimalLLnode::print(unsigned int& ignoreCount, unsigned
int& displayCount, const Filter& filter) const
Print the whole linked list of Animals (that matches the print counts and the filter),
starting from the current node as the head. You need to implement this function such
that the list of animals is printed in increasing ID order (Hint: task 2.4 should ensure
the linked list is in decreasing ID order).
Task 2.3:
BSTnode::~BSTnode()
Deallocate the linked list in the BSTnode.
Task 2.4:
void BSTnode::addAnimal(const Animal* a)
Add an Animal to the current linked list, such that the sequence of animals is in
decreasing ID order. In other words, the ID of node is larger than the ID of
node->next.
Task 2.5:
void BSTnode::removeAnimal(const Animal* a)
Remove an Animal from the current linked list.
● If the animal is not found, do nothing.
● If the linked list is empty after removing, head should be set to nullptr.
Task 3: BST
In this part, you will implement the member functions of BST in bst.cpp. As
mentioned, this class is implemented similar to the lecture notes example, with 2 key
differences:
● The value data is replaced with a linked list of Animals. This means we cannot
simply "assign" or "copy" pointer values between nodes, especially during
item removal, and you need to ensure there is no runtime errors such as
memory leak, double deletion or accessing memory that was already deleted.
● Comparison between Animals is done using the comparator data member.
This is a function that compares two Animals (via their pointers), a and b, and
returns an int value:
○ The return value is negative if a < b.
○ The return value equals 0 if a == b.
○ The return value is positive if a > b.
Task 3.1:
BST::~BST()
Deallocate dynamic memory in the BST.
Task 3.2:
BSTnode*& BST::findMinNode()
Return a reference to the BSTnode* pointing to the node with the lowest value. This
is similar to the lecture notes example's find_min() function, but the return value
is the node itself.
Note: This function is optional and will not be tested. However, it is recommended
that you implement this function to be used in task 3.4. Alternatively, you are free to
implement task 3.4 without using this function.
Task 3.3:
void BST::insert(const Animal* a)
Insert an animal to the BST. Note that unlike the lecture notes example, if a node
with the "same" value already exists, this animal should be added to its linked list.
Task 3.4:
void BST::remove(const Animal* a)
Remove an animal from the BST. The steps are similar to the lecture notes with a
few differences:
● If the node with the "same" value is found, remove it from the linked list.
● If the linked list becomes empty, the BSTnode needs to be removed from the
BST. This means:
○ If this node has 2 children, "move" the linked list from the
minimum-value node of the right BST to the current node, and remove
the old minimum-value node from the right BST.
○ Else, remove and deallocate this node similar to the lecture example.
Task 3.5:
void BST::print(unsigned int& ignoreCount, unsigned int&
displayCount, const Filter& filter) const
Print all animals in the BST (that matches the print counts and the filter) in increasing
"value" order.
Task 4: AdoptionCenter
For the final part, you will implement the class AdoptionCenter in
adoptionCenter.cpp.
Task 4.1:
AdoptionCenter::AdoptionCenter()
Initialize an empty AdoptionCenter with no animals. More specifically:
● Set animals to nullptr.
● Set numAnimals to 0.
● Initialize the sortedAnimals BSTs, which require a parameter of type
AnimalComparator. This can be achieved by supplying a lambda function
with the correct parameters and return value.
The sorting method for each BST:
● NAME: Sort by species name, in increasing lexicographic order. For example,
"Bird" is before "Cat".
● AGE: Sort by age, in increasing order.
● HEALTH: Sort by health condition severity, in increasing order.
● VACCINE: Sort by vaccine status total hash value, in increasing order.
Task 4.2:
AdoptionCenter::~AdoptionCenter()
Deallocate dynamic memory in the AdoptionCenter.
Task 4.3:
void AdoptionCenter::addAnimal(Animal* a)
Add an animal to the dynamic array by increasing the array size by 1, assign the new
Animal to the end of the array, and increment numAnimals accordingly. Then, add
the animal to all of the BSTs.
Task 4.4:
bool AdoptionCenter::removeAnimal(unsigned int id)
Remove the animal with the specified ID from the AdoptionCenter.
● If the ID does not exist, the function should do nothing.
● Otherwise, if the animal with the specified ID is found:
○ Remove it from the dynamic array. Reduce the dynamic array size by 1
and decrement numAnimals accordingly.
○ Remove it from all of the BSTs.
○ Deallocate the Animal object.
Finally, return true if an animal was successfully removed from the AdoptionCenter.
Task 4.5:
void AdoptionCenter::incrementAge()
Increment the age of all existing Animals by 1.
Note: The BST sorted by age does not need to be re-sorted.
Task 4.6:
void AdoptionCenter::setAnimalHealthCondition(unsigned int id,
const HealthCondition& h)
Find the animal with the specified ID and set its HealthCondition accordingly.
● If the ID does not exist, do nothing.
● Else, make sure the BST sorted by health severity remains sorted.
Task 4.7:
void AdoptionCenter::addAnimalVaccine(unsigned int id, const
string& v)
Add a vaccine to the animal with the specified ID. This is implemented in a similar
way to the above function.
Task 4.8:
void AdoptionCenter::setAnimalSpecialNeeds(unsigned int id,
const std::string& n)
Modify the special needs of the animal with the specified ID. This is implemented in a
similar way to the above function, but there is no need to modify any BSTs.
End of Tasks
Compile & Test
main.cpp
Compile the main program by running make. The main program is a simulation of the
user interface of the adoption system, where the user can view, sort, filter available
animals. There are also admin options to modify the list of animals. The available
options are briefly described in the program prompt:
1. View available pets. Pets are displayed in pages.
1. Information displayed for each pet: ID, Species (Breed), Age, Health
condition, Number of vaccines taken (Total hash value), Special needs.
2. While in the display menu, type < or > to move between pages. Type
any other character to exit.
2. Change the current filter (default: no filter).
1. The user may select the option to enter a string used for filtering
species name or health description.
2. The user may also add or remove vaccine names from the filter's
vaccine list.
3. Change the sorting order (default: ID).
4. Change the number of animals displayed per page (default: 20)
5. Display the full list of vaccines an animal has taken by providing its ID.
6. Admin options:
1. Add an animal to the database. The admin user types the information
of the animal as prompted.
2. Remove an animal from the database by providing its ID.
3. Increment the age of all animals.
4. Change an animal's health condition (description and severity).
5. Add a vaccine to an animal.
6. Change an animal's special needs description.
Note: If you type the wrong input type (e.g. the program expects an int, but a string
was entered instead), the program may encounter infinite loop. This is not relevant to
the tasks, you just need to pay attention when typing the input.
Example output:
Welcome to the Pet Adoption Center Management System.
Select your choice:
1. View available pets
2. Set filter (current filter: Species = None; Health Condition = None; Vaccines: None)
3. Change sort criteria (current criteria: ID)
4. Change display count (current display amount: 20)
5. View pet's taken vaccines
6. Admin options
7. Exit
1
ID Species (Breed) Age Health Condi... Vaccines Taken Special Needs
=========================================================================
============================
0 Bird (Budgerigar) 14 Healthy 0 (0 )
1 Cat (Persian) 19 Fair 0 (0 )
2 Cat (British Shorthair) 29 Healthy 3 (3735 )
4 Bird (Green-Cheeked Conure) 19 Healthy 1 (880 )
5 Rabbit (N/A) 14 Healthy 1 (1128 )
6 Reptiles (Ball Python) 9 Very poor 0 (0 )
7 Rabbit (Flemish Giant) 13 Healthy 4 (25348)
9 Rabbit (N/A) 20 Poor 5 (28400)
10 Reptiles (King Snakes) 7 Healthy 3 (9825 )
11 Reptiles (Crested Gecko) 13 Healthy 3 (12756)
12 Dog (Daschund) 2 Healthy 2 (5160 )
14 Reptiles (King Snakes) 19 Very poor 0 (0 )
15 Cat (Maine Coon) 9 Healthy 1 (598 )
16 Reptiles (King Snakes) 8 Healthy 0 (0 )
17 Bird (Cockatiel) 18 Poor 3 (7722 )
19 Reptiles (Corn Snakes) 14 Healthy 2 (4432 )
20 Cat (N/A) 25 Healthy 3 (3462 )
21 Reptiles (Corn Snakes) 15 Healthy 0 (0 )
22 Rabbit (Dwarf Hotot) 19 Healthy 3 (4959 )
24 Bird (Parrotlet) 29 Very poor 0 (0 )
=========================================================================
============================
Page 1
Enter < or > to go to previous or next page (enter anything else to exit)
>
ID Species (Breed) Age Health Condi... Vaccines Taken Special Needs
=========================================================================
============================
25 Cat (Siamese) 22 Healthy 1 (223 )
26 Reptiles (Leopard Gecko) 28 Healthy 2 (4460 )
27 Bird (Cockatiel) 4 Healthy 1 (1384 )
29 Rabbit (Dwarf Hotot) 22 Healthy 1 (1287 )
30 Rabbit (Rex) 9 Healthy 4 (16520)
31 Rabbit (Flemish Giant) 2 Healthy 0 (0 )
32 Cat (Siamese) 19 Bad 5 (14295)
34 Bird (N/A) 10 Healthy 3 (10719)
35 Reptiles (Crested Gecko) 10 Healthy 0 (0 ) Ear cleaning (infected)
36 Dog (Golden Retriever) 25 Very poor 3 (12975)
37 Cat (British Shorthair) 29 Healthy 3 (3147 )
39 Bird (Canary Finch) 0 Healthy 4 (15000)
40 Dog (Bulldog) 4 Healthy 4 (21468)
41 Bird (Hahn's Macaw) 17 Healthy 0 (0 ) Wound cleaning
42 Cat (Maine Coon) 20 Critical 3 (7167 )
44 Bird (Hahn's Macaw) 27 Poor 2 (5282 )
45 Dog (Bulldog) 18 Healthy 4 (19780)
46 Rabbit (English Lop) 23 Poor 4 (16288)
47 Reptiles (Hamster) 4 Critical 3 (16623)
49 Dog (Beagle) 9 Healthy 2 (6250 )
=========================================================================
============================
Page 2
Enter < or > to go to previous or next page (enter anything else to exit)
>
ID Species (Breed) Age Health Condi... Vaccines Taken Special Needs
=========================================================================
============================
50 Reptiles (Ball Python) 19 Healthy 0 (0 )
51 Dog (German Shepherd Dog) 6 Healthy 4 (16736)
52 Reptiles (Guinea pig) 18 Healthy 1 (1032 )
54 Bird (Green-Cheeked Conure) 9 Healthy 3 (9069 )
55 Dog (Siberian Huskey) 16 Healthy 1 (2030 )
56 Rabbit (N/A) 28 Healthy 1 (1287 )
57 Rabbit (Dutch) 28 Healthy 0 (0 )
59 Dog (Bulldog) 3 Healthy 2 (1822 )
60 Rabbit (English Angora) 28 Healthy 2 (4172 ) Antibacterial medicine
61 Bird (Cockatoo) 12 Healthy 0 (0 ) Ear cleaning (infected)
62 Cat (Siamese) 10 Healthy 5 (19615)
64 Cat (Maine Coon) 7 Healthy 4 (7008 )
65 Dog (Bulldog) 14 Healthy 4 (19996)
66 Cat (Ragdoll) 24 Healthy 4 (17852)
67 Reptiles (Guinea pig) 7 Healthy 0 (0 )
69 Dog (German Shepherd Dog) 0 Healthy 0 (0 )
70 Rabbit (Dutch) 8 Healthy 4 (23424) Hand feeding
71 Reptiles (Crested Gecko) 2 Healthy 2 (2810 )
72 Cat (Ragdoll) 8 Bad 0 (0 ) Antibacterial medicine
74 Reptiles (Crested Gecko) 20 Healthy 0 (0 )
=================================