COMP 2012 Object-Oriented Programming and Data Structures

Lab 5 Polymorphism: Virtual Functions

Management System of an IT Corporations

In this lab, you are going to use the dynamic binding feature in C++ to construct a management system in an IT Corporation. The source files are available HERE.

Overview

Although the outbreak of Covid-19 has an impact on the whole society, your corporation is thriving well, thanks to the strong technology. In order to manage the employees in the corporation, the CEO decides to build a management system to manage his employees more efficiently. Now, this task is assigned to you.

Here are some salary guidelines in the corporation:

  • A Technician and Technician Leader is paid according to their base salary plus the number of projects they work on in a month.
  • A Manager is paid by her/his base salary and additional salary depending on the number of employees s/he manages.

  • Description

    There are 4 classes involved: Employee, Manager, Technician, TechnicianLeader. The relationships between them are shown in the following figures. Detailed descriptions for each class can also be found below.

    Note: '+': public; '-': private; '#': protected

    1. Employee

    2. This class is the abstract base class of Manager, Technician, TechnicianLeader. This class contains the information of an employee including the id, name, gender, entry date, post and the salary.

      It has two constructors: Employee() and Employee(int id, const string& name, char gender, const Date& entry_date, string post, Department dept). The former does nothing, while the latter will set all the properties of the employee.

      The destructor ~Employee() should print:

      Resign: Empolyee name
      where name is the employee's name.

      get_name() will return the name of the employee.

      print_salary() should print:

      name : $salary
      where name and salary are the properties of the employee.

      calculate_salary() will calculate and set the salary of the employee based on his duty. This function is a pure virtual function.

      print_description() should print the information of the employee. This function is a pure virtual function.

    3. Manager

    4. This class is derived from Employee. It contains two private members. staffs is an array of employees supervised by this manager. MAX_STAFF_NUM is defined to limit the maximum number of the staffs. num_staff is the number of employees in the staffs array.

      It has two constructors: Manager() and Manager(int id, const string& name, char gender, const Date& entry_date, Department dept). The former does nothing, while the latter will set all the properties of the manager, set post to "Manager", and allocate memory for the staffs based on MAX_STAFF_NUM.

      The destructor ~Manager() should first delete the staffs array. As we claim that an employee (except the manager itself) must have a manager, remember to also delete each pointed employee before deleting the array. After that, print:

      Resign: Manager name
      where name is the manager's name.

      manage(Technician *t) will append the technician to the staff array. The num_staff should be increased by one. When a staff is appended, it should print:

      name_s is managed by name_m now!
      where name_s is the name of the staff and name_m is the name of the manager. (For simplicity, you do not need to check whether the staffs is out of bound. We assume that a manager will always manage at most MAX_STAFF_NUM employees.)

      calculate_salary() will calculate the salary of the manager by the formula: 20000 + 2000 * num_staff, and then set the salary of the class.

      print_description() should print:

      ID: id, Name: name, Gender: gender, Entry date: entry_date, Post: Manager, Group: dept
      where id, name, gender, and dept are properties of the manager, and entry_date should be represented as "yyyy-mm-dd". Note that to print the string of dept, please use the enum_to_str(Department dept) in the Employee.cpp.

      print_staff() should print:

      name_m is managing num_staff staffs: [name_1, ][name_2, ]...[name_x, ]
      where name_m is the name of the manager, num_staff is the property of the manager, and name_x is the name of the x-th staff.

    5. Technician

    6. This class is derived from Employee. It contains a protected member: num_projects, which indicates the number of projects he works on this month.

      It has two constructors: Technician() and Technician(int id, const string& name, char gender, const Date& entry_date, int num_projects, Department dept). The former does nothing, while the latter will set all the properties of the technician, and set post to "Technician".

      The destructor ~Technician() should print:

      Resign: Technician name
      where name is the technician's name.

      calculate_salary() will calculate and set the salary of the Technician by the formula: 10000 + 1000 * num_projects, where num_projects is the property, and then set the salary of the class.

      print_description() should print:

      ID: id, Name: name, Gender: gender, Entry date: entry_date, Post: Technician, Group: dept, Finished num_projects: num_projects
      where id, name, gender, dept and num_projects are properties of the Technician, and entry_date should be represented as "yyyy-mm-dd" based on the property. Note that to print the string of dept, please use the enum_to_str(Department dept) in the Employee.cpp.

    7. TechnicianLeader

    8. This class is derived from Technician.

      It has two constructors: TechnicianLeader() and TechnicianLeader(int id, const string& name, char gender, const Date& entry_date, int num_projects, Department dept). The former does nothing, while the latter will set all the properties of the technicianLeader, and set post to "Technician Leader".

      The destructor ~TechnicianLeader() should print:

      Resign: TechnicianLeader name
      where name is the TechnicianLeader's name.

      calculate_salary() will calculate and set the salary of the TechnicianLeader by the formula: 20000 + 1500 * num_projects.

      print_description() should print:

      ID: id, Name: name, Gender: gender, Entry date: entry_date, Post: Technician Leader, Group: dept, Finished num_projects: num_projects
      where id, name, gender, dept and num_projects are properties of the TechnicianLeader, and entry_date should be represented as "yyyy-mm-dd". Note that to print the string of dept, please use the enum_to_str(Department dept) in the Employee.cpp.


    Lab tasks

    1. All .h files, Employee.cpp and main.cpp are given to you. Please read the description and these files to understand the relationship. Noted that calculate_salary() and print_description() are pure virtual functions.
    2. Based the information, implements the rest files, including Manager.cpp, Technician.cpp, and TechnicianLeader.cpp.
    3. Compile the project.
    4. Run the executable to check with the expected output below:
      ID: 101, Name: Bruce Wayne, Gender: M, Entry date: 2016-5-10, Post: Manager, Group: HumanResource
      ID: 102, Name: Peter Parker, Gender: F, Entry date: 2020-6-10, Post: Technician, Group: Game, Finished num_projects: 4
      Peter Parker is managed by Bruce Wayne now!
      ID: 103, Name: Tony Stark, Gender: M, Entry date: 2018-7-10, Post: Technician Leader, Group: FrontEnd, Finished num_projects: 2
      Tony Stark is managed by Bruce Wayne now!
      ID: 104, Name: Steve Rogers, Gender: F, Entry date: 2021-11-11, Post: Technician, Group: Backend, Finished num_projects: 1
      Steve Rogers is managed by Bruce Wayne now!
      ID: 105, Name: Bruce Banner, Gender: M, Entry date: 2019-12-3, Post: Technician Leader, Group: Operation, Finished num_projects: 3
      Bruce Banner is managed by Bruce Wayne now!
      Bruce Wayne is managing 4 staffs: Peter Parker, Tony Stark, Steve Rogers, Bruce Banner,
      Bruce Wayne : $28000
      Peter Parker : $14000
      Tony Stark : $23000
      Steve Rogers : $11000
      Bruce Banner : $24500
      Resign: Technician Peter Parker
      Resign: Empolyee Peter Parker
      Resign: TechnicianLeader Tony Stark
      Resign: Technician Tony Stark
      Resign: Empolyee Tony Stark
      Resign: Technician Steve Rogers
      Resign: Empolyee Steve Rogers
      Resign: TechnicianLeader Bruce Banner
      Resign: Technician Bruce Banner
      Resign: Empolyee Bruce Banner
      Resign: Manager Bruce Wayne
      Resign: Empolyee Bruce Wayne
                               


    Submission Deadline and Guidelines:

    The lab assignment is due on 10 minutes after the end of your lab session.
    We will use an online grading system ZINC to grade your lab work. Therefore, you are supposed to upload the following files in a zip file to ZINC:
    - Manager.cpp
    - Technician.cpp
    - TechnicianLeader.cpp
    
    You can submit your codes multiple times to ZINC before the deadline. Only the last submission will be graded.

    Page maintained by
    • Yuxuan ZHOU
    • Last Modified:
    Homepage