CSE 240 – Assignment 6 Points: 50 pts Topics: • C/C++ Syntax • Pointers • Functions • Dynamic Allocation of Memory • Data Structures: Linked Lists • Object Orientation Overall Specifications: You are...

1 answer below »
Can you give me a time frame and price for this assignment?


CSE 240 – Assignment 6 Points: 50 pts Topics: • C/C++ Syntax • Pointers • Functions • Dynamic Allocation of Memory • Data Structures: Linked Lists • Object Orientation Overall Specifications: You are to create a Linked List or Binary Search Tree data structure from scratch. This structure should be Templated so that any data could be stored within it. For a maximum of B on specifications – you can make your structure non-templated – meaning it stores only the data required for the problems. The primary goal of this assignment is to make a Linked List that you can use and re-use. The Linked List itself is the majority of the specifications grade. Specifications Scoring Breakdown: Templated Linked List/BST + Problem – 100% of specifications Templated Linked List/BST only – 80% of specifications Untemplated Linked List/BST + Problem – 80% of specifications Untemplated Linked List/BST only – 70% of specifications ** BIG GIANT NOTE – TEMPLATES AND FILES ** When you use a templated type in C++ ALL templated code must be done in the .h file. This means that ALL of your methods will be defined in the .h file as well as your class. You should still forward declare Classes above then Methods below. Your .h file should have your LinkedList/BST class and your Node class and the method definitions for both. Remember to use your :: operator correctly. Feel free to use friendship if needed. Option 1 Zombie Conga Party! - Linked Lists You will create a Linked List Class and a Node Class The Linked List should contain the following methods in its public interface: NOTE: T stands for the template data type, so T data means the variable of type T (whatever T is) • Constructor • Destructor • AddToFront(T data) – create a node containing T data and add it to the front of the list • AddToEnd(T data) – create a node containing T data and add it to the end of the list • AddAtIndex(T data, int index) – create a node containing T data and add it to the list at index. The new node containing the data will be the #index node in the list. Return boolean for success or failure (optional: you could also return an integer with failure codes since this method can fail multiple ways) • RemoveFromFront() – Delete first item and return its contents • RemoveFromEnd() – Delete last item and return its contents • RemoveTheFirst(T data) – find first instance of T data and remove it • RemoveAllOf(T data) – find each instance of T data and remove it • ElementExists(T data) – Returns a T/F if element exists in list • Find(T data) – Look for data in the list, return a pointer to its node • IndexOf(T data) – returns an index of the item in the list (zero-based) • RetrieveFront – returns the data contained in the first node, does not delete it • RetrieveEnd – returns the data contained in the last node, does not delete it • Retrieve(int index) – returns the data contained in node # index, does not delete it, returns null if index is out of bounds or data does not exist • PrintList – Loop through each node and print the contents of the Node • Empty – Empty out the list, delete everything • Length – How many elements are in the list More methods private or public should be created as needed to facilitate the functionality of the Interface methods. If you feel your list needs more functionality, feel free to create it. As per usual, I have not made a perfect representation of the parameters you might need, etc. I have made suggestions where appropriate, but you might need more depending on how you code things. Node Class • Constructor • Destructor • Getters & Setters The node class should be fairly rudimentary. Ideally, it should be templated so you can store anything in it. Description: You are going to create a silly Zombie Conga Line using your Linked List. Each node is going to store a Zombie in it. Zombies can be Red, Yellow, Green, Blue, Magenta and Cyan. Every turn you will randomly generate a Zombie object and an action. You will then perform that action using the Zombie object as the parameter for that action. NOTE – these actions are external to the Linked List. They are accomplished by calling Linked List methods. Actions: • Engine! o This zombie becomes the first Zombie in the conga line • Caboose! o This zombie becomes the last zombie in the conga line • Jump in the Line! o This zombie joins the conga line at position X where X <= length of the linked list • everyone out! o remove all matching zombies from the linked list • you’re done! o remove the first matching zombie from the linked list • brains! o generate two more matching zombies and add one to the front, one to the end and one to the middle. • rainbow brains! o add this zombie to the front, then add one of each zombie color to the end of the conga line. every 5 rounds remove the head zombie and tail zombie. setting up the list: set up the initial conga line by running these actions: 1. run a rainbow brains! action 2. run a random number (between 2 and 5) of brains actions user interface: • ask the user how many rounds they want to run. • then generate that many random actions and fulfill them. • if the conga line ever empties completely due to an action tell the user that the party is over. • once the number of rounds has finished. ask the user if they want to continue the party or end. • if they choose to continue ask them for a new number of rounds to run. output: each round you’ll output the entire linked list. you can represent each zombie as a single character corresponding to their color (r, y, g, b, m, c). have fun, make silly messages and color the output if you like! you’ll show the zombie generated and the action generated. then you’ll show the outcome of the action. spelling it out for you: you should create the following classes: 1. linkedlist 2. node 3. zombie your nodes should store zombies. your linkedlist is made of nodes. hints: build robust constructors and use them! your node and your zombie will benefit highly from good constructors. do yourself a favor and overload the == operator in your zombie. it will make life easier! overload the cout for your zombie. it’ll make your printlist method easier. you might consider making the conga its own class so you can make each of the actions a method in the conga class. extra credit: +2 – color your zombies in the output. sample output: round: 0 the zombie party keeps on groaning! size: 16 :: [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] b zombie jumps in the front of the line! (engine) the conga line is now: size: 17 :: [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] ******************* round: 1 the zombie party keeps on groaning! size: 17 :: [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] m zombie jumps in the front of the line! (engine) the conga line is now: size: 18 :: [m] [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] ******************* round: 2 the zombie party keeps on groaning! size: 18 :: [m] [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] c zombie pulls up the rear! (caboose) the conga line is now: size: 19 :: [m] [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] [c] ******************* round: 3 the zombie party keeps on groaning! size: 19 :: [m] [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] [c] y zombie brought a whole party itself! (rainbow brains!) the conga line is now: size: 26 :: [y] [m] [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] [c] [r] [g] [b] [y] [m] [c] ******************* round: 4 the zombie party keeps on groaning! size: 26 :: [y] [m] [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [m] [c] [g] [m] [r] [c] [r] [g] [b] [y] [m] [c] y zombie brings its friends to the party (brains!) the conga line is now: size: 29 :: [y] [y] [m] [b] [r] [m] [g] [r] [r] [g] [g] [r] [m] [b] [y] [y] [m] [c] [g] [m] [r] [c] [r] [g] [b] [y] [m] [c] [y] ******************* note: you don’t have to use my messages, i just made them on a whim. do however follow my lead and put a label showing what action the message represents. don’t forget to output the list before and after the action. option 2: word frequency analysis – binary search tree you will create a binary search tree class and a node class/struct the binary search tree should contain the following methods in its public interface: • constructor • destructor • insert(t data) – create a node containing t data and add it to the tree (remember: no duplicates) • remove (t data) – find instance of t data and remove it • elementexists(t data) – returns a t/f if element exists in tree • find(t data) – look for data in the list, return a pointer to its node • toarray – create an array from the contents of the tree and return it • empty – empty out the list, delete length="" of="" the="" linked="" list="" •="" everyone="" out!="" o="" remove="" all="" matching="" zombies="" from="" the="" linked="" list="" •="" you’re="" done!="" o="" remove="" the="" first="" matching="" zombie="" from="" the="" linked="" list="" •="" brains!="" o="" generate="" two="" more="" matching="" zombies="" and="" add="" one="" to="" the="" front,="" one="" to="" the="" end="" and="" one="" to="" the="" middle.="" •="" rainbow="" brains!="" o="" add="" this="" zombie="" to="" the="" front,="" then="" add="" one="" of="" each="" zombie="" color="" to="" the="" end="" of="" the="" conga="" line.="" every="" 5="" rounds="" remove="" the="" head="" zombie="" and="" tail="" zombie.="" setting="" up="" the="" list:="" set="" up="" the="" initial="" conga="" line="" by="" running="" these="" actions:="" 1.="" run="" a="" rainbow="" brains!="" action="" 2.="" run="" a="" random="" number="" (between="" 2="" and="" 5)="" of="" brains="" actions="" user="" interface:="" •="" ask="" the="" user="" how="" many="" rounds="" they="" want="" to="" run.="" •="" then="" generate="" that="" many="" random="" actions="" and="" fulfill="" them.="" •="" if="" the="" conga="" line="" ever="" empties="" completely="" due="" to="" an="" action="" tell="" the="" user="" that="" the="" party="" is="" over.="" •="" once="" the="" number="" of="" rounds="" has="" finished.="" ask="" the="" user="" if="" they="" want="" to="" continue="" the="" party="" or="" end.="" •="" if="" they="" choose="" to="" continue="" ask="" them="" for="" a="" new="" number="" of="" rounds="" to="" run.="" output:="" each="" round="" you’ll="" output="" the="" entire="" linked="" list.="" you="" can="" represent="" each="" zombie="" as="" a="" single="" character="" corresponding="" to="" their="" color="" (r,="" y,="" g,="" b,="" m,="" c).="" have="" fun,="" make="" silly="" messages="" and="" color="" the="" output="" if="" you="" like!="" you’ll="" show="" the="" zombie="" generated="" and="" the="" action="" generated.="" then="" you’ll="" show="" the="" outcome="" of="" the="" action.="" spelling="" it="" out="" for="" you:="" you="" should="" create="" the="" following="" classes:="" 1.="" linkedlist="" 2.="" node="" 3.="" zombie="" your="" nodes="" should="" store="" zombies.="" your="" linkedlist="" is="" made="" of="" nodes.="" hints:="" build="" robust="" constructors="" and="" use="" them!="" your="" node="" and="" your="" zombie="" will="" benefit="" highly="" from="" good="" constructors.="" do="" yourself="" a="" favor="" and="" overload="" the="=" operator="" in="" your="" zombie.="" it="" will="" make="" life="" easier!="" overload="" the="" cout="" for="" your="" zombie.="" it’ll="" make="" your="" printlist="" method="" easier.="" you="" might="" consider="" making="" the="" conga="" its="" own="" class="" so="" you="" can="" make="" each="" of="" the="" actions="" a="" method="" in="" the="" conga="" class.="" extra="" credit:="" +2="" –="" color="" your="" zombies="" in="" the="" output.="" sample="" output:="" round:="" 0="" the="" zombie="" party="" keeps="" on="" groaning!="" size:="" 16="" ::="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" b="" zombie="" jumps="" in="" the="" front="" of="" the="" line!="" (engine)="" the="" conga="" line="" is="" now:="" size:="" 17="" ::="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" *******************="" round:="" 1="" the="" zombie="" party="" keeps="" on="" groaning!="" size:="" 17="" ::="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" m="" zombie="" jumps="" in="" the="" front="" of="" the="" line!="" (engine)="" the="" conga="" line="" is="" now:="" size:="" 18="" ::="" [m]="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" *******************="" round:="" 2="" the="" zombie="" party="" keeps="" on="" groaning!="" size:="" 18="" ::="" [m]="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" c="" zombie="" pulls="" up="" the="" rear!="" (caboose)="" the="" conga="" line="" is="" now:="" size:="" 19="" ::="" [m]="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" [c]="" *******************="" round:="" 3="" the="" zombie="" party="" keeps="" on="" groaning!="" size:="" 19="" ::="" [m]="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" [c]="" y="" zombie="" brought="" a="" whole="" party="" itself!="" (rainbow="" brains!)="" the="" conga="" line="" is="" now:="" size:="" 26="" ::="" [y]="" [m]="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" [c]="" [r]="" [g]="" [b]="" [y]="" [m]="" [c]="" *******************="" round:="" 4="" the="" zombie="" party="" keeps="" on="" groaning!="" size:="" 26="" ::="" [y]="" [m]="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" [c]="" [r]="" [g]="" [b]="" [y]="" [m]="" [c]="" y="" zombie="" brings="" its="" friends="" to="" the="" party="" (brains!)="" the="" conga="" line="" is="" now:="" size:="" 29="" ::="" [y]="" [y]="" [m]="" [b]="" [r]="" [m]="" [g]="" [r]="" [r]="" [g]="" [g]="" [r]="" [m]="" [b]="" [y]="" [y]="" [m]="" [c]="" [g]="" [m]="" [r]="" [c]="" [r]="" [g]="" [b]="" [y]="" [m]="" [c]="" [y]="" *******************="" note:="" you="" don’t="" have="" to="" use="" my="" messages,="" i="" just="" made="" them="" on="" a="" whim.="" do="" however="" follow="" my="" lead="" and="" put="" a="" label="" showing="" what="" action="" the="" message="" represents.="" don’t="" forget="" to="" output="" the="" list="" before="" and="" after="" the="" action.="" option="" 2:="" word="" frequency="" analysis="" –="" binary="" search="" tree="" you="" will="" create="" a="" binary="" search="" tree="" class="" and="" a="" node="" class/struct="" the="" binary="" search="" tree="" should="" contain="" the="" following="" methods="" in="" its="" public="" interface:="" •="" constructor="" •="" destructor="" •="" insert(t="" data)="" –="" create="" a="" node="" containing="" t="" data="" and="" add="" it="" to="" the="" tree="" (remember:="" no="" duplicates)="" •="" remove="" (t="" data)="" –="" find="" instance="" of="" t="" data="" and="" remove="" it="" •="" elementexists(t="" data)="" –="" returns="" a="" t/f="" if="" element="" exists="" in="" tree="" •="" find(t="" data)="" –="" look="" for="" data="" in="" the="" list,="" return="" a="" pointer="" to="" its="" node="" •="" toarray="" –="" create="" an="" array="" from="" the="" contents="" of="" the="" tree="" and="" return="" it="" •="" empty="" –="" empty="" out="" the="" list,="">
Answered 1 days AfterApr 21, 2021

Answer To: CSE 240 – Assignment 6 Points: 50 pts Topics: • C/C++ Syntax • Pointers • Functions • Dynamic...

Arun Shankar answered on Apr 22 2021
152 Votes
LinkedList.cpp
#include
#include
using namespace std;
#include "LinkedList.h"
// Constructor
template
LinkedList::LinkedList()
{
    head = nullptr;
    tail = nullptr;
length = 0;
}
// Destructor
template
LinkedList::~LinkedList()
{
    Empty();
}
// AddToFront(T data) – creat
e a node containing T data and add it to the front of the list
template
void LinkedList::AddToFront(T data)
{
Node* newNode = new Node(data);
if(head == nullptr)
head = tail = newNode;
else
{
newNode -> setNext(head);
head = newNode;
}
++length;
}
// AddToEnd(T data) – create a node containing T data and
// add it to the end of the list
template
void LinkedList::AddToEnd(T data)
{
Node* newNode = new Node(data);
if(head == nullptr)
head = tail = newNode;
else
{
tail -> setNext(newNode);
tail = newNode;
}
++length;
}
// AddAtIndex(T data, int index) – create a node
// containing T data and add it to the
// list at index. The new node containing the data will
// be the #index node in the
// list. Return boolean for success or failure (optional:
// you could also return an
// integer with failure codes since this method can fail
// multiple ways)
template
bool LinkedList::AddAtIndex(T data, int index)
{
if((index < 0) || (index > length))
return false;
else if(index == 0)
AddToFront(data);
else if(index == length)
AddToEnd(data);
else
{
Node* newNode = new Node(data);
Node* curr = head;
Node* prev = nullptr;
for(int i = 0; i < index; i++)
{
prev = curr;
curr = curr -> getNext();
}
prev -> setNext(newNode);
newNode -> setNext(curr);
++length;
}
return true;
}
// RemoveFromFront() – Delete first item and return its
// contents
template
void LinkedList::RemoveFromFront()
{
if(head == nullptr)
return;
else if(head == tail)
{
free(head);
head = tail = nullptr;
}
else
{
Node* curr = head -> getNext();
free(head);
head = curr;
}
--length;
}
// RemoveFromEnd() – Delete last item and return its
// contents
template
void LinkedList::RemoveFromEnd()
{
if(head == nullptr)
return;
else if(head == tail)
{
free(head);
head = tail = nullptr;
}
else
{
Node* curr = head;
while(tail != curr -> getNext())
curr = curr -> getNext();
free(tail);
tail = curr;
tail -> setNext(nullptr);
}
--length;
}
// ElementExists(T data) – Returns a T/F if element // exists in list
template
bool LinkedList::ElementExists(T data)
{
Node* curr = head;
while(curr != nullptr)
{
if(data == curr -> getData())
return true;
curr = curr -> getNext();
}
return false;
}
// Find(T data) – Look for data in the list, return a
// pointer to its node
template
Node* LinkedList::Find(T data)
{
Node* curr = head;
while(curr != nullptr)
{
if(data == curr -> getData())
return curr;
curr = curr -> getNext();
}
return nullptr;
}
// IndexOf(T data) – returns an index of the item in the
// list (zero-based)
template
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here