Knowee
Questions
Features
Study Tools

You are tasked with developing a software system for managing different types of employees in a company. The company has three types of employees: full-time employees, part-time employees, and consultants. Each type of employee has different attributes and calculation methods for calculating their monthly salary.Full-time employees receive a fixed monthly salary.Part-time employees are paid based on the number of hours they work and rate per hour.Consultants are paid based on the number of hours they work and an hourly rate.Design a C++ program that utilizes runtime polymorphism to model this scenario. Create a base class Employee with virtual functions calculateSalary() and displayDetails(). Derive three classes FullTimeEmployee, PartTimeEmployee, and Consultant from Employee, each implementing its own version of calculateSalary() and displayDetails() based on the rules described above.Then, demonstrate the use of runtime polymorphism by creating an array of Employee pointers containing instances of full-time employees, part-time employees, and consultants. Populate the array with objects of each type and iterate over it, calling the calculateSalary() and displayDetails() functions for each employee. Input Format:Enter name of full-time employeeEnter monthly salaryEnter name of part-time employeeEnter hourly rateEnter hours workedEnter name of consultantEnter hourly rateEnter hours worked

Question

You are tasked with developing a software system for managing different types of employees in a company. The company has three types of employees: full-time employees, part-time employees, and consultants. Each type of employee has different attributes and calculation methods for calculating their monthly salary.Full-time employees receive a fixed monthly salary.Part-time employees are paid based on the number of hours they work and rate per hour.Consultants are paid based on the number of hours they work and an hourly rate.Design a C++ program that utilizes runtime polymorphism to model this scenario. Create a base class Employee with virtual functions calculateSalary() and displayDetails(). Derive three classes FullTimeEmployee, PartTimeEmployee, and Consultant from Employee, each implementing its own version of calculateSalary() and displayDetails() based on the rules described above.Then, demonstrate the use of runtime polymorphism by creating an array of Employee pointers containing instances of full-time employees, part-time employees, and consultants. Populate the array with objects of each type and iterate over it, calling the calculateSalary() and displayDetails() functions for each employee. Input Format:Enter name of full-time employeeEnter monthly salaryEnter name of part-time employeeEnter hourly rateEnter hours workedEnter name of consultantEnter hourly rateEnter hours worked

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple implementation of the scenario in C++:

#include <iostream>
#include <vector>
using namespace std;

class Employee {
public:
    string name;
    virtual double calculateSalary() = 0;
    virtual void displayDetails() = 0;
};

class FullTimeEmployee : public Employee {
public:
    double monthlySalary;
    double calculateSalary() override {
        return monthlySalary;
    }
    void displayDetails() override {
        cout << "Full Time Employee: " << name << ", Monthly Salary: " << monthlySalary << endl;
    }
};

class PartTimeEmployee : public Employee {
public:
    double hourlyRate;
    int hoursWorked;
    double calculateSalary() override {
        return hourlyRate * hoursWorked;
    }
    void displayDetails() override {
        cout << "Part Time Employee: " << name << ", Hours Worked: " << hoursWorked << ", Hourly Rate: " << hourlyRate << endl;
    }
};

class Consultant : public Employee {
public:
    double hourlyRate;
    int hoursWorked;
    double calculateSalary() override {
        return hourlyRate * hoursWorked;
    }
    void displayDetails() override {
        cout << "Consultant: " << name << ", Hours Worked: " << hoursWorked << ", Hourly Rate: " << hourlyRate << endl;
    }
};

int main() {
    vector<Employee*> employees;

    FullTimeEmployee* ft = new FullTimeEmployee();
    ft->name = "John";
    ft->monthlySalary = 5000;
    employees.push_back(ft);

    PartTimeEmployee* pt = new PartTimeEmployee();
    pt->name = "Jane";
    pt->hourlyRate = 20;
    pt->hoursWorked = 120;
    employees.push_back(pt);

    Consultant* c = new Consultant();
    c->name = "Doe";
    c->hourlyRate = 30;
    c->hoursWorked = 100;
    employees.push_back(c);

    for (Employee* e : employees) {
        e->displayDetails();
        cout << "Salary: " << e->calculateSalary() << endl;
    }

    return 0;
}

This program creates a base class Employee with two pure virtual functions calculateSalary() and displayDetails(). It then creates three derived classes FullTimeEmployee, PartTimeEmployee, and Consultant each implementing its own version of calculateSalary() and displayDetails(). In the main() function, it creates an array of Employee pointers containing instances of full-time employees, part-time employees, and consultants, and iterates over it, calling the calculateSalary() and displayDetails() functions for each employee.

This problem has been solved

Similar Questions

You're tasked with designing an employee management system for a company. You've created a base class Employee with virtual functions calculateSalary() and displayDetails(). Now, you need to implement derived classes FullTimeEmployee and PartTimeEmployee. How would you utilize virtual functions to calculate the salary and display details for each type of employee?

Create a Java  base class called Employee. Use this class to store two double-type values that could be used to compute the salary of employees. Also,the base class should have a static variable ‘totalemp’  to keep track of the total number of employees created. Derive two specific classes called part_time and full_time from the base employee. Add a member function called as get_basic() to get the basic pay and another member called display_salary() to compute and display the salary of the employees. Using these three classes, design a program that will accept the basic pay of part_time and full_time employees interactively. Remember the two values given as input will be treated as the basic pay of the employees and the following information is used for calculating the salaries of both the part-time as well as full-time employees. Print invalid if the basic_salary of part-time employee and basic_salary of full-time employee are not met the ”Boundary Condition”Part time                                         Full timeHRA = 20% of basic pay                    HRA = 30% of basic payDA = 72% of basic pay                      DA = 80% of basic paySalary = Basic + HRA + DA              Salary = Basic + HRA + DABoundary Condition:0 < basic_salary of part-time employee <= 10000000 < basic_salary of full-time employee <= 1000000Input Format:First line to enter the basic_salary of part-time employee and basic_salary of full-time employeeOutput Format:Total salary of part-time employee and total salary of full-time employee.Total number of employees processed Sample Testcase Input-1:50007000000Sample Testcase Output-1:8900.0invalid1 Sample Testcase Input-2:30000600000Sample Testcase Output-2:42720.0110400.02 Sample Testcase Input-3:0900000Sample Testcase Output-3:invalid216000.01

Implement a C++ program to manage the salary structure for employees at a university, including Head of Department (HOD), Faculty, and Technical Assistants. Begin by defining a base class Employee with common attributes name and basicPay. Create derived classes, such as HOD, Faculty, and TechnicalAssistant, that are inherited from the employee. Each derived class should have its own method, calculateSalary(), to compute the total salary based on its specific attributes and the basic pay. The salary should also include a bonus based on the overall salary:If the overall salary is less than 50,000, the bonus is 5% of the overall salary.If the overall salary is between 50,000 and 100,000, the bonus is 7% of the overall salary.If the overall salary is more than 100,000, the bonus is 10% of the overall salary.HODs receive additional grade pay, dearnessAllowance, house RentalAllowance, and travelAllowance; faculty receive house RentalAllowance and travelAllowance; and Technical Assistants receive the basic pay and travelAllowance. In the main() function, instantiate objects of each employee type with sample data, calculate their total salary and bonus using the calculateSalary() method, and display them.

An employee will have a name, pay_rate, and list of hours_worked.Employee class must have following methods:Constructor – takes name and pay_rate. It will also creat an empty list of hours_worked.add_hours – takes hours as a parameter and add it to the hours_worked list.salary – calculates the salary for the employe (pay_rate x total hours worked).Write a main function that will:Ask user for employee name and pay rate.Create the employee object.Ask user for the number of days the employee worked.For each day it will ask the user for number of hours that employee worked and use the add_hours function to add this to the list of hours_worked in employee class.It will display the employee data as follows (use f string to format the output):Employee Name: Joe DoePay Rate: $ 25.75 per hourTotal number of hours worked: 39.45Total Salary: $ 1015.84

Design a structure in C to represent an employee's information, including their name, employee ID, department, and salary. Additionally, write a program that allows users to input employee data, display employee information, and update an employee's salary. write a code for demonstrating the implementation of the structure and program functionalities.input and output Enter employee details:Enter employee name: John DoeEnter employee ID: 101Enter department: SalesEnter salary: 50000Employee Information:Name: John Employee ID: 101 Department:Sales Salary: 50000.00Enter new salary: 55000Salary updated successfully.Updated Employee Information:Name: JohnEmployee ID: 101Department: SalesSalary: 55000.00

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.