You will program to process an employment database. The input is a csv file in which the first line is the header and each remaining line describes an employee with his/her ID, name, salary, and the ID of his/her manager. Here is an example:

100,Adam Smith,1000000,0
101,John Nash,200000,100
102,Alan Turing,1500000,100
103,Grace Hopper,100000,102
104,Scarlett O'Hara,180000,101

In this example, line 3 is about John Nash who has ID of 101, salary of $200,000, and is managed by Adam Smith. Adam Smith (in line 2) is the CEO, thus, has no manager, i.e. has ManagerID of 0.
Because the database is large, you want to store it in memory as a binary search tree with ID as the search key.

Task 1. Declare class Employee to store information for an employee.

Task 2. Declare class TreeNode for the nodes of your binary search tree. This class should have the ID of the employee and a pointer to the corresponding Employee object.

Task 3. Implement a function to insert an employee to the binary search tree. Its prototype is:
void insert(TreeNode* &root, Employee* empl)

Task 4. Implement a function to load the employment data from the input file to the binary search tree. Its prototype is:
void load(TreeNode* &root, char* csv)

Question 4.1. What does the binary search tree produced by your function looks like if the previous example is given as input data.

Question 4.2. Rearrange the data in the previous example so that the binary search tree produced by your function is a balanced tree.

Task 5. Implement a function to save the employment data in the binary search tree to the output file. Its prototype is:
void save(TreeNode* root, char* csv)
This function should NOT output the data sorted by emplyeeID (as in the example).

Task 6. Implement a function to search for an employee given his/her ID. Its prototype is:
Employee* search(TreeNode* root, int id)

Task 7. Implement a function to update salary for an employee given his/her ID. Its prototype is:
Employee* updateSalary(TreeNode* root, int id, double salary)
This function should throw an "Invalid salary" if the salary is negative and thow an "Employee not found" if there is no employee with the given ID in the binary search tree.

Task 8. Implement a function to report the name and salary of the CEO.

Task 9. Implement a function to compute the total salary of all employees.

Task 10. Implement a function to report the employee with highest salary (not necessary the CEO).

Task 11. Write a main function to test the previous functions. You could test those functions by the following order:
• Declare an empty TreeNode *tree.
• Call function load (Task 4) to load the data from a csv file.
• Call function insert (Task 3) to insert some new employees.
• Call and output results of function search (Task 6) to search for employees you just insert.
• Call and output results of functions implemented in Task 8, 9, 10.
• Call function updateSalary (Task 7) to update salary of a non-existing employee to catch and print the "Employee not found" exception.
• Call function updateSalary (Task 7) to update salary of an existing employee with a negative salary to catch and print the "Invalid salary" exception.
• Call function updateSalary (Task 7) to update salary of an employee to a very high value.
• Call and output results of function implemented in Task 10 again.
• Call and check results of function save (Task 5).

Hint: For functions require accessing all nodes in the tree (e.g. writing to file like in Task 5, finding a special element like in Task 8, finding the maximal element like in Task 10...) you will need to traverse the tree using pre-order, in-order, or post-order traversal and perform the corresponding operations (e.g. write, compare...) on each node. Sometimes, it might be simpler to have a helper recursive function if you need extra parameters (e.g. to store the maximal element).

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <cstdlib>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iostream>
using namespace std;

class Employee {
    Employee(int id, string name = "", double salary = 0.0, int mId = 0);   
    virtual ~Employee();
    int getID();
    string getName();
    double getSalary();
    int getMID();   
    Employee * deepCopy();
    void setup(string line);
    string toString();
    void setSalary(double salary);
    int id;
    string name;
    double salary;
    int mId;

* constructor
* @param id
* @param name
* @param salary
* @param mId
Employee::Employee(int id, string name, double salary, int mId ){
    this->id = id;
    this->name = name;
    this->salary = salary,
    this->mId = mId;

* destructor
Employee::~Employee() {
$60.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats