Menu

[Solved]-Using Binary Tree Provided Textbook Create Class Called Date Class Following Data Members Q37163626

Using the binary tree provided in the textbook.

Create a class called Date. The class will have the followingdata members

  • day as integer
  • month as integer
  • year as integer

Methods needed

  • Accessors and mutators
  • Able to print date in the format January 1, 2018

Create a class called Person. This class will have the followingdata members (protected)

  • name as string
  • address as string
  • city as string
  • state as string
  • phone as string

It will have accessor and mutators for the data members.

Create a class called EmployeeInfo which inherits from thePerson class. This class will have the following data members(private).

  • id as integer
  • hireDate as Date (first class listed)
  • empInfo as Person

It will have accessor and mutators for the data members

Main should show that all the methods in the binary tree workwith the EmployeeInfo class. Show that all methods work. Allow theprogram to prompt the user for an ID to search for. If the ID isfound then all the information about the employee should bedisplayed (All data in EmployeeInfo, Person and Date). If employeeis not found display a message telling the user that the persondoes not exist.

Program should continue until the user indicates they aredone.

All classes should be in their own files (both h and cpp). Notall implementation in the header file.

Add at least 10 employees to the tree. You do not need to askthe user for the information.

Add all needed operators to allow the program to work. Thebinary tree should not be changed so that it directly knows aboutthe employee info class.

BinaryTree.h

template <class T>class BinaryTree{ private: TreeNode* root; // Address of root node void Insert(TreeNode* nodePtr, TreeNode newNode); void DeleteNode(T value, TreeNode* nodePtr); void DisplayInOrder(TreeNode* nodePtr); void DisplayPreOrder(TreeNode* nodePtr); void DisplayPostOrder(TreeNode* nodePtr); void DestroyNode(TreeNode* nodePtr); void DestroySubTree(TreeNode* nodePtr); public: BinaryTree(); ~BinaryTree(); void InsertNode(T value); void RemoveNode(T value); void DisplayInOrder(); void DisplayPreOrder(); void DisplayPostOrder();};

BinaryTree.cpp

#include “BinaryTree.h”
template <class T>
BinaryTree::~BinaryTree()
{
DestroySubTree(root);
}

template <class T>
BinaryTree::DestroySubTree(TreeNode* nodePtr)
{
if (nodePtr != nullptr)
{
if (nodePtr->left != nullptr)
DestroySubTree(nodePtr->left);
if (nodePtr->right != nullptr)
DestroySubTree(nodePtr – Right);

delete nodePtr;
}
}
template <class T>
void BinaryTree::Insert(T value)
{
TreeNode* newNode = new TreeNode;
newNode->value = value;
newNode->left = newNode->right = nullptr;

InsertNode(root, newNode);
}

template <class T>
void BinaryTree::InsertNode(TreeNode* &nodePtr, TreeNode*&newNode)
{
if (nodePtr == nullptr)
nodePtr = newNode;
else if (newNode->value < nodePtr->value)
InsertNode(nodePtr->left, newNode);
else
InsertNode(nodePtr->right, newNode);
}
template <class T>
void BinaryTree::Remove(T value)
{
DeleteNode(value, root);
}
template <class T>
void BinaryTree::DeleteNode(T value, TreeNode* &nodePtr)
{
if (nodePtr != nullptr)
{
if (value < nodePtr->value)
DeleteNode(value, nodePtr->left);
else if (value > nodePtr->value)
DeleteNode(value, nodePtr->right);
else
DestroyNode(nodePtr);
}
}
template <class T>
void BinaryTree::DestroyNode(TreeNode* &nodePtr)
{
TreeNode* tempNode = nullptr;

if (nodePtr != nullptr)
{
if (nodePtr->right == nullptr)
{
tempNode = nodePtr;
nodePtr = nodePtr->left;
}
else if (nodePtr->left == nullptr)
{
tempNode = nodePtr;
nodePtr = nodePtr->right;
}
else
{
tempNode = nodePtr->right;

while (tempNode->left != nullptr)
tempNode = tempNode->left;

tempNode->left = nodePtr->left;
tempNode = nodePtr;

nodePtr = nodePtr->right;

}

delete tempNode;
}
}
template <class T>
void BinaryTree::DisplayInOrder()
{
DisplayInOrder(root);
}

template <class T>
void BinaryTree::DisplayInOrder(TreeNode* nodePtr)
{
if (nodePtr != nullptr)
{
DisplayInOrder(nodePtr->left);
cout << nodePtr->value << endl;
DisplayInOrder(nodePtr->right);
}
}
template <class T>
void BinaryTree::DisplayPreOrder()
{
DisplayPreOrder(root);
}

template <class T>
void BinaryTree::DisplayPreOrder(TreeNode* nodePtr)
{
if (nodePtr != nullptr)
{
cout << nodePtr->value << endl;
DisplayPreOrder(nodePtr->left);
DisplayPreOrder(nodePtr->right);
}
}
template <class T>
void BinaryTree::DisplayPostOrder()
{
DisplayPostOrder(root);
}

template <class T>

void BinaryTree::DisplayPostOrder(TreeNode* nodePtr)
{
if (nodePtr != nullptr)
{
DisplayPreOrder(nodePtr->left);
DisplayPreOrder(nodePtr->right);
cout << nodePtr->value << endl;
}
}

TreeNode.h

template <class T>
class TreeNode
{
T data;
TreeNode* left;
TreeNode* right;

TreeNode(T val):data(val),left(NULL),right(NULL)
{
}
};

TreeNode.cpp

#include “TreeNode.h”
TreeNode::TreeNode()
{
   num;
*left;
*right;
}

TreeNode::TreeNode(int num)
{
   num = num;
   node *left;
   node *right;
}

Expert Answer


Answer to Using the binary tree provided in the textbook. Create a class called Date. The class will have the following data membe… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *