Question

In: Computer Science

Part I: The Employee Class You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class.

 

Part I:   The Employee Class

You are to first update the Employee class to include two virtual functions. This will make the Employee class an abstract class.

* Update the function display() to be a virtual function

    * Add function, double weeklyEarning() to be a pure virtual function. This will make Employee an abstract class, so your main will not be able to create any Employee objects.

Part II: The Derived Classes

Add an weeklyEarning() function to each of the three derived classes. A salaried employee’s weekly earning is as stored. An hourly employee’s weekly earning is the hrsworked * payperhr. A commissioned employee’s weekly earning would be the base + the comAmount.

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

#include

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
#include
#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

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
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
#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 

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
#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 

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 << "------------------------------";
}

Solutions

Expert Solution

P.S : Updations are done with a comment "///**updation**"


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

#include

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

   virtual void display();                                 ////**updation**

   virtual double weeklyEarning()=0;                                                       

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

-----------------------------------
Employee.cpp
-----------------------------------
#include
#include
#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 idNum,firstName,lastName
 void Employee::display()                          ///**updation**
{
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

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();
   
   double weeklyEarning();                    ///**updation**
                           
   


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

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

#include
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 << "------------------------------";
}
//returns weekly earnings
double Salaried:: weeklyEarning()
  {
  return weeklySal;                     ///**updation**
  }
-----------------------------------

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

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

double weeklyEarning();    ///**updation**
};
#endif

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

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

#include 

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 << "------------------------------";

}
//returns weekly earnings
double Commission:: weeklyEarning()
  {
  return basesalary+comAmount; ///**updation**
  } 
-----------------------------------

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

#include
#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();
   double weeklyEarning();    ///**updation**

};
#endif

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

-----------------------------------
Hourly.cpp
-----------------------------------
#include "Hourly.h"
#include 

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 << "------------------------------";
}

//returns weekly earnings

double Hourly :: weeklyEarning()

{

return (payperhr*hrsworked); ///**updation**

}


Related Solutions

In C++ Create an abstract class called Shape Shape should have the following pure virtual functions:...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions: getArea() setArea() printArea() Create classes to inherit from the base class Circle Square Rectangle Both implement the functions derived from the abstract base class AND must have private variables and functions unique to them like double Radius double length calculateArea() Use the spreadsheet info.txt read in information about the circle, rectangle, or square text file: circle   3.5   square   3   rectangle   38   36 circle   23  ...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private data for name, selection, wins, and losses. It must have a non-default constructor that requires name. It may not contain a default constructor. Create overloaded functions for the ++ and - - operator. The overloaded ++operator will add to the number of wins, while the - - operator will add to the losses. You will create two different child classes of player, Human and...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
Make quicksort functions to sort this class, first by ID then by athleteEvaluation athleteID: an unique...
Make quicksort functions to sort this class, first by ID then by athleteEvaluation athleteID: an unique identifier for the athlete athletePosition: an abbreviation of the expected player’s position on the team. We will use an enumerated data type to store the position within our BUAthlete class. A definition of the enumerated data type is provided below. Don't forget that enumerated data types are actually stored as integers. enum Position {OL, QB, RB, WR, TE, DL, DE, LB, CB, S, K};...
I have listed below two functions. Please add these two functions to StudentMath class. Test it...
I have listed below two functions. Please add these two functions to StudentMath class. Test it from the Test class public int divideByZero(int gradeA, int gradeB, int gradeC) { int numberOfTests = 0; int gradeAverage = 0; try { gradeAverage = (gradeA + gradeB + gradeC)/numberOfTests; } catch(ArithmeticException ex) { System.out.println("Divide by zero exception has occured" + ex.getMessage()); } return gradeAverage; } public int ArrayOutOfBoundEception() { int i = 0; try { // array of size 4. int[] arr =...
There is a pair of functions in stdlib.h (make sure to include it) that are used...
There is a pair of functions in stdlib.h (make sure to include it) that are used for generating pseudo-random numbers. These are "srand" and "rand". Examples are on pages 686 and 687. E.g., function "srand(3)" provides the seed value of 3 to the srand function. (3 is just a number, and probably isn't even a good number for this purpose, but that's a discussion for another time). The reason that we use a seed value is so that we can...
I am trying to make a new code that uses functions to make it. My functions...
I am trying to make a new code that uses functions to make it. My functions are below the code. <?php */ $input; $TenBills = 1000; $FiveBills = 500; $OneBills = 100; $Quarters = 25; $Dimes = 10; $Nickels = 5; $Pennies = 1; $YourChange = 0; $input = readline("Hello, please enter your amount of cents:\n"); if(ctype_digit($input)) { $dollars =(int)($input/100); $cents = $input%100;    $input >= $TenBills; $YourChange = (int)($input/$TenBills); $input -= $TenBills * $YourChange; print "Change for $dollars dollars...
java/netbeans 1.Design an abstract class Employee that stores: employee name, unique auto-generated id, hire year. Implement...
java/netbeans 1.Design an abstract class Employee that stores: employee name, unique auto-generated id, hire year. Implement any necessary methods in addition to: a.The toString and equals methods. The equals method should NOT compare the id. b.The copy constructor (should copy the same id too) c.An abstract method float getWeeklyCheckAmount() d.Implement the appropriate interface to be able to sort employee names in alphabetical order. Subclasses should NOT be allowed to override this implementation. 2.Design an abstract class HourlyWorker that extends Employee...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the Date class to create an object for date hired. A faculty member has office hours and a rank. A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT