Question

In: Computer Science

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

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

Following c++ program deomstrates usage of inheritance.

We have one parent class : Employee
Three child classes derives from Employee are : Salaried, Hourly, Commission.

Each has their own extra features plus employee features.

Implementation of application walk you through the menu driven flow, which will allow you to perform following actions :


1. add a new salaried employee
2. add a new hourly employee
3. add a new commissioned employee
4. list all employees with a particular last name
5. output all information for all employees stored
6. search for an employee with a particular id number
7. output the name and salaries ONLY of all salaried employees
8. output the name and hourly rate ONLY of all hourly employees
9. output the name, id and base salary of all commissioned employees
0. Exit


There are total 9 code files :
Employee.h, Employee.cpp, Salaried.h, Salaried.cpp, Commission.h, Commission.cpp, Hourly.h, Hourly.cpp, main.cpp.

and

output image file.

Source code :

-----------------------------------
Employee.h
-----------------------------------
#ifndef Employee_H   
#define Employee_H

#include<string>

using namespace std;

class Employee
{

private:
   string lastName;
   string firstName;
   int idNum;

public:

   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();

   string getFName();

   int getIDNum();

   void displayName();

   void display();

};
#endif
-----------------------------------

-----------------------------------
Employee.cpp
-----------------------------------
#include<string>
#include<iostream>
#include"Employee.h"

using namespace std;

Employee::Employee() {
   //default values assigned to all variables
   lastName = "";
   firstName = "";
   idNum = 0;
}

Employee::Employee(int idNum, string lname, string fname) {
  
   this->lastName = lname;
   this->firstName = fname;
   this->idNum = idNum;
}
//Sets last name
void Employee::setLName(string lname) {
   this->lastName = lname;
}
//sets first name
void Employee::setFName(string fname) {
   this->firstName = fname;
}
//sets id num
void Employee::setIDNum(int idnum) {
   this->idNum = idnum;
}

//get last name
string Employee::getLName() {
   return lastName;
}
  
//get first name  
string Employee::getFName() {
   return firstName;
}

//get id num
int Employee::getIDNum() {
   return idNum;
}

//display id and last name
void Employee::displayName() {

   cout << endl << "ID Num : " << this->idNum;
   cout << endl << "Last name : " << this->lastName;
}

//display employee details
void Employee::display() {

   cout << endl << "ID Number " << this->idNum;
   cout << endl << "First name : " << this->firstName;
   cout << endl << "Last name : " << this->lastName;

}

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

-----------------------------------
Salaried.h
-----------------------------------
#ifndef Salaried_H   
#define Salaried_H

#include "Employee.h"
#include<string>

using namespace std;

class Salaried : public Employee{

private:

   double weeklySal;
public:

   Salaried();

   Salaried(int idNum, string lname, string fname);

   Salaried(int idNum, string lname, string fname, double sal);

   void setSal(double nsal);

   double getSal();

   void displaySal();

   void display();

};
#endif
-----------------------------------

-----------------------------------
Salaried.cpp
-----------------------------------
#include "Salaried.h"

#include<iostream>
using namespace std;

Salaried::Salaried():Employee() {
   this->weeklySal = 0;
}

Salaried::Salaried(int idNum, string lname, string fname) :Employee(idNum, lname, fname) {
   this->weeklySal = 0;
}

Salaried::Salaried(int idNum, string lname, string fname, double sal) : Employee(idNum, lname, fname) {
   this->weeklySal = sal;
}

//set salary
void Salaried::setSal(double nsal) {
   this->weeklySal = nsal;

}

//get salary
double Salaried::getSal() {
   return weeklySal;
}

//display name, id num, salary
void Salaried::displaySal() {

   cout << endl << "Name " << this->getLName();
   cout << endl << "ID Num " << this->getIDNum();
   cout << endl << "Weekly salary " << this->weeklySal;

   cout << endl << "------------------------------";

}

//Display employee details
void Salaried::display() {

   Employee::display();
   cout << endl << "Weekly salary " << this->weeklySal;
   cout << endl << "------------------------------";
}
-----------------------------------

-----------------------------------
Commission.h
-----------------------------------
#ifndef Commission_H   
#define Commission_H

#include<string>
#include "Employee.h"

using namespace std;

class Commission : public Employee{
private:

double basesalary;
double comAmount;

public:

Commission();

Commission(int idNum, string lname, string fname);

Commission(int idNum, string lname, string fname, double bsal);

void setBase(double npay);

void setCom(double nhr);

double getBase();

double getCom();

void displayBase();

void displayEmp();

};
#endif

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

-----------------------------------
Commission.cpp
-----------------------------------
#include "Commission.h"

#include <iostream>

using namespace std;

//sets Commission instance to default intial values
Commission::Commission():Employee() {

   this->basesalary = 0;
   this->comAmount = 0;
}

//Sets Commission instance to Commission parameters
Commission::Commission(int idNum, string lname, string fname):Employee(idNum, lname, fname) {
  
   this->basesalary = 0;
   this->comAmount = 0;
}

//Sets Commission instance to Employee plus Commision parameters
Commission::Commission(int idNum, string lname, string fname, double bsal):Employee(idNum, lname, fname) {
  
   this->comAmount = 0;
   this->basesalary = bsal;

}

//Sets base salary
void Commission::setBase(double npay) {
   this->basesalary = npay;
}

//Set commision salary
void Commission::setCom(double nhr) {
   this->comAmount = nhr;
}

//Get base salary
double Commission::getBase() {
   return basesalary;
}

//Get commission salary
double Commission::getCom() {
   return comAmount;
}

//Display base salary and commision salary
void Commission::displayBase() {

   cout << endl << "Name " << this->getLName();
   cout << endl << "ID Num " << this->getIDNum();
   cout << endl << "Base salary " << this->basesalary;

   cout << endl << "------------------------------";

}

//Display commission employee details
void Commission::displayEmp() {

   Employee::display();
   cout << endl << "Base salary " << this->basesalary;
   cout << endl << "Commission Amount : " << this->comAmount;

   cout << endl << "------------------------------";

}
-----------------------------------

-----------------------------------
Hourly.h
-----------------------------------
#ifndef Hourly_H   
#define Hourly_H

#include<string>
#include"Employee.h"

using namespace std;

class Hourly : public Employee{
private:

   double payperhr;
   double hrsworked;

public:

   Hourly();
   Hourly(int idNum, string lname, string fname);
   Hourly(int idNum, string lname, string fname, double newpay);
   void setPay(double);
   void setHrs(double nhr);
   double getPay();
   double getHrs();
   void displayHrly();
   void display();

};
#endif

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

-----------------------------------
Hourly.cpp
-----------------------------------
#include "Hourly.h"
#include <iostream>

using namespace std;


Hourly::Hourly():Employee() {

   this->payperhr = 0;
   this->hrsworked = 0;
}

Hourly::Hourly(int idNum, string lname, string fname):Employee(idNum, lname, fname) {

   this->payperhr = 0;
   this->hrsworked = 0;
}
Hourly::Hourly(int idNum, string lname, string fname, double newpay): Employee(idNum, lname, fname) {
  
   this->payperhr = newpay;
   this->hrsworked = 0;
}

void Hourly::setPay(double pphr) {
   this->payperhr = pphr;
}

void Hourly::setHrs(double nhr) {
   this->hrsworked = nhr;
}

double Hourly::getPay() {
   return payperhr;
}

double Hourly::getHrs() {
   return hrsworked;
}
void Hourly::displayHrly() {

   cout << endl << "Name " << this->getLName();
   cout << endl << "ID Num " << this->getIDNum();
   cout << endl << "Pay per hour " << this->payperhr;
   cout << endl << "------------------------------";
}
void Hourly::display() {
   Employee::display();
   cout << endl << "Pay per hour " << this->payperhr;
   cout << endl << "Hours worked : " << this->hrsworked;

   cout << endl << "------------------------------";
}
-----------------------------------

-----------------------------------
main.cpp
-----------------------------------
#include<iostream>
#include<vector>

#include "Salaried.h";
#include "Hourly.h";
#include "Commission.h";

using namespace std;

//Menu for all features
void menu();


//driver method
int main() {

   //store all salariedEmployees
   vector<Salaried> salariedEmployees;
   //store all hourlyEmployees
   vector<Hourly> hourlyEmployees;
   //store all commissionEmployees
   vector<Commission> commissionEmployees;

   //to store menu option
   int choice;

   //local variables for reading info
   double weeklySal;
string lastName;
string firstName;
   int idNum;
   double payperhr;
   double hrsworked;
   double basesalary;
   double comAmount;

   //Search employee id
   int searchIDNum;

   Salaried salariedEmp = Salaried();
   Hourly hourlyEmp = Hourly();
   Commission commissionEmp = Commission();

   do {
       //Dsiplay menu
       menu();

       //Ask user for menu option
       cout << endl << "Enter your choice :";

       //Read menu option
       cin >> choice;

       //Based on selected menu option, specific case will be executed
       switch (choice) {

       case 1:
           //add a new salaried employee
           cout << endl << "Enter salaried employee details :" << endl;
          
           cout << endl << "First name :"; cin >> firstName;
           cout << endl << "Last name :"; cin >> lastName;
           cout << endl << "ID Num :"; cin >> idNum;
           cout << endl << "Weekly Salary :"; cin >> weeklySal;

           salariedEmp.setFName(firstName);
           salariedEmp.setLName(lastName);
           salariedEmp.setIDNum(idNum);
           salariedEmp.setSal(weeklySal);

           salariedEmployees.push_back(salariedEmp);
           cout << endl << "salaried employee details added." << endl;

           break;

       case 2:
           //add a new hourly employee
           cout << endl << "Enter Hourly employee details :" << endl;

           cout << endl << "First name :"; cin >> firstName;
           cout << endl << "Last name :"; cin >> lastName;
           cout << endl << "ID Num :"; cin >> idNum;
           cout << endl << "Pay per Hour :"; cin >> payperhr;
           cout << endl << "Hours worked :"; cin >> hrsworked;

           hourlyEmp.setFName(firstName);
           hourlyEmp.setLName(lastName);
           hourlyEmp.setIDNum(idNum);
           hourlyEmp.setPay(payperhr);
           hourlyEmp.setHrs(hrsworked);

           hourlyEmployees.push_back(hourlyEmp);
           cout << endl << "Hourly employee details added." << endl;

           break;

       case 3:
           //add a new commissioned employee

           cout << endl << "Enter Commission employee details :" << endl;

           cout << endl << "First name :"; cin >> firstName;
           cout << endl << "Last name :"; cin >> lastName;
           cout << endl << "ID Num :"; cin >> idNum;
           cout << endl << "Base salary :"; cin >> basesalary;
           cout << endl << "Commission amount :"; cin >> comAmount;

           commissionEmp.setFName(firstName);
           commissionEmp.setLName(lastName);
           commissionEmp.setIDNum(idNum);
           commissionEmp.setBase(basesalary);
           commissionEmp.setCom(comAmount);

           commissionEmployees.push_back(commissionEmp);
           cout << endl << "Commission employee details added." << endl;

           break;

       case 4:
           //list all employees with a particular last name
           cout << endl << "Enter the last name (employees with mentioned last name's details will be displayed) : ";
           cin >> lastName;

           cout << endl << "Displaying employee who's has last name :" << lastName << endl;

           for (auto& it : hourlyEmployees) {

               if(it.getLName() == lastName)
                   it.display();
           }

           for (auto& it : salariedEmployees) {
               if (it.getLName() == lastName)
                   it.display();
           }

           for (auto& it : commissionEmployees) {
               if (it.getLName() == lastName)
                   it.display();
           }
           cout << endl << "Done displaying employee names";

           break;

       case 5:
           //output all information for all employees stored

           cout << endl << "Displaying all employee details "<< endl;

           for (auto& it : hourlyEmployees) {

                   it.display();
           }

           for (auto& it : salariedEmployees) {
                   it.display();
           }

           for (auto& it : commissionEmployees) {
                   it.display();
           }
           cout << endl << "Done displaying all employee details";

           break;

       case 6:
           //search for an employee with a particular id number
           cout << endl << "Enter the search IDNum : ";
           cin >> searchIDNum;

           cout << endl << "Displaying employee who's has ID Num :" << searchIDNum << endl;

           for (auto& it : hourlyEmployees) {

               if (it.getIDNum() == searchIDNum)
                   it.display();
           }

           for (auto& it : salariedEmployees) {
               if (it.getIDNum() == searchIDNum)
                   it.display();
           }

           for (auto& it : commissionEmployees) {
               if (it.getIDNum() == searchIDNum)
                   it.display();
           }
           cout << endl << "Done displaying employee details with mentioned ID num";

           break;

       case 7:
           //output the name and salaries ONLY of all salaried employees

           cout << endl << "Displaying name and salary of all salaried employees" << endl;

  
           for (auto& it : salariedEmployees) {
               cout << endl << "First Name : " << it.getFName();
               cout << endl << "Last Name : " << it.getLName();
               cout << endl << "Salary : " << it.getSal();
           }

           cout << endl << "Done displaying all salaried employee details";

           break;

       case 8:
           //output the name and hourly rate ONLY of all hourly employees

           cout << endl << "Displaying name and hourly rates of all hourly employees" << endl;


           for (auto& it : hourlyEmployees) {
               cout << endl << "First Name : " << it.getFName();
               cout << endl << "Last Name : " << it.getLName();
               cout << endl << "Hourly Rate : " << it.getPay();
           }

           cout << endl << "Done displaying all hourly employee details";

           break;

       case 9:
           //output the name, id and base salary of all commissioned employees
           cout << endl << "Displaying name , id and base salary of all commissioned employees" << endl;


           for (auto& it : commissionEmployees) {
               cout << endl << "First Name : " << it.getFName();
               cout << endl << "Last Name : " << it.getLName();
               cout << endl << "ID Num : " << it.getIDNum();
               cout << endl << "Base Salary : " << it.getBase();
           }

           cout << endl << "Done displaying all commission employee details";

           break;

       case 0:
           //exit
           cout << endl << "Exiting!";
           return 0;
           break;

       default:
           cout << endl << "Invalid choice, try again!";
       }

   } while (1);

   return 0;
}


void menu() {
  
   cout << endl << "---Employee database---" << endl;

   cout << endl << "1. add a new salaried employee";
   cout << endl << "2. add a new hourly employee";
   cout << endl << "3. add a new commissioned employee";
   cout << endl << "4. list all employees with a particular last name";
   cout << endl << "5. output all information for all employees stored";
   cout << endl << "6. search for an employee with a particular id number";
   cout << endl << "7. output the name and salaries ONLY of all salaried employees";
   cout << endl << "8. output the name and hourly rate ONLY of all hourly employees";
   cout << endl << "9. output the name, id and base salary of all commissioned employees";
   cout << endl << "0. Exit";
}
-----------------------------------

-----------------------------------
output
-----------------------------------


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

Let me know , if you face any issue.


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) 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?
in c++ please In this program you are going to have several files to turn in...
in c++ please In this program you are going to have several files to turn in (NOT JUST ONE!!) hangman.h – this is your header file – I will give you a partially complete header file to start with. hangman.cpp – this is your source file that contains your main function functions.cpp – this is your source file that contains all your other functions wordBank.txt – this is the file with words for the game to use.  You should put 10...
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...
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?
In C++, develop a menu program which reads in data from 4 different input files -...
In C++, develop a menu program which reads in data from 4 different input files - appetizers, entrees, desserts, and drinks. Then, record the item information ordered by the customer for each item selected. When finished, display all items ordered to the screen with the subtotal, tax (10% for easy math), and the total. Be sure to get tip as well. Then, ensure enough payment was received before generating an output file receipt which can be printed off. Use functions...
Do you think that large organization like airlines, with thousands of employees with different expertise, may...
Do you think that large organization like airlines, with thousands of employees with different expertise, may benefit from enterprise wikis? Do you think workplace wikis can help organizations?
1.         _____ refers to a strong emotional bond employees have to their organization that makes them...
1.         _____ refers to a strong emotional bond employees have to their organization that makes them feel actively involved and committed to their work. Employee involvement Employee (workforce) engagement Workforce management Job enrichment 2.         _____ refers to any activity by which employees participate in work-related decisions and improvement activities, with the objectives of tapping the creative energies of all employees and improving their motivation. Employee involvement Employee engagement Workforce management Job enrichment 3.         _____ represents the highest level of engagement....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT