Question: Note: I am coding in C++ Here is list.cpp: #define _LIST_CPP #include list.h #include animal.h #include // // In the `List` class, complete the `adopt`

Note: I am coding in C++
Here is list.cpp:
#define _LIST_CPP
#include "list.h"
#include "animal.h"
#include
//
// In the `List` class, complete the `adopt` member function in `list.cpp`.
// The `adopt` function must:
//
// 1. find the animal closest to the head of the list that meets the given
// preferences (if a suitable animal exists),
// 2. remove that node from the list, and
// 3. return a pointer to the `Animal` (if a suitable animal was found) **or**
// `NULL` if no animal was found
//
template
const Animal *List
//your code here
}
while(temp->next != NULL) {
if (willAdoptCats) {
temp2->next = temp->next;
temp->next = NULL;
//return Animal;
} else {
temp = temp->next;
temp2 = temp2->next;
}
}
return NULL;
}
template
List
this->head = NULL;
}
template
void List
ListNode* node = new ListNode(ndata);
node->next = head;
this->head = node;
}
Consider an animal shelter that contains two types of animals: dogs and cats. A dog is represented by the Dog class, a cat is represented by a Cat class, and both classes inherit the Animal class. The animal shelter maintains a singly list of all the animals (nodes with an Animal * pointer that points to the Animal). When you want to adopt an animal from this shelter, you let them know your preference for a dog, cat, or either. Based on your preference, you adopt the animal closest to the head of the list that matches your preference. In the List class, complete the adopt member function in list.cpp The adopt function must: 1. find the animal closest to the head of the list that meets the given preferences (if a suitable animal exists), 2. remove that node from the list, and 3. return a pointer to the Animal (if a suitable animal was found) or NULL if no animal was found The List class (list.cpp, list.h) stores a singly linked list of List Node nodes, using the same structure and variable names as MP3. The Animal class has a member function getType() that will return "Dog" or "Cat" based on the type of animal. A complete Makefile and tester code is provided for you. To compile and test, run: make ./animal-test
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
