Write a C program that uses a header file Write a class defi

Write a C++ program that uses a header file.

Write a class definition for a class named Employee. It should include data members for a String type social security number, a String type employee name, and double type hours worked, hourly pay rate, net pay, deduction percentage, and gross pay. Include a constructor method that initializes the social security number and name to null string and the double type attributes to 0.0. Also include a method to assign values to each variable, a method to calculate grss pay (be sure to include overtime pay if hours worked are greater than 40), a method to calculate net pay (just subtract the deduction amount from the gross pay), and a method to display all of the Employee\'s attributes.

In a separate file, write a program to instantiate two Employee objects and for each employee:

(display the employee\'s default attributes.)

(get values from the user to store in social security number, name, hours worked, pay rate, and deduction percentage.)

(call the methods that calculate the employee\'s gross pay and net pay.)

(call the method to diplay the employee\'s attributes again.)

Run the program with hours equal to 35, pay rate equal to $9.50, and a deduction rate of 20% for the first employee, and hours equal to 47, pay rate equal to $10.25, and a deduction rate of 35% for the second employee. Use any values for name and social security number.

Solution

Employee.cpp

#include <iostream>
#include \"Employee.h\"

using namespace std;

class Employee{
    Employee::Employee(){
        string socialSecurityNumber = \"\";
        string name = \"\";
        double hoursWorked = 0.0;
        double hourlyPayRate = 0.0;
        double netPay = 0.0;
        double deductionPercentage = 0.0;
        double grossPay = 0.0;
    }

    void Employee::setSocialSecurityNumber(string ssn){
        socialSecurityNumber = ssn;
    }

    void Employee::setName(string empName){
        name = empName;
    }

    void Employee::setHourlyPayRate(double hpr){
        hourlyPayRate = hpr;
    }

    void Employee::setHoursWorked(double hw){
        hoursWorked = hw;
    }

    void Employee::setDeductionPercentage(double dp){
        deductionPercentage = dp;
    }

    double Employee::calculateGrossPay(){
        grossPay = hourlyPayRate * hoursWorked;
        return grossPay;
    }

    double Employee::calculateNetPay(){
        double gp = calculateGrossPay();
        netPay = gp - gp*deductionPercentage/100.0;
        return netpay;
    }

}

Employee.h

#ifndef Employee_H
#define Employee_H

class Employee{
private:
    string socialSecurityNumber;
    string name;
    double hoursWorked;
    double hourlyPayRate;
    double netPay;
    double deductionPercentage;
    double grossPay;
public:
    Employee();
    void setSocialSecurityNumber(string ssn);
    void setName(string empName);
    void setHourlyPayRate(double hpr);
    void setHoursWorked(double hw);
    void setDeductionPercentage(double dp);
    double calculateGrossPay();
    double calculateNetPay();
};

#endif

Driver.cpp

#include <iostream>
#include \"Employee.h\"

using namespace std;

int main(){
    Employee employee1 = new Employee();
    Employee employee2 = new Employee();
    employee1.setName(\"employee1\");
    employee1.setSocialSecurityNumber(\"SSN1\");
    employee1.setHoursWorked(35);
    employee1.setHourlyPayRate(9.50);
    employee1.setDeductionPercentage(20);
    employee2.setName(\"employee2\");
    employee2.setSocialSecurityNumber(\"SSN2\");
    employee2.setHoursWorked(47);
    employee2.setHourlyPayRate(10.25);
    employee2.setDeductionPercentage(35);
}

Write a C++ program that uses a header file. Write a class definition for a class named Employee. It should include data members for a String type social securi
Write a C++ program that uses a header file. Write a class definition for a class named Employee. It should include data members for a String type social securi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site