Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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.
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 –…
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
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;
};
Chapter 19 Solutions
Starting Out with C++: Early Objects (9th Edition)
Ch. 19.1 - Prob. 19.1CPCh. 19.1 - Prob. 19.2CPCh. 19.1 - Prob. 19.3CPCh. 19.1 - Prob. 19.4CPCh. 19.1 - Prob. 19.5CPCh. 19.1 - Prob. 19.6CPCh. 19.2 - Prob. 19.7CPCh. 19.2 - Prob. 19.8CPCh. 19.2 - Prob. 19.9CPCh. 19.2 - Prob. 19.10CP
Ch. 19.2 - Prob. 19.11CPCh. 19.2 - Prob. 19.12CPCh. 19 - Prob. 1RQECh. 19 - Prob. 2RQECh. 19 - Prob. 3RQECh. 19 - Prob. 4RQECh. 19 - Prob. 5RQECh. 19 - Prob. 6RQECh. 19 - Prob. 7RQECh. 19 - Prob. 8RQECh. 19 - Prob. 9RQECh. 19 - Prob. 10RQECh. 19 - Prob. 11RQECh. 19 - Prob. 12RQECh. 19 - Prob. 13RQECh. 19 - Prob. 14RQECh. 19 - Prob. 15RQECh. 19 - Prob. 16RQECh. 19 - Prob. 17RQECh. 19 - Prob. 18RQECh. 19 - Prob. 19RQECh. 19 - Prob. 20RQECh. 19 - Prob. 1PCCh. 19 - Prob. 2PCCh. 19 - Prob. 3PCCh. 19 - Prob. 4PCCh. 19 - Prob. 5PCCh. 19 - Prob. 6PCCh. 19 - Prob. 7PCCh. 19 - Prob. 8PCCh. 19 - Prob. 9PCCh. 19 - Prob. 10PC
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
- In C++arrow_forwardNetBeansarrow_forwardOffline 3 Binary Search Tree Implementation Prepared by: Shoumik Saha 1. Find the given code of Binary Search Tree from our class. 2. Use it for the offline. Don't change anything that is already given, but you can add something (variable or function) if you need. 3. Implement these functions a. tree_successor b. tree_delete 4. You can check your code by experimenting with different values. Menu for successor and delete function is already added in the main function. *There will be a penalty for any late submission. **Any plagiarism will result in negative marking. ***TRY YOURSELF N.B.: 1. Follow the given slide for better understanding. 2. There willI be online on Binary Search Tree in the next lab class. ןןןןarrow_forward
- Program 3: Binary Search Tree Program Objective The primary objective of this program is to learn to implement binary search trees and to combine their functionalities with linked lists. Program Description In a multiplayer game, players' avatars are placed in a large game scene, and each avatar has its information in the game. Write a program to manage players' information in a multiplayer game using a Binary Search (BS) tree for a multiplayer game. A node in the BS tree represents each player. Each player should have an ID number, avatar name, and stamina level. The players will be arranged in the BS tree based on their ID numbers. If there is only one player in the game scene, it is represented by one node (root) in the tree. Once another player enters the game scene, a new node will be created and inserted in the BS tree based on the player ID number. Players during the gameplay will receive hits that reduce their stamina. If the players lose all their stamina, they vanish from the…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_forwardBinary Search Tree Empirical and Theoretical ResultsPart 1: we need to define a binary search tree data structure. Also, we need to implement the following functions:1. Insert Sorted: BSTREE insert(BSTREE root, int num): root points to a node in a binary search tree; num is a number to be inserted in the tree rooted at “root”. This function returns the root of the modified tree.2. Print Elements: void inorder traversal(BSTREE root, FILE *fp): root points to a node in a binary search tree. This function does not return anything, but prints out, to the file specified, the nodes in the tree rooted at “root” by performing an inorder traversal. Part 2: Test the performance of the designed data structure using theoretical and experimental approaches as follows:1. Dataset 1-Dataset is sorted- Add code to insert the numbers 1...n in that order in an initially empty doubly linked list and a binary search tree.a. Run it on different values of n where :i. n = 20,000ii. n = 50,000iii. n =…arrow_forward
- Programming Language: C Programming 1. Make a code of implementation of the Binary Tree program and explain each line on how it works NOTE: it's Binary Tree , NOT Binary Search Treearrow_forwarddata structure-JAVAarrow_forwardBinary search tree. Write a function named totalSum that takes as parameter the root of the binary search tree(with the following type) and returns the total sum of the numbers in the tree. struct tree{ int data; struct tree *left, *right; };arrow_forward
- The operation of processing each element in the structure is known as: Sorting Searching Inserting Traversalarrow_forwardA Dictionary implementation using Binary Search Trees Program requirements and structure You should be able to do the following: Add dictionary entries Search for an entry Print the whole dictionary You will be using the .compareTo method from the String class in order to move through your tree. Recursive method to print the tree in inorder traversal (you need little mods below code) public void printTree(Node root){ if(root != null){ printTree(root.getLeftChild()); System.out.println(root.toSting( )); printTree(root.getRightChild()); } } Instructions: Please use CODE TEMPLATE!arrow_forwardGet 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_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