Starting Out with C++ from Control Structures to Objects (8th Edition)
8th Edition
ISBN: 9780133769395
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 20, 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Binary Trees (C++)
You will create a class for Emploveelnfo that contains:
• Employee ID Number – int
Employee Name – string
Implement a binary tree whose nodes hold an instance of your Emploveelnfo class. The nodes
should be sorted on the Employee ID number. You will have a binary tree class header and
implementation file.
You can write your main to use the following information to test your tree:
Employee Name
James B W Bevis
Employee ID Number
6702
Romney Wordsworth
Revis Jacara
Clegg Forbes
Kalin Tros
1255
1071
2390
1558
7406
Archibald Beechcroft
Penthor Mul
Bartlet Finchley
7562
3004
4922
Latham Bine
8483
Jeff Myrtlebank
Your program should read an employee ID and display a message telling the user whether it was
found in the tree or not. Your main will have one binary tree object and all of the operations on
the binary tree will be class methods.
Other functions to add
• Add function to display the tree
• Allow user to add a new employee
• Allow user to remove an employee
NOTE –…
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)
Ex1. DLL2BST
Add a constructor that constructs the binary search tree from the given DLList.
BST<T>::BST(const DLL<T>& list)
Chapter 20 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Ch. 20.1 - Prob. 21.1CPCh. 20.1 - Prob. 21.2CPCh. 20.1 - Prob. 21.3CPCh. 20.1 - Prob. 21.4CPCh. 20.1 - Prob. 21.5CPCh. 20.1 - Prob. 21.6CPCh. 20.2 - Prob. 21.7CPCh. 20.2 - Prob. 21.8CPCh. 20.2 - Prob. 21.9CPCh. 20.2 - Prob. 21.10CP
Ch. 20.2 - Prob. 21.11CPCh. 20.2 - Prob. 21.12CPCh. 20 - Prob. 1RQECh. 20 - Prob. 2RQECh. 20 - Prob. 3RQECh. 20 - Prob. 4RQECh. 20 - Prob. 5RQECh. 20 - Prob. 6RQECh. 20 - Prob. 7RQECh. 20 - Prob. 8RQECh. 20 - Prob. 9RQECh. 20 - Prob. 10RQECh. 20 - Prob. 11RQECh. 20 - Prob. 12RQECh. 20 - Prob. 13RQECh. 20 - Prob. 14RQECh. 20 - Prob. 15RQECh. 20 - Prob. 16RQECh. 20 - Prob. 17RQECh. 20 - Prob. 18RQECh. 20 - Prob. 19RQECh. 20 - Prob. 20RQECh. 20 - Prob. 21RQECh. 20 - Prob. 22RQECh. 20 - Prob. 23RQECh. 20 - Prob. 24RQECh. 20 - Prob. 25RQECh. 20 - Prob. 1PCCh. 20 - Prob. 2PCCh. 20 - Prob. 3PCCh. 20 - Prob. 4PCCh. 20 - Prob. 5PCCh. 20 - Prob. 6PCCh. 20 - Prob. 7PCCh. 20 - Prob. 8PC
Knowledge Booster
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
- Tree.java: This is a simple binary tree class that should be used to represent the data in your Huffman tree. You only need to implement two of the methods (_printTree and compareTo). Huffman.java: This file contains all of the logic required to implement a Huffman tree. The code in this file relies on the Tree.java file. You must provide the implementation for all of the methods in this class. public class Main { /* * tree.txt should produce this tree: * 16 * / \ * 6 Z * / \ * A D * * A (1), D (5), Z (10) * * Codes: * A: 00 * D: 01 * Z: 1 * * Preorder Traversal: * 16, 6, 1 (A), 5 (D), 10 (Z) */ public static void main(String[] args) throws Exception { Huffman huff = new Huffman(); huff.buildTreeFromFile("tree.txt"); // Print the tree: System.out.println("printTree tests:"); huff.printTree(); // Expected output: [16: , 6: , 1:A, 5:D, 10:Z] // Get some codes:…arrow_forwardB. Project descriptionFor this project, you will create two ADTs:• A generic ADT Binary Search Tree• An ADT Class database: This ADT contains a list of class sections. Therefore, a class representing a class sectionmust be created.arrow_forwardBook{ AvlNode{ AvlTree{String title Book insert()int ID int height printTree()String author AvlNode left height()double price AvlNode right max()} } }From your understanding of AVL trees, implement the four different types of rotations and node swoping inside AvlTree.java; each question must be completed with inline Javadoc and/or comments:1. rotRight(AvlNode someNode) and returns AvlNode.2. rotLeft(AvlNode someNode) and returns AvlNode.3. doubleRotLeft(AvlNode someNode) and returns AvlNode. 4. doubleRotRight(AvlNode someNode) and returns AvlNode. 5. Complete a driver code under the main methodarrow_forward
- Get the Longest Path Write a member function called DLList BST:: get longest_path() that returns a DLL of the longest path in the tree. For example, the red nodes in the following tree are on the longest path and should be added to the list. In case there are multiple longest paths, retrieve any of them.arrow_forwardPython binary search tree: a function that takes in a root, p, and checks whether the tree rooted in p is a binary search tree or not. What is the time complexity of your function? def is_bst(self, p: Node):arrow_forwardGiven Code: #include<iostream>#include<queue> struct treeNode{ char dataItem; struct treeNode *firstChild; struct treeNode *nextSibling;}; /* Preorder Traversalpreorder (v)visit(v)for each child w of vpreorder(w)*/void preorder(treeNode *currNode){ if(currNode != NULL){ std::cout << currNode->dataItem << " "; preorder(currNode->firstChild); preorder(currNode->nextSibling); } return;} /* Postorder Traversalpostorder (v)for each child w of vpostOrder(w)visit(v)*/void postorder(treeNode *currNode){ if(currNode != NULL){ preorder(currNode->firstChild); preorder(currNode->nextSibling); std::cout << currNode->dataItem << " "; } return;} /*Inorder Traversalif(v==NULL) returninOrder(v.left)visit(v)inOrder(v.right)*/void inorder(treeNode *currNode){ if(currNode != NULL){ inorder(currNode->firstChild); std::cout << currNode->dataItem…arrow_forward
- struct insert_into_bst { // Function takes a constant Book as a parameter, inserts that book indexed by // the book's ISBN into a binary search tree, and returns nothing. void operator()(const Book& book) { // // TO-DO (7) ||| ///// // Write the lines of code to insert the key (book's ISBN) and value // ("book") pair into "my_bst". END-TO-DO (7) | } std::map& my_bst; };arrow_forwardAssignment 4 The goal of this assignment is to write a Java program that finds the lowest common ancestor of two nodes in a binary tree. To accomplish this goal, you will have to implement a program that allows the user to ask for two letters on the tree shown below, and finds the lowest common ancestor of those two nodes in the tree.arrow_forwardin c++ Assume that you have a binary search tree. Write a function that counts the number ofelements in the tree that are less than 15 and prints the result. You write only the func-tion, you do not need to test it.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education