Question

Create a C++ project Create an Employee class using a separate header file and implementation file....

Create a C++ project

Create an Employee class using a separate header file and implementation file.

    • The calculatePay() method should return 0.0f.
    • The toString() method should return the attribute values ("state of the object").
  • Create an Hourly class using a separate header file and implementation file.
    • The Hourly class needs to inherit from the Employee class
    • The calculatePay() method should return the pay based on the number of hours worked and the pay rate. Remember to calculate overtime!
  • Create a Salary class using a separate header file and implementation file.
    • The Salary class needs to inherit from the Employee class.
    • The calculatePay() method should return the annualSalary divided by 52.0f because there are 52 weeks in the year.
  • Create a Manager class using a separate header and implementation file.
    • The Manager class needs to inherit from the Salary class (yes, a Child class can be a Parent class).
    • The calculatePay() method should use the Salary's calculatePay() method plus the bonus divided by 52.0f (base pay plus bonus).
  • Add a Source.cpp file to your project.

  • Create a main method for your application.
  • In the main method, create three objects—one object using each of the three classes.
  • Display the size of the Hourly object. Then, display the size of the first object's memory address (remember, & means "address of").
    • The memory address (pointer) is only 4 bytes. However, the Hourly object is huge! If we send the Hourly object across the system bus to the method, it will take rather a lot of time. However, if we pass the pointer across the system bus to the method, it will travel quickly! Pointers make our applications faster!
  • Create a method called displayEmployee that accepts an Employee pointer as the parameter. Because Employee is the parent, it can hold child objects. In other words, I can send an Hourly, Salary, or Manager object to this method using the Employee parameter! Here is the prototype:

          void displayEmployee(Employee* emp);
  • In the displayEmployee method, show the object's information one line at a time, including the Weekly Pay (do not use the toString method). Notice that we only have access to the Employee class methods. We do not have access to the specific child methods.
  • In the displayEmployee method, convert the Employee object back to the child state. Then, display the specific child information using one line at a time. We use "dynamic_cast" to convert the object back to the child form. If it is the correct data type, we get an object. If it is the incorrect data type, then we get "NULL". Here is the code for the Manager object.

         Manager* mgr = dynamic_cast<Manager*>(emp);    // try to convert Employee parent object to a Manager child object
         if( mgr != NULL )                                                        // if the mgr is not NULL, then we have a Manager object!
         {
              cout << "Bonus: $" << mgr->getBonus( ) << endl;
         }
  • Go back to the main method. Call the displayEmployee method, and send it the address of the Hourly object. Then, call the displayEmployee method, and send it the address of the Salary object. Finally, call the displayEmployee method, and send it the address of the Manager object.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

string Hourly::toString() // #include <sstream> in Hourly.h
{
stringstream ss;
ss << "PayRate :" << hourlyRate << endl;
ss << "Hours Worked:" << hoursWorked << endl;
return ss.str();
}

Salary.h

/* Salary.h */

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

using namespace std;

class Salary : public Employee {

private:
float annualSalary;
public:
Salary(float a);
float calculatePay();
string toString();
  
};


Salary.cpp

#include "Salary.h"
using namespace std;

Salary::Salary(float a){
annualSalary = a;
}


float Salary::calculatePay(){
return annualSalary/52.0;
}
string Salary::toString(){
stringstream ss;
ss << "Annual Salary: $" << annualSalary;
return ss.str();
}

/* Manager.h */

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

using namespace std;

class Manager : public Salary {

private:
float bonus;
public:
Manager(float a, float b):public Salary(a){
bonus = b;
}
float calculatePay();
string toString();
};


Manager.cpp

#include "Manager.h"
using namespace std;

float Manager::calculatePay(){
return Salary::calculatePay + bonus/52.0;
}
string Salary::toString(){
stringstream ss;
ss << "Bonus: $" << bonus;
return Salary::toString() + "/n" + ss.str();
}

Add a comment
Know the answer?
Add Answer to:
Create a C++ project Create an Employee class using a separate header file and implementation file....
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
  • This is done in C++ Create an Employee class using a separate header file and implementation...

    This is done in C++ Create an Employee class using a separate header file and implementation file. Review your UML class diagram for the attributes and behaviors The calculatePay() method should return 0.0f. The toString() method should return the attribute values ("state of the object"). Create an Hourly class using a separate header file and implementation file. The Hourly class needs to inherit from the Employee class The calculatePay() method should return the pay based on the number of hours...

  • The purpose of this lab is to practice the concept of inheritance. We will create an...

    The purpose of this lab is to practice the concept of inheritance. We will create an Hourly class that is an Employee class. In other words, the Hourly class inherits from the Employee class. In addition, we will create a Salary class that inherits from the Employee class. Finally, we will make a Child class work as a Parent class. We will create a Manager class that inherits from the Salary class. Create a C++ project, and call it Week...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

  • IN C++ MUST INCLUDE HEADER FILE, IMPLEMENTATION FILE, AND DRIVER FILE. IN C++ Create a header...

    IN C++ MUST INCLUDE HEADER FILE, IMPLEMENTATION FILE, AND DRIVER FILE. IN C++ Create a header and implementation file to define an apartment class. Create a driver program to test the class, and create a make file to compile the driver program. Create two files called apartment.h and appartmentImp.cpp along with creating a driver program named testApartment.cpp containing the main function. Program Requirements: • Class attributes should include integers for number of rooms, monthly rent, and square feet, as well...

  • C++ project we need to create a class for Book and Warehouse using Book.h and Warehouse.h header ...

    C++ project we need to create a class for Book and Warehouse using Book.h and Warehouse.h header files given. Then make a main program using Book and Warehouse to read data from book.dat and have functions to list and find book by isbn Objectives: Class Association and operator overloading This project is a continuation from Project 1. The program should accept the same input data file and support the same list and find operations. You will change the implementation of...

  • Create another Java class named EmployeeMain within the same project, which includes the main method. a....

    Create another Java class named EmployeeMain within the same project, which includes the main method. a. Include another class named Employee in the same Java file. This class has the following instance variables and instance methods. Define all the instance/static variables with private access modifier and constructors, instance/static methods with public access modifier. Instance Variables empID: int employeeName: String basicSalary: double Constructor Set the value for empID. Instance Methods Get and set methods for all instance variables. displayEmployee: Display the...

  • Use C++ Create a Student header file (C++) . Declare the following operations in the file....

    Use C++ Create a Student header file (C++) . Declare the following operations in the file. setName() setMarks() setDateOfBirth() calculateGrade() - This method should compute and return grades based on the mark the student entered calculateAge() - This method should compute and return age using the DateOfBirth the user entered displayDetails() - This method should return a string displaying all the details of the user. Now write the implementation class for the header file. Now reuse these C++ Code in...

  • 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...

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