Create a class called Employee with the following characteristics. There should be 5 private data types ID (unsigned int), Last name (string), first name (string), and hourly rate (float), and total salary earned (float). There should be 1 constructor that takes 4 arguments and populates the class data. It should be robust by ensuring that the hourly rate is above the minimum wage of $7.15/hour Create Get and Set methods to change of the 4 variables. Create a method 'float Pay( float nHours )' that returns the pay received by multiplying the hourly rate by the number of hours worked. This method should also add this value to a variable storing the total salary earned. Create a method to get the total amount of salary earned. Your main file should demonstrate that all methods and that they are working correctly.
#ifndef FINAL_H
#define FINAL_H
class Employee
{
private:
unsigned int ID;
string LastName;
string FirstName;
float HourlyRate;
float salary;
public:
Employee(); // default constructor
Employee(int, string, string, float);
void setID(int num) { ID = num ;}
void setLastName(string last) { LastName = last; }
void setFirstName(string first) { FirstName = first; }
void setHourlyRate( float rate) { HourlyRate = rate; }
float Pay( float nHours );
void Print();
int getID() { return ID; }
float getHourlyRate();
float getSalary();
};
#endif
#include <iostream>
#include <string>
using namespace std;
#include "final.h"
void main(void)
{
Employee guy_two;
guy_two.Print();
Employee guy(1, "Bell", "Stephen", 7.05);
cout<<endl;
guy.setFirstName("Joe");
guy.setLastName("Player");
guy.setHourlyRate(7.25);
guy.setID(22);
guy.Print();
cout<<"pay earned for work: "<<guy.Pay(30)<<endl;
cout<<guy.getSalary()<<endl;
return;
}
#include <iostream>
#include <string>
using namespace std;
#include "final.h"
using namespace std;
Employee::Employee()
{
ID = 0;
LastName = "no";
FirstName = "name";
HourlyRate = 0;
}
Employee::Employee(int ID, string LastName, string FirstName, float rate)
{
float min = 7.15;
if (rate < min)
rate = 7.15;
else
HourlyRate = rate;
this->ID = ID;
this->LastName = LastName;
this->FirstName = FirstName;
HourlyRate = rate;
}
float Employee::Pay(float hours)
{
float pay;
float salary = 0;
pay = HourlyRate*hours;
salary += pay;
return pay;
}
float Employee::getSalary()
{
return salary;
}
float Employee::getHourlyRate()
{
return HourlyRate;
}
void Employee::Print( )
{
cout << "Hourly rate: "<<HourlyRate << endl;
cout << "ID number: "<< ID << endl;
cout << LastName<<", "<<FirstName << endl;
}
I have written all this code myself, and now the problem I'm having is with the part about: "This method should also add this value to a variable storing the total salary earned. Create a method to get the total amount of salary earned." I can't figure out how to do this part. I'm an ME not CS but this is an entry level course required in my major... I do enjoy programming though :)
|