Starting Out with C++: Early Objects Plus MyLab Programming with Pearson eText -- Access Card Package (9th Edition)
Starting Out with C++: Early Objects Plus MyLab Programming with Pearson eText -- Access Card Package (9th Edition)
9th Edition
ISBN: 9780134520520
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 19, Problem 8PC
Program Plan Intro

Employee Tree

Program Plan:

BinaryTree.h:

  • Create a template prefix and define the template class BinaryTree to perform the following functions:
    • Declare the required variables.
    • Declare the function prototypes.
    • Define the no-argument generic constructor BinaryTree() to initialize the root value as null.
    • Call the functions insertNode(),displayInOrder(), and searchNode().
    • Define the generic function insert () to insert the node in pointed by the tree node pointer in a tree.
    • Define the generic function insertNode() to create a new node and it is passed inside the insert() function to insert a new node into the tree.
    • Define the generic function searchNode() to search the value in the tree. If it is present, then the function returns a pointer to the value member of the node otherwise it returns false.
    • Define the generic function displayInOrder()to display the values in the subtree pointed by the node pointer.

Employee.h:

  • Create the header file for employee class.
  • Include the required header files.
  • Create the Employee class.
    • Declare the variables.
    • Declare the friend function BinaryTree to pass the instance of employee class nodes.
    • Create the constructor for Employee() class and assign the corresponding variables for employee identification number and name.
    • Define the method setID() to assign the employee ID.
    • Define the method setName() to assign the string to employee name.
    • Define the method getID() to return the value of employee ID.
    • Return the Boolean value using equal operator to check if the returned employee matches with the value.
    • Using friend class return the employee id number and name using stream object.

Main.cpp:

  • Include the required header files.
  • In main() function,
    • Declare the variable.
    • Create the object for BinaryTree.
    • Create the data for employee workers from 1 to 8 individually using the object.
    • Call the function insertNode() to put the employee information into tree.
    • Call the function displayInOrder() to display the tree in order.
    • Prompt the user to enter the employee number.
    • Then call the searchNode() function to search the employee in the tree and assign the information to the pointer.
    • If the pointer is found then print the corresponding message otherwise print the error message.
    • Return the values.

Blurred answer
Students have asked these similar questions
Java Programming Language: 1. Make a class that accepts id numbers ranging from 1 to 29. 2. The id numbers are nodes of a binary tree. 3. Traverse the tree in inorder, preorder, and postorder and display the traversed values.
Cs questions. A binary search tree can be used to store arithmetic expressions. Change the BinarySearchTree class to implement the required operator precedence rules for the evaluation of expressions like 2 + 3 4 / 5.with C++
C++ DATA STRUCTURES Implement the TNode and Tree classes. The TNode class will include a data item name of type string,which will represent a person’s name. Yes, you got it right, we are going to implement a family tree!Please note that this is not a Binary Tree. Write the methods for inserting nodes into the tree,searching for a node in the tree, and performing pre-order and post-order traversals.The insert method should take two strings as input. The second string will be added as a child node tothe parent node represented by the first string. Hint: The TNode class will need to have two TNode pointers in addition to the name data member:TNode *sibling will point to the next sibling of this node, and TNode *child will represent the first child ofthis node. You see two linked lists here??? Yes! You’ll need to use the linked lists
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education