Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in C++, please read all of instruction before starting. I put some text in bold

ID: 3804382 • Letter: I

Question

in C++, please read all of instruction before starting. I put some text in bold because those are important. Please help me..

Design a PayRoll class that has data members for an employee's first and last name, hourly pay rate, number of hours worked. The default constructor will set the first and last name to empty string, and hours worked and pay rate to zero. The class must have mutator functions to set each of the data members of the class and accessors to access them The class should also have the following member functions

1. displayPayroll function that displays all data members of the a PayRoll instance on one line separated by blanks

2. readPayRoll function that reads data members of a PayRoll instance from an input stream associated with a text file (important please!!!) assume all data members are on one line separated by commas)

3. getGross function that will return a double calculated by multiplying the hours worked by the pay rate. Driver program: Write a program with an array of seven PayRoll objects. The program should read the name (first and last), pay rate and the number of hours for each employee and display each employee information followed by the employee's gross pay, all on one line separated by blanks. Set the precision for printing the doubles to two decimal places.

Input Validation:

1. Do not accept values greater than 60 for the number of hours worked, simply have the set function set number of hours worked to 60, the maximum allowed.

2. Do not accept negative values for pay rate and hours worked (set them to 00 3. Be sure to include an employee claiming to work more than 60 hours per week, negative pay rate, and negative hours worked.

Explanation / Answer

#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <cstdlib>


using namespace std;

class PayRoll
{
   private:
       string name;
int hours;
float payRate;

public:
PayRoll(){}

~PayRoll(){}
  
   void setName(string PayRollName){
       name = PayRollName;
   }
  
void setHours(int hours1){
if(hours1 > 60){
hours = 60;
}else{
hours = hours1;
}
   }
  
   void setPayRate(float payRate1) {
   if(payRate1 < 0){
   payRate1 = 00.3;
   }else{
   payRate = payRate1;
   }
   }
  
   string getName(){
       return name ;
   }
  
int getHours() {
       return hours;
   }
  
   float getPayRate() {
   return payRate;
   }
          
void printPayRollInfo();
  
   void setValues(string line);
  
   double getGross(int workHours,float payRatePerHour);
  
};

double PayRoll:: getGross(int workHours,float payRatePerHour){
float grossFigure = 0.0;
double dValue = 0;
grossFigure = workHours * payRatePerHour;
return dValue = static_cast<double>(grossFigure);
}

//printing
void PayRoll:: printPayRollInfo()
{
cout << "Name : " << name << " ";
cout << "hours : " << hours << " ";
cout << "payRate : " << payRate << " " <<endl;
}

void PayRoll:: setValues(string line){
  
   std::string s = line;
   std::string delimiter = ",";
   s = s + delimiter;
size_t pos = 0;
std::string token;
int count = 0;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
if(count == 0){
setName(token);
}
if(count == 1){
int h = std::atoi(token.c_str());
setHours(h);
}
if(count == 2){
float f = std::atof(token.c_str());
setPayRate(f);
}
count++;
s.erase(0, pos + delimiter.length());
}
}

int main()
{
std::ifstream file("Newfile.txt");
std::string line;
vector<PayRoll> tokens;
PayRoll *f2 = NULL;
  
while(std::getline(file, line)) { // ' ' is the default delimiter
f2 = new PayRoll;
f2->setValues(line);
tokens.push_back(*f2);
}
  
vector<PayRoll>::iterator it;
for ( it = tokens.begin(); it != tokens.end(); ++it ) {
double grossfigure = it->getGross(it->getHours(),it->getPayRate());
cout << "Name : " << it->getName() << " ";
cout << "hours : " << it->getHours() << " ";
cout << "payRate : " << it->getPayRate() << " " ;
cout << "grossfigure : " << grossfigure << " " <<endl;
}

return 0;
}

Description:

Class PayRoll have following functions

1. mutator ( setter) functions to set each of the data members

2. getter functions to get the data members.

3. printPayRollInfo - display all the records avaibale in text file in comma seperated form.

4. Program can take any number of records instead of hardcoded 7 object.

5. getGross function which return double value

6. if the work hours is mentioned greater than 60 then the above program will convert it into default value 60.

7. If the pay rate is mentioned in negative or less then zero then the above program will convert it into default 00.3 and make calculation accordingly.

Output ;

sh-4.2$ main                                                                                                                                                         

Name       : john       hours        : 60       payRate     : 8.3       grossfigure     : 498                                                                        

Name       : brain      hours        : 60       payRate     : 9.7       grossfigure     : 582                                                                        

Name       : lara       hours        : 60       payRate     : 12.3      grossfigure     : 738   

Newfile.txt

--------------

john,134.3,8.3
brain,134.6,9.7
lara,123.3,12.3