Question: Create a template class (LinkedList.h) that declares a singly-linked list. This template class should be able to create a linked list of any type of
Create a template class (LinkedList.h) that declares a singly-linked list. This template class should be able to create a linked list of any type of object. LinkedList class should have the following attributes: A structure (struct) ADT named ListNode, which defines a node with a value & a pointer to the next ListNode. A pointer to a ListNode named head A pointer to a ListNode named tail An integer named numNodes LinkedList class should have the following member functions: Constructor should initialize head & tail to point to nothing and initialize numNodes to zero Destructor like a RemoveAll function should deallocate memory for all existing nodes getLength should return the number of nodes in the list getNodeValue this function accepts a position (integer) as a parameter and then returns the value (object) inside the node at that position appendNode this function accepts a value (object) as a parameter. It creates a new node at the end of the list with the sent object inside of it and increments the number of nodes. This function does not return anything. deleteNode this function accepts a position (integer) as a parameter, which indicates the position of the node to be deleted. It updates the links of the nodes on either side of this node to be deleted. Then it deletes the node. Then, it decrements the number of nodes. CREATURE (CREATURE.H & CREATURE.CPP) Create a class specification (Creature.h) & class implementation (Creature.cpp) file for a class named Creature. The purpose of the Creature class is to allow for creation of a Creature object. Creature should have the following attributes: The creatures name (string) A description of the creature (string) The cost (float) of the creature (per month) to care for it (food, grooming, destruction, etc) A boolean representing whether the creature is dangerous or not (1 means true it is dangerous and 0 means false, it is not dangerous) Creatures should have the following member functions: Constructor default constructor (doesnt have to have anything inside it) Constructor with parameters string, string, bool, & float should initialize the creatures attributes Accessor functions o getName o getDescription o getDangerous o getCost Mutator functions o setName o setDescription o setDangerous o setCost printCreature a function to print a single creatures information to the screen in a nice, easy to read format printCreatureToFile a function to print a single creatures information to the file unformatted one piece of information per line. This is so the program would be able to read the creatures information back later. ZOO.CPP This is the driver. This file should have a main function and several other functions to organize or help the main function as described below: main This function should create a creature linked list, based on the LinkedList template class you create. Then it should display a menu of four options until the user chooses option 4, which is to end the program. Look at sample output to see the flow of the program. o If user chooses option 1, then a sub-menu should be shown to ask user if they want to enter creatures manually or from file. If manually, then the enterMagicalCreature function should be called, sending the address of the creatureList to this function. If from a file, then the enterMagicalCreatureFromFile function should be called, sending the address of the creature list to this function. o If user chooses option 2, then the deleteCreature function should be called, sending the address of the creature list to this function. o If user choses option 3, then the printCreatures function should be called, sending the address of the creature list to this function. o If user chooses option 4, then the program should ask the user if they want to save their creature list to a file. If user chooses yes, then call the saveCreaturesToFile function, sending the creature list to this function. Print GOODBYE! before the program ends. enterMagicalCreature this function should ask the user for the creatures name, description, if it is dangerous, and the cost per month to care fo rhte creature. Then it should create a new creature object with this data. Then, it should append the creature object to the linked creature list. Then it should print a confirmation that the creature (print creatures name) has been added to the zoo. The function should then ask the user if they want to add more creatures. If they answer yes, then repeat this process. Otherwise, the function should end and it doesnt return any data. enterMagicalCreatureFromFile this function should ask the user for the name of the file they want to read from. Then, if the file is able to be opened (print a message if cant be opened) then read the creature data from the file (one at a time) with a loop and after reading in one creature, create a new creature object with this data, then append the creature to the creature linked list. After reading all the creatures from the file & adding them to the linked list, print how many creatures FROM THE FILE were added to the zoo. This may or may not be the current number of creatures in the linked list! This function does not return any data. deleteCreature this function should first print a numbered list of the names of all the creatures in the linked list. Then ask the user which creature number they want to delete. Then the creature should be removed from the linked list. A confirmation should be printed out that the creature was removed. This function does not return anything. printCreatures this function should print THERE ARE NO CREATURES AT YOUR ZOO! if there are no creatures in the linked list. If there are creatures in the linked list then it should print each creatures detail in the list. This function does not return anything. saveCreaturesToFile this function should either print THERE ARE NO CREATURES AT YOUR ZOO! if there are no creatures in the linked list. If there are creatures in the linked list then it should ask the user for the filename that they wish to use to save the creatures and then use a loop to get a creature from each node, and then call this creatures printCreatureToFile function, sending the filename to the function.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
