Question

C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab...

C++
Lab 9B Inheritance

Class Production Worker

Create a project C2010Lab9b; add a source file Lab9b.cpp to the project. Copy and paste the code is listed below:

  1. Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information:
  • Shift (an integer)
  • Hourly pay rate (a double)

// Specification file for the ProductionWorker Class

#ifndef PRODUCTION_WORKER_H

#define PRODUCTION_WORKER_H

#include "Employee.h"

#include <string>

using namespace std;

class ProductionWorker // write clause here to derive from Employee base class.

{

private:

       // declare The worker's shift as int

       // declare The worker's hourly pay rate as a double

public:

       // Default constructor

       ProductionWorker() : Employee()

             { shift = 0; payRate = 0.0; }

       // Constructor

       ProductionWorker(string aName, string aNumber, string aDate,

             int aShift, double aPayRate) : Employee(aName, aNumber, aDate)

             { shift = aShift; payRate = aPayRate; }

       // Mutators

       void setShift(int s)

             { shift = s; }

       void setPayRate(double r)

             { payRate = r; }

       // Accessors

       int getShiftNumber() const

             { return shift; }

       string getShiftName() const

             {

       // write the logic for the getshiftName() accessor

             }

       double getPayRate() const

             { return payRate; }

};

#endif

  1. The workday is divided into two shifts: day and night. The shift variable will hold an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2.
  2. Write one or more constructors and the appropriate accessor and mutator functions for the class.
  3. Compile and run program. Copy and paste output into this word document.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#ifndef __PRODUCTION_WORKER___H
#define __PRODUCTION_WORKER___H
#include"employee.h"
#include<string>
using namespace std;

class ProductionWorker : public Employee {
    private:
        int shift;
        double payRate;
    public:
        ProductionWorker() : Employee(){
            shift = 0;
            payRate = 0.0;
        }

        ProductionWorker(string name, string number, string date, double shift, int rate)
            : Employee(name, number, date){
            this->shift = shift;
            this->payRate = rate;
        }

        ProductionWorker(int shift, double rate)
            : Employee(){
            this->shift = shift;
            this->payRate = rate;
        }

        void setShift(int shift) {
            this->shift = shift;
        }

        int getShiftNumber() {return shift;}

        void setPayRate(double rate) {
            this->payRate = rate;
        }

        double getPayRate() { return payRate;}

        string getShiftName() {
            switch(shift) {
                case 1:
                    return "day shift";
                case 2:
                    return "night shift";
                default:
                    return "shift not set";
            }
        }

        string getFullDetails() {
            return string("Production Worker : {")
                +string("\n\t Name   : "<<getName())
                +"\n\t Number : "<<getNumber()
                +"\n\t Date   : "<<getDate()
                +"\n\t Shift : "<<getShiftName()
                +"\n\t PayRate: "<<to_string(getPayRate())
                +"\n}"<<endl;
        }
};
#endif

#ifndef __EMPLOYEE__
#define __EMPLOYEE__
#include<iostream>
#include<string>
using namespace std;

class Employee {
    private:
        string name;
        string number;
        string date;
    public:
        Employee() {
            name = "Not specified";
            number = "Not specifed";
            date = "Not specified";
        }
        Employee(string empName, string empNumber, string empDate) {
            this->name = empName;
            this->number = empNumber;
            this->date = empDate;
        }
        void setName(string empName) {
            this->name = empName;
        }
        void setNumber(string empNumber) {
            this->number = empNumber;
        }
        void setDate(string empDate) {
            this->date = empDate;
        }
        string getName() {return name;}
        string getNumber() {return number;}
        string getDate() {return date;}
};

#endif

// Testing code

#include"productionworker.h"

using namespace std;

int main() {
    ProductionWorker pw("John", "1234", "19-Jun-98", 1, 2.45);
    cout<<pw.getFullDetails();
}

Add a comment
Know the answer?
Add Answer to:
C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab...
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
  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

  • Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so...

    Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private...

    HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private int empNumber;    private double hoursWorked;    private double payRate;       private static int hospitalEmployeeCount = 0;    //-----------------------------------------------------------------    // Sets up this hospital employee with default information.    //-----------------------------------------------------------------    public HospitalEmployee()    { empName = "Chris Smith"; empNumber = 9999; hoursWorked = 0; payRate =0;               hospitalEmployeeCount++;    }       //overloaded constructor.    public HospitalEmployee(String eName,...

  • JAVA HELP Design a class named Employee. The class should keep the following information in fields:...

    JAVA HELP Design a class named Employee. The class should keep the following information in fields: Employee name Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. Hire date then, Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to...

  • Design a class named Employee. The class should keep the following information in

    WRITE IN C++ ONLY PLEASE. IM USING VISUAL STUDIO CODE.1. Employee and ProductionWorker ClassesDesign a class named Employee. The class should keep the following information in• Employee name• Employee number• Hire dateWrite one or more constructors and the appropriate accessor and mutator functions for the class.Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information:• Shift (an integer)• Hourly pay rate (a double )The workday...

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds...

    USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...

  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

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