Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 21, 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
Computer Science JAVA Write a program that maintains the names of your friends and relatives and thus serves as a friends list. You should be able to enter, delete, modify, or search this data. You should assume that the names are unique. use a class to represent the names in the friends list and another class to represent the friends list itself. This class should contain a Binary Search Tree of names as a data field. (TreeNode Class BinarySearchTree Class FriendsList Class)
typedef struct node{int data;struct node *left,*right;}BST;The node structure of BST is shown above. Please design an efficient algorithm to return the maximum keyword value in BST. Completion function: int findmax (BST *T)
Multiple choice in data structures void doo(node<int>*root){ if(root !=0) { node<int>*p=root; while(root->next!=0) root=root->next; p->data=root->data; } What is this code do? a. swap the first item with the last item in the linked list b. set the first item in the linked list as the last item c. doesn't do anything because the root parameter is passed by value d. change the root item in the binary tree with the farthest leaf item
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