Artifact 2: Algorithms and Data Structures
Original Artifact: Grazio Rescue Animal Service
For this second artifact, the original project was from an early course I was attending at SNHU: IT-145
Foundations in Computer Programming. The purpose of the project was to create an command line
application in Java that could be used to input rescue animals into an array list. It consisted of three
data classes:
-
RescueAnimal - Parent class
-
Monkey - Child of RescueAnimal
-
Dog - Child of RescueAnimal
This project was an excersice in learning inheritance and object manipulation.
View Project on GitHub
Narrative Describing Artifact and Planned Enhancements
1. Briefly describe the artifact. What is it? When was it created?
For category 2 I chose the Final Project from IT-145. The project was for a Rescue Animal Service that
developed a Java program to manage different rescue animals for a made up customer. It consisted of 4
files and was mainly focused on inheritance. The project had a Parent Rescue Animal class and two child
classes, Dog and Monkey. It also had a driver class for managing the lists of Rescue Animals, and stored
them in separate arrays. To access these lists the program would iterate through the entire list to find
the specific animal the customer needed to look for.
2. Justify the inclusion of the artifact in your ePortfolio.
I chose this project to include in my portfolio to show off how much I have grown over the year or so
since I developed the initial project. The initial project was focused on data access through getters
and setters, saving the data into arrays and linear retrieval. I decided it would benefit from the
implementation of a Binary Search Tree data structure that would speed up retrieval times. I also
decided to port the program to C++ instead of Java, but this was mainly so I did not have two Java
applications as part of the portfolio.
3. Did you meet the course outcomes?
With this enhancement I feel that I met the course outcome of:
-
Design and evaluate computing solutions that solve a given problem using algorithmic principles and
computer science practices and standards appropriate to its solution, while managing the trade-offs
involved in design choices (data structures and algorithms).
4. Reflect on the process of enhancing and modifying the artifact.
For this enhancement I chose to change the project from Java to C++. One major issue I ran into was that
I thought I remembered C++ a lot more than I truly remembered. It took me a few hours to stop staring at
the screen and remember the syntax and procedures of pointers for this enhancement. Eventually after
much rereading of some of my books, web articles and my previous ZyBooks I was able to remember what I
needed to do to implement a Binary Search Tree and how to manage class definitions, iostream and the
other specifics of C++ I had forgotten, even though I developed a program in C++ just 6 months ago. I
also ran into issues with Visual Studio’s auto complete function. It kept suggesting code that was not
what I wanted and there were a few times that I pressed tab accidentally and added a lot of code that I
did not want. Eventually I shut off the autocomplete “Assistance” and just focused on developing without
it.
View Project on GitHub
Description of the Enhanced Artifact
1. RescueAnimal Struct:
- Serves as the base class for all rescue animals.
- Contains common attributes like animalID, name, age, weight, acquisitionDate, acquisitionCountry,
inServiceCountry, isReserved, animalType (enum: Dog, Monkey, Unknown), gender (enum: Male, Female,
Unknown), and trainingStatus (enum: NotTrained, InTraining, Trained).
- Includes public setter and getter methods for these attributes.
2. Dog Struct:
- Inherits from RescueAnimal.
- Adds a specific attribute: breed.
- Its constructor automatically sets animalType to Dog.
3. Monkey Struct:
- Inherits from RescueAnimal.
- Adds specific attributes: tailLengthInches, bodyLengthInches, heightInches, and species (enum:
Capuchin, Guenon, Macaque, Marmoset, SquirrelMonkey, Tamarin, Unknown).
- Its constructor automatically sets animalType to Monkey.
4. Node Struct:
- Represents a node in the Binary Search Tree.
- Each node holds a RescueAnimal object and pointers to its left and right children.
5. BinarySearchTree Class:
- Manages the collection of RescueAnimal objects using a BST data structure.
- root: Pointer to the root node of the tree.
- Constructor: Initializes the tree and populates it with a few sample dogs and monkeys for
demonstration.
- Destructor: Recursively deletes all nodes in the tree to prevent memory leaks (deleteTree method).
- addNode(Node* node, RescueAnimal animal): Recursively adds a new RescueAnimal to the tree based on
its animalID (lexicographical comparison). It prevents adding animals with duplicate IDs.
- search(const std::string& animalID): Searches for an animal by its ID in the BST. Returns a pointer
to the RescueAnimal if found, nullptr otherwise.
- printAllDogs(Node* node): Performs an in-order traversal to print details of all dogs in the tree.
- printAllMonkeys(Node* node): Performs an in-order traversal to print details of all monkeys in the
tree, including their reservation status.
- printUnreservedAnimals(Node* node): Performs an in-order traversal to print details of all animals
(dogs and monkeys) that are *not* reserved.
- insertDog(Dog dog) / insertMonkey(Monkey monkey): Wrapper methods to easily insert Dog or Monkey
objects into the BST, handling the initial root assignment.
6. RescueAnimalService Class:
- The main service class that orchestrates the application's logic.
- Holds an instance of BinarySearchTree (bst).
- Constructor: Seeds the random number generator (used for animalID generation and sample data).
- Destructor: Deletes the bst object to free memory.
- menu(): Presents a text-based menu to the user, allowing them to:
- Intake new dogs or monkeys.
- Reserve an existing animal.
- Print lists of all dogs, all monkeys, or all unreserved animals.
- Exit the application.
Includes basic input validation.
- printAnimals(int displayType): Calls the appropriate printing method from the BinarySearchTree based
on the displayType (1 for dogs, 2 for monkeys, 3 for unreserved).
- intakeNewAnimal(int animalMenuType): Prompts the user for details to create a new Dog or Monkey
object. It includes extensive input validation for various fields (name, age, weight, dates, gender,
training status, species, dimensions). Once data is collected, it creates the animal object and
inserts it into the BST.
- generateAnimalID(const std::string& name): Creates a unique animal ID by combining the first few
characters of the animal's name with a random number.
- reserveAnimal(): Prompts the user for an animal ID, searches for it, and if found and not already
reserved, sets its isReserved status to true.
7. main() Function:
- The entry point of the program.
- Creates an instance of RescueAnimalService.
- Calls the menu() method to start the interactive service.
Screenshots of Enhanced artifact
The User interface is a basic command line interface. When a new animal is entered into the system it is
inserted into the binary search tree.
RescueAnimal Data Structure
Dog Data Structure, child of RescueAnimal Structure
Monkey Data Structure, child of RescueAnimal Structure
Node Data Structure
Comparison of time taken to find record using BST search vs Linear search.