Description
Adventure time cast
Write your own version of a Binary Tree class template that can hold values of any data type. Name this file BinaryTree.h. (more details about this class in the BINARYTREE.H section of this document)
Then, create a class for an Adventure Time cast member called AT_Cast class that holds a cast member’s cast ID and their name. Name this file AT_Cast.h. (more details about this class in the AT_CAST.H section of this document)
Next, use the provided driver which creates a binary tree whose nodes hold an AT_Cast object. The nodes should be sorted on the CAST ID number. The driver will print out the cast (sorted by cast ID number) in three different ways – in-order traversal, pre-order traversal, and then post-order traversal.
BinaryTree.h
This should be a template class which contains the following private & public members:
Private attributes & functions
- TreeNode struct containing a value of the template type, a pointer to the left TreeNode and a pointer to the right TreeNode
- A pointer to the root TreeNode
- Private functions:
- Insert
- destroySubTree
- displayInOrder
- displayPreOrder
- displayPostOrder
Public Functions
- Constructor
- Destructor (which should call destroySubTree)
- insertNode (which should call the insert function)
- displayInOrder (should call the displayInOrder private function)
- displayPreOrder (should call the displayPreOrder private function)
- displayPostOrder (should call the displayPostOrder private function)
AT_Cast.h
AT_Cast class should hold the following (private) Adventure Time information:
- Cast ID Number: an integer
- Cast Member Name: a string
This class should also implement the following public functions:
- Constructor (setting the id & name) – use default arguments for the parameters; setting id to zero and name to “None”
- setID
- setName
- getID
- getName
- overloaded < operator (code & explanation below)
- overloaded << operator (code & explanation below)
Overloaded Operators
You will need two overloaded operators for the AT_Cast. You will need to overload the relational “less than” operator ‘<’ and also the stream insertion operator ‘<<’. I have given you the code below.
bool operator < (const AT_Cast& member)
{
return this->castID < member.castID;
}
friend ostream &operator << (ostream &strm, AT_Cast &member)
{
strm << “Cast ID Number: ” << member.castID;
strm << “\tName: ” << member.name << endl;
return strm;
}
Driver.cpp
The driver is provided and adds the following Adventure Time cast members:
Cast ID Number |
Name |
1021 |
Finn |
1057 |
Jake |
2486 |
Ice King |
3769 |
Princess Bubblegum |
1017 |
Lumpy Space Princess |
1275 |
Cinnamon Bun |
1899 |
Peppermint Butler |
4218 |
Marceline |
1214 |
BMO |
Sample Output
Here are the cast members of Adventure Time:
IN ORDER TRAVERSAL———————————————-
Cast ID Number: 1017 Name: Lumpty Space Princess
Cast ID Number: 1021 Name: Finn
Cast ID Number: 1057 Name: Jake
Cast ID Number: 1214 Name: BMO
Cast ID Number: 1275 Name: Cinnamon Bun
Cast ID Number: 1899 Name: Peppermint Butler
Cast ID Number: 2486 Name: Ice King
Cast ID Number: 3769 Name: Princess Bubblegum
Cast ID Number: 4218 Name: Marceline
PRE ORDER TRAVERSAL———————————————-
Cast ID Number: 1021 Name: Finn
Cast ID Number: 1017 Name: Lumpty Space Princess
Cast ID Number: 1057 Name: Jake
Cast ID Number: 2486 Name: Ice King
Cast ID Number: 1275 Name: Cinnamon Bun
Cast ID Number: 1214 Name: BMO
Cast ID Number: 1899 Name: Peppermint Butler
Cast ID Number: 3769 Name: Princess Bubblegum
Cast ID Number: 4218 Name: Marceline
POST ORDER TRAVERSAL———————————————-
Cast ID Number: 1017 Name: Lumpty Space Princess
Cast ID Number: 1214 Name: BMO
Cast ID Number: 1899 Name: Peppermint Butler
Cast ID Number: 1275 Name: Cinnamon Bun
Cast ID Number: 4218 Name: Marceline
Cast ID Number: 3769 Name: Princess Bubblegum
Cast ID Number: 2486 Name: Ice King
Cast ID Number: 1057 Name: Jake
Cast ID Number: 1021 Name: Finn
What to turn in
Place driver.cpp, BinaryTree.h, & AT_Cast.h in a zipped folder and upload to ilearn submission folder.