Question

In: Computer Science

C++ It is common for an organization to have different categories of employees, such that one...

C++

It is common for an organization to have different categories of employees, such that one Employee class can not easily describe all types of Employees.In this project, you will code a basic Employee class, and then a number of classes which derive from the Employee class (inherit), adding Employee specifics. An application program which stores info for one company will have use objects of different types to model the all employees.

Part I:   The Employee Class

First create the Employee class described below. This class will serve as a base class. All specific employee typed will be derived from this class. :

Employee

-lastName:string

-firstName:string

-idNum:int

+Employee()    //default values assigned to all variables

+Employee(int idNum, string lname, string fname)

+void setLName(string)

+void setFName(string)

+void setIDNum(int)

+string getLName()

+sgtringgetFName()

+intgetIDNum()

+void displayName()

+void display()

Stick with the access specifiers on the diagram. Items denoted as + are public, - are private.

NOTE: There are NO protected member variables in this class

The constructors both initialize all member variables. Sets functions set the indicated member variable of the object, and get functions return the value of the indicated member variable of the object.

The displayName() function prints out the last name and ID only, and the display()function outputs the all employee information that is stored.

PART II: The Derived Classes

Salaried

Hourly

Commission

-weeklySal:double

-payperhr:double

-hrsworked:double

-basesalary:double

-comAmount:double

+Salaried(string lname, string fname)

+Salaried(string lname, string fname, double sal)

+void setSal(double nsal)

+double getSal()

+void displaySal()

+void display()

+Hourly(string lname, string fname)

+Hourly(string lname, string fname, double newpay)

+void setPay(double)

+void setHrs(double nhr)

+double getPay()

+double getHrs()

+void displayHrly():

+void display()

+Commission(string  

        lname, string fname)

+Commission(string lname, string fname, double bsal)

+void setBase(double npay)

+void setCom(double nhr)

+double getBase()

+double getCom()

+void displayBase()

+void displayEmp()

As you can see, Employee is a base class, which is extended by the Hourly, Salaried and Commissioned classes. The derived classes describe 3 ‘types’ of employee.

Each of the derived classes provides instance data necessary for determining an employee’s weekly earnings, and both set (mutator) and get(accessor) methods for these additional variables. A salaried employee just gets a prearranged salary per week. An hourly employee’s weekly salary is based on the hourly rate and number of hours worked that week. A commissioned employee gets a base pay per week, plus the amount of commission earned that week. Each of these classes provides two display functions, one that outputs info specific for that class, one that overrides the base class function display(), to output all info on the object (both base and derived class data).

The displaySal() function outputs the employee name, id and weekly salary.

The displayHrly() function outputs the employee name, id and hourly rate.

The displayBase() function outputs the employee name, id and base pay.

Once these classes are working and tested you are ready to begin part III.

Part III The Application

You are to write an application which will allow the user to enter all his/her employees and their data. This application will allow the user to print out information on employees.

(This project will be updated in a future project assignment, so be sure to stick to the specifications. This will make the update happen more smoothly)

This application is to store each of the three types of objects in it’s own vector. That is, you will have a vector<Salaried>, a vector<Hourly> and a vector<Commission>.

Your program is to provide the following options for the user:

   * add a new salaried employee

   * add a new hourly employee

   * add a new commissioned employee

   * list all employees with a particular last name

   * output all information for all employees stored

   * search for an employee with a particular id number

   * output the name and salaries ONLY of all salaried employees

* output the name and hourly rate ONLY of all salaried employees

   * output the name, id and base salary of all commissioned employees

  

You are to submit 9 files, Employee.h, Employee.cpp, Salaried.h, Salaried.cpp, Hourly.h, Hourly.cpp, Commission.h, Commission.cpp, and your main program file.

Solutions

Expert Solution

The idea is to use the abstract and polymorphism concepts to extend the functionalities of an Employee.

As asked in the above question, providing step-by-step codes for each class including Main class. Please find all the coding below with headings of class name.

------------------------------------------------------------------------------------------------------------------------------------

Let us make the basic Employee class as an abstract class inorder present the general functionality of an employee. The other classes that extend Employee class are Salaried, Commission and Hourly respectively as per the given inputs. included total 5 files along with EMPLOYEE creation in main.

So to start with Employee Class: Here is the tested fully functional code for Employee Class with given members:

1. EMPLOYEE

public abstract class Employee

{

private String firstName;

private String lastName;

private int idNum;

public Employee()

{

//initializing with default values

}

public Employee (int idNum, string lname, string fname)

    {

      firstName = fname;

      lastName = lname;

      idNum = idNum;

    }

public void setFName ( String fname)

{

       firstName = fname;

}

public String getFName ()

   {

     return firstName;

   }

public void setLName ( String lname)

     {

      lastName = lname;

     }

public String getLName ()

   {

   return lastName;

   }

public void setIDNum ( int idNum)

    {

       idNum = idNum;

    }

public int getIDNum ()

    {

      return idNum;

    }

public void displayName()

   {

     return String.format( "%s %s\nEmployee id Number: %s",

        getFName(), getLName() );

}

public void display()

   {

     return String.format( "%s %s\nEmployee id Number: %s",

        getFName(), getLName(),getIDNum () );

}

Moving on to Derived classes:

2. SALARIED

public class Salaried extends Employee
{
private double weeklySal;
public Salaried( String lname, String fname)
{
super( lname, fname);
}
public Salaried( String lname, String fname, double sal )
{
super( lname, fname );
setSal( sal );
}
public void setSal( double nsal )
{
if (nsal >= 0.0 )
weeklySal = nsal;
else
throw new IllegalArgumentException(
"Weekly salary should be >= 0.0" );
}
public double getSal()
{
return weeklySal;
}
@Override   
public double earnings()
{
return getSal();
}

public void display()

   {

     return String.format( "%s %s\nEmployee id Number: %s",

        getFName(), getLName(),getIDNum () );

}   
public void displaySal()   
{
return String.format( "Salaried Employee: %s\n%s: $%,.2f",
super.display(), "Weekly salary" , getSal() );
}

}

3. HOURLY

public class Hourly extends Employee
{
private double payperhr;
private double hrsworked;

public Hourly( String lname, String fname)
{
super( lname, fname );
}
public Hourly( String lname, String fname,double newpay)
{

super( lname, fname );
setPay( newpay );
}

public void setPay( double newpay )
{
if ( newpay >= 0.0 )
payperhr = newpay;
else
throw new IllegalArgumentException(
"Hourly payperhr must be >= 0.0" );
}

public double getPay()
{
return payperhr;
}
public void setHrs( double nhr )
{
if ( (nhr>=0.0) && ( nhr <= 168.0 ) )
hrsworked = nhr;
else
throw new IllegalArgumentException(
"hrsworked worked must be >= 0.0 and <= 168.0" );
}
public double getHrs()
{
return hrsworked;
}
@Override   
public double earnings()
{
if ( getHrs() <= 40 ) // no overtime
return getPay() * getHrs();
else   
return 40 * getPay() + ( getHrs() - 40 ) * getPay() * 1.5 ;
}

public void display()

   {

     return String.format( "%s %s\nEmployee id Number: %s",

        getFName(), getLName(),getIDNum () );

}

public void displayHrly()
{   
return String.format( "Hourly employee: %s\n%s: $%,.2f; %s: %,.2f",
super.display(), "hourly payperhr" , getPay(),
"hrsworked worked", getHrs() );
}   
}

4. COMMISSION:

public class Commission extends Employee
{
private double basesalary;
private double comAmount;
public Commission( String lname, String fname)
{
super( lname, fname );
}
public Commission( String lname, String fname, double bsal)
{
super( lname, fname );
setBase( npay );
}
public void setCom( double nhr )
{
if ( nhr > 0.0 && nhr < 1.0 )
comAmount = nhr;
else
throw new IllegalArgumentException(
"Commission rate must be > 0.0 and < 1.0" );
}
public double getCom()
{
return comAmount;
}
public void setBase( double npay )
{
if ( npay >= 0.0 )
basesalary = npay;
else
throw new IllegalArgumentException(
"Base salary must be >= 0.0" );
}
public double getBase()
{
return basesalary;
}
@Override   
public double earnings()
{   
return getCom() * getBase();
}

public void display()

   {

     return String.format( "%s %s\nEmployee id Number: %s",

        getFName(), getLName(),getIDNum () );

}      
public void displayBase()
{
return String.format( "%s: %s\n%s: $%,.2f; %s: %.2f",
"Commissioned employee", super.display(),
"base salary", getBase(),   
"commission rate", getCom() );   
}
}

5. MAIN

public class Main
{
public static void main( String[] args )
{
Employee employee = new Employee( 12345, "Pratibha", "Jogendra" );   
Salaried salaried = new Salaried( "Pratibha", "Jogendra" ,800.00 );
Hourly hourly = new Hourly( "Datta", "Prakash" , 16.75);
Commission commission = new Commission("Kumar", "Gunadhya", 10000.00);
System.out.println( "Individual Employees :\n" );
System.out.printf( "%s\n%s: $%,.2f\n\n", salaried, "earned", salaried.earnings() );
System.out.printf( "%s\n%s: $%,.2f\n\n", hourly, "earned", hourly.earnings() );
System.out.printf( "%s\n%s: $%,.2f\n\n",commission, "earned", commission.earnings() );
Employee[] employees = new Employee[ 4 ];
employees[ 0 ] = salaried;
  employees[ 1 ] = hourly;
employees[ 2 ] = commission;

//Can display output using polymorphism
}
}


Related Solutions

It is common for an organization to have different categories of employees, such that one Employee...
It is common for an organization to have different categories of employees, such that one Employee class can not easily describe all types of Employees.In this project, you will code a basic Employee class, and then a number of classes which derive from the Employee class (inherit), adding Employee specifics. An application program which stores info for one company will have use objects of different types to model the all employees. Part I:   The Employee Class First create the Employee...
C++ Requires 9 files It is common for an organization to have different categories of employees,...
C++ Requires 9 files It is common for an organization to have different categories of employees, such that one Employee class can not easily describe all types of Employees.In this project, you will code a basic Employee class, and then a number of classes which derive from the Employee class (inherit), adding Employee specifics. An application program which stores info for one company will have use objects of different types to model the all employees. Part I:   The Employee Class...
The employees of the organization involved people who have different lifestyles and are at different stages...
The employees of the organization involved people who have different lifestyles and are at different stages in their life. Jessie is a single mother who works for minimum wage and lives in the “divided flat” for accommodation. Jessie wants to improve her living condition to relieve the problem of inadequate basic necessity. Ronnie is a single woman who earns a decent salary and has only a few friends outside her office. Ronnie often feels lonely after work. (a) Identify and...
c) An organisation has 1000 employees. There are five categories of employees in the organisation (human...
c) An organisation has 1000 employees. There are five categories of employees in the organisation (human resources, IT, finance, marketing, and maintenance). Top management is interested in obtaining feedback from the employees with regard to job satisfaction. Given that the proportion of employees from the various departments are as follows; 20% from human resources, 10% IT, 30% from finance, 30% from marketing and the balance from maintenance. i) The researcher plans to take a sample of 200 employees. State and...
Explore what impact the different auditor’s opinion will have on the audited organization, its employees and...
Explore what impact the different auditor’s opinion will have on the audited organization, its employees and its stakeholders. Do you feel it is absolutely necessary to audit an organization every year if they have continuously been issued a clean audit opinion? Why or why not?
Write a program in C to process weekly employee timecards for all employees of an organization...
Write a program in C to process weekly employee timecards for all employees of an organization (ask the user number of employees in the start of the program). Each employee will have three data items: an identification number, the hourly wage rate, and the number of hours worked during a given week.A tax amount of 3.625% of gross salary will be deducted. The program output should show the identification number and net pay. Display the total payroll and the average...
1. Whistleblower is : Which one and Explain A. employees of an organization that go beyond...
1. Whistleblower is : Which one and Explain A. employees of an organization that go beyond their duties and expectation in order to highlight wrong within the organization or B. employees go beyond normal procedure& loyalty to their employer and report wrong doing in the intrest of the public .
Many work groups consist of employees from a variety of different sections of the organization (ie,...
Many work groups consist of employees from a variety of different sections of the organization (ie, someone from sales, someone from engineering, someone from accounting, etc.). While other work groups consist of a smaller subsection of the individual sections themselves (for instance, 4 of the 15 people from accounting). Which work group would be easier to be a part of, the heterogeneous (diversified) group or the homogeneous (similar) group. Which do you think would get the most work done? What...
Scenario 6: Your organization is shifting and you have a team of employees that have been...
Scenario 6: Your organization is shifting and you have a team of employees that have been notified that they are no longer part of the organization. Some employees will have an end date in one month, some in three months and some in six months. A few employees feel betrayed and are no longer performing at a high level. These employees are scheduled depart in six months. 1. How will you keep these employees motivated?
If your organization doesn't have a "common" problem-solving methodology, what one would you recommend? Why?
If your organization doesn't have a "common" problem-solving methodology, what one would you recommend? Why?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT