Design and Develop Classes Scenarios 1) Class name is Employee has the attribute
ID: 3918284 • Letter: D
Question
Design and Develop Classes Scenarios
1) Class name is Employee has the attributes: empID (an integer), first name (a string), last name (a string), hourly pay rate (a decimal), hours worked (a list of seven decimals). The methods should include: a constructor that sets all of the attributes to either 0 or empty string “”, a set function for each attribute, a setAll function that assigns arguments each attribute, a get function for each attribute, a totalHours function that returns the total number of hours worked, a weeklyPay function that returns the total pay for the week.
Create a class diagram
Create the class specification/interface – Define class in C++
Create a class implementation – Define methods in C++
Constructor sets all of the attributes to either 0 or empty string “”
A set function for each attribute
A get function for each attribute that returns the value of the attribute
A totalHours function that returns the total number of hours worked
A weeklyPay function that returns the total pay for the week
Hours past 40 pay at 1.5 times the hourly rate
Add the class interface and implementation to a test driver – Define main driver in C++
Explanation / Answer
//Employee.h
#pragma once
#include<iostream>
#include<string>
using namespace std;
class Employee
{
int empID;
string firstName;
string lastName;
double payRate;
double hoursWorked;
public:
Employee();
void set_empID(int id);
void set_firstName(string name);
void set_lastName(string name);
void set_payRate(double rate);
void set_hoursWorked(double hours);
void setAll(int id, string fname, string lname, double rate, double hours);
int get_empID();
string get_firstName();
string get_lastName();
double get_payRate();
double totalHours();
double weeklyPay();
};
---------------------------------------------------------
//Employee.cpp
#include"Jul_27_Emp.h"
Employee::Employee()
{
empID = 0;
firstName = "";
lastName = "";
payRate = 0;
hoursWorked = 0;
}
void Employee::set_empID(int id)
{
empID = id;
}
void Employee::set_firstName(string name)
{
firstName = name;
}
void Employee::set_lastName(string name)
{
lastName = name;
}
void Employee::set_payRate(double rate)
{
payRate = rate;
}
void Employee::set_hoursWorked(double hours)
{
hoursWorked = hours;
}
void Employee::setAll(int id, string fname, string lname, double rate, double hours)
{
empID = id;
firstName = fname;
lastName = lname;
payRate = rate;
hoursWorked = hours;
}
int Employee::get_empID()
{
return empID;
}
string Employee::get_firstName()
{
return firstName;
}
string Employee::get_lastName()
{
return lastName;
}
double Employee::get_payRate()
{
return payRate;
}
double Employee::totalHours()
{
return hoursWorked * 5; //hours worked per day * 5 days of work in a week
}
double Employee::weeklyPay()
{
return payRate * totalHours();
}
---------------------------------------------------------------------------------------------------
//main.cpp
#include"Jul_27_Emp.h"
int main()
{
Employee emp,emp1;
emp.setAll(1234, "John", "Ronald", 20.56, 8);
//test all the indivual set functions
emp1.set_empID(1243);
emp1.set_firstName("Mary");
emp1.set_lastName("Smith");
emp1.set_payRate(24.89);
emp1.set_hoursWorked(8.5);
//now print the info onto screen
cout << "EmpID: " << emp.get_empID() << ", First Name: " << emp.get_firstName() << " ,Last Name: " << emp.get_lastName() << " ,Hourly Rate: " << emp.get_payRate() << ", Total hour worked: " << emp.totalHours() << " , Weekly pay: $" << emp.weeklyPay() << endl;
cout << "EmpID: " << emp1.get_empID() << ", First Name: " << emp1.get_firstName() << " ,Last Name: " << emp1.get_lastName() << " ,Hourly Rate: " << emp1.get_payRate() << ", Total hour worked: " << emp1.totalHours() << " , Weekly pay: $" << emp1.weeklyPay() << endl;
}
/*output
EmpID: 1234, First Name: John ,Last Name: Ronald ,Hourly Rate: 20.56, Total hour worked: 40 , Weekly pay: $822.4
EmpID: 1243, First Name: Mary ,Last Name: Smith ,Hourly Rate: 24.89, Total hour worked: 42.5 , Weekly pay: $1057.83
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.