Binary Search Tree. Code ( in .txt ): [ http://goo.gl/ctUVso ] Write a program t
ID: 3685943 • Letter: B
Question
Binary Search Tree.
Code (in .txt): [http://goo.gl/ctUVso]
Write a program that a company can use to keep up with the efficiency of its employees. The company keeps a record of mistakes made by each employee. If five mistakes are made by an employee, the employee is fired. The company has a maximum of 20 employees. Each employee has a unique identification number between 10 and 40. An employee is represented by an ID number and a counter to count the number of mistakes that the employee has made. Write a program to simulate this process by using the following guide lines. 1.Allow your program to randomly generate the identifications for each employee between 10 and 30. 2.The first time an identifications number is generated the person is lured with a count of zero mistakes. 3.If the same identification number is generated again, increment the counter for the employee's mistakes. 4.Once the person makes 5 mistakes fire the person. 5.Use binary search trees to keep up with the employees. 6.A person is hired by placmg the information about the person (identification number and zero mistakes) on an employee binary search tree. 7.A person is fired by removing the information about the person from the employee binary search tree and placing the information on a fired binary search tree. 8.Both binary search trees are ordered by the employee's identification number. 9.Allow your program to randomly generate ID numbers 100 times. (Use the C++ randO function) Output: Your program should do the following: -Print out a numerically ordered list of all identification numbers of employees along with the number of mistakes of each employee from the employee binary search tree. -Remove all employees from the employees binary search tree with 5 or more mistakes -Print out the content of the employees binary search tree after the fired employees have been removed. -Print out a numerically ordered list of the identification numbers of the fired employees along with the number of mistakes for each employee on the fired binary search tree. Use one of the following definitions for your binary search tree:Explanation / Answer
---------------------------------------================================----------------------------------==============
class node
{ friend class BinarySearchTree;
private:
int ID;
int counter;
node * leftchild;
node * rightchild;
};
class BinarySearchTree
{public:
BinarySearchTree();
bool empty(); //return true if the tree is empty, otherwise return false
bool Insert(int IdNum);//insert a new employee with ID number IdNum
bool IsThere (int Id); //return true if Id is in the tree, else return false
void Delete(int IdNum); //if value IdNum is in the tree, remove it
void Display();//Display the data from smallest to largest based on ID number
private:
node * root;//pointer to the root node
};
/* The following definition for the binary search tree using a struct to hold the two values: */
struct employee{
int ID;
int counter;
};
typedef employee ElementType;
class node
{
friend class BinarySearchTree;
private:
ElementType data;
node * leftchild;
node * rightchild;
};
class BinarySearchTree
{
public:
BinarySearchTree();
bool empty(); // return true if the tree is empty, otherwise return false
bool Insert(ElementType x);//insert a value x
bool IsThere (ElementType x);
//return true if x is in the tree, otherwise return false
void Delete(ElementType x); //if value x is in the tree, remove x
void Display();
//Display the data stored from smallest to largest based on ID number
private:
node * root;//pointer to the root node
};
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.