Question

Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

Create the Employee class:

The Employee class has three attributes:

private:

string firstName;

string lastName;

string SSN;

The Employee class has

▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes.

▪ a constructor with parameters for each of the attributes

▪ getter and setter methods for each of the private attributes

▪ a method getFullName() that returns the last name, followed by a comma and space, followed by the first name

The Employee class contains information common to all employees; however, we need to store additional information about specific groups of employees, such as hourly workers or salaried workers. For hourly workers, we need to store their hourly rate and the number of hours worked in the past week we also need to calculate their pay for the past week.

Create a subclass HourlyEmployee of Employee

Employee is the superclass

HourlyEmployee is the subclass

The HourlyEmployee has addtional attributes:

private:

float hourlyRate;

int hrsWorked;

The HourlyEmployee class has

▪ a constructor with parameters for each of the attributes (Self-learning: how to call the second constructor defined in the superclass to initialize the private attributes defined in the super class through the constructor of the subclass.)

▪ getter and setter methods for each of the private attributes

▪ a new method used to calculate the weekly salary of an hourly employee. The implementation of this

method is given as follows.

double HourlyEmployee::calcWeeklySalary()

{

            double overtime = 0.0;

            if (hrsWorked > 40)

            {

                        overtime = (hrsWorked - 40)

                                    * (0.5 * hourlyRate);

            }

            return overtime + hrsWorked * hourlyRate;

}

Your need to create the Employee class and the HourlyEmployee class as required above to make sure the following given main function will produce the right output.

intmain(){

      Employee emp1;

      cout<<emp1.getFirstName()<<" "<<emp1.getLastName()<<" "<<emp1.getSSN()<<endl;

      cout<<emp1.getFullName()<<endl;

      Employee emp2("Alice", "Lackey", "291294949");

      cout<<emp2.getFirstName()<<" "<<emp2.getLastName()<<" "<<emp2.getSSN()<<endl;

      cout<<emp2.getFullName()<<endl;

      HourlyEmployee hremp1("Tom", "Steele", "3235245", 7.8, 20);

      cout<<hremp1.getFirstName()<<" "<<hremp1.getLastName()<<" "<<hremp1.getSSN()<<" "<<hremp1.getHourlyRate()<<" "<<hremp1.getHrsWorked()<<endl;

      cout<<hremp1.getFullName()<<endl;

      cout<<hremp1.calcWeeklySalary()<<endl;

      hremp1.setFirstName("Bob");

      hremp1.setLastName("Zhang");

      hremp1.setSSN("9879870897");

      hremp1.setHourlyRate(8.5);

      hremp1.setHrsWorked(18);

      cout<<hremp1.calcWeeklySalary()<<endl;

}

unknown unknown unknown

unknown, unknown

Alice Lackey 291294949

Lackey, Alice

Tom Steele 3235245 7.8 20

Steele, Tom

156

153


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include<iostream>

using namespace std;

//Class Employee (Parent class)

class Employee

{

//class members firstname, lastname and ssn

private:

string firstName;

string lastName;

string SSN;

public:

Employee();

Employee(string, string, string);

string getFirstName();

string getLastName();

string getSSN();

void setFirstName(string);

void setLastName(string);

void setSSN(string);

string getFullName();

};

//default constructor

Employee :: Employee()

{

//set firstname, lastname and SSN to unknown

firstName = "unknown";

lastName = "unknown";

SSN = "unknown";

}

//constructor with parameters

Employee :: Employee(string set_firstname, string set_lastname, string set_ssn)

{

//set firstname, lastname and SSN to unknown

firstName = set_firstname;

lastName = set_lastname;

SSN = set_ssn;

}

//method that returns the firstname

string Employee :: getFirstName()

{

return firstName;

}

//method that returns the lastname

string Employee :: getLastName()

{

return lastName;

}

//method that returns SSN

string Employee :: getSSN()

{

return SSN;

}

//method that sets firstname

void Employee :: setFirstName(string fname)

{

firstName = fname;

}

//method that sets lastname

void Employee :: setLastName(string lname)

{

lastName = lname;

}

//method that sets SSn

void Employee :: setSSN(string ssn)

{

SSN = ssn;

}

//method that returns fullname

string Employee :: getFullName()

{

return lastName + ", " + firstName;

}

//class HourlyEmployee that inherits Employee class

class HourlyEmployee: public Employee

{

private:

float hourlyRate;

int hrsWorked;

public:

HourlyEmployee(string, string, string, float, int);

float getHourlyRate();

int getHrsWorked();

void setHourlyRate(float);

void setHrsWorked(int);

double calcWeeklySalary();

};

//parameterized constructor, call the parent class parameterized constructor

HourlyEmployee:: HourlyEmployee(string fname, string lname, string ssn, float rate, int hrs) : Employee(fname, lname, ssn)

{

hourlyRate = rate;

hrsWorked = hrs;

}

//method that gets hourlyRate

float HourlyEmployee:: getHourlyRate()

{

return hourlyRate;

}

//method that gets hours worked

int HourlyEmployee:: getHrsWorked()

{

return hrsWorked;

}

//method that sets hourlyRate

void HourlyEmployee:: setHourlyRate(float rate)

{

hourlyRate = rate;

}

//method that sets hours worked

void HourlyEmployee:: setHrsWorked(int hrs)

{

hrsWorked = hrs;

}

double HourlyEmployee:: calcWeeklySalary()

{

double overtime = 0.0;

if (hrsWorked > 40)

{

overtime = (hrsWorked - 40)

* (0.5 * hourlyRate);

}

return overtime + hrsWorked * hourlyRate;

}

int main()

{

Employee emp1;

cout<<emp1.getFirstName()<<" "<<emp1.getLastName()<<" "<<emp1.getSSN()<<endl;

cout<<emp1.getFullName()<<endl;

Employee emp2("Alice", "Lackey", "291294949");

cout<<emp2.getFirstName()<<" "<<emp2.getLastName()<<" "<<emp2.getSSN()<<endl;

cout<<emp2.getFullName()<<endl;

HourlyEmployee hremp1("Tom", "Steele", "3235245", 7.8, 20);

cout<<hremp1.getFirstName()<<" "<<hremp1.getLastName()<<" "<<hremp1.getSSN()<<" "<<hremp1.getHourlyRate()<<" "<<hremp1.getHrsWorked()<<endl;

cout<<hremp1.getFullName()<<endl;

cout<<hremp1.calcWeeklySalary()<<endl;

hremp1.setFirstName("Bob");

hremp1.setLastName("Zhang");

hremp1.setSSN("9879870897");

hremp1.setHourlyRate(8.5);

hremp1.setHrsWorked(18);

cout<<hremp1.calcWeeklySalary()<<endl;

}

output:

unknown unknown unknown
unknown,unknown
Alice Lackey 291294949
Lackey,Alice
Tom Steele 3235245 7.8 20
Steele,Tom
156
153

Add a comment
Know the answer?
Add Answer to:
Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create an abstract class Employee. Your Employee class should include the following attributes: First name (string)...

    Create an abstract class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create an abstract method called earnings.      Create another class HourlyEmployee that inherits from the abstract Employee class.   HourEmployee must use the inherited parent class variables and add in attributes HourlyRate and HoursWorked. Your HourEmployee class should...

  • Create the class Book which has the following members: 1. private members: 1. title as String...

    Create the class Book which has the following members: 1. private members: 1. title as String 2. isbn as String 3. author as String 4. price as double 2. public members: 1. default constructor which initializes all data members to their default values. 2. non-default constructor which initializes all data members to parameters values. 3. toString which returns a representing String of the Book. 4. add all the setters and getters. Create the class EBook which is a subclass of...

  • employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name;...

    employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name; std::string address; std::string phoneNum; double hrWage, hrWorked; public: Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo); std::string getName(); void setName(std::string n); int getENum(); std::string getAdd(); void setAdd(std::string a); std::string getPhone(); void setPhone(std::string p); double getWage(); void setWage(double w); double getHours(); void setHours(double h); double calcPay(double a, double b); static Employee read(std::ifstream& in); void write(std::ofstream& out); }; employee.cpp ---------- //employee.cpp #include...

  • In one file create an Employee class as per the following specifications: three private instance variables:...

    In one file create an Employee class as per the following specifications: three private instance variables: name (String), startingSalary (int), yearlyIncrement (int) a single constructor with three arguments: the name, the starting salary, and the yearly increment. In the constructor, initialize the instance variables with the provided values. get and set methods for each of the instance variables. A computation method, computeCurrentSalary, that takes the number of years in service as its argument. The method returns the current salary using...

  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT