C++ please ! Activities Google Chrome FloorFen × Assignme Thu 17:02 in C++Wi xin
ID: 3751295 • Letter: C
Question
C++ please !
Activities Google Chrome FloorFen × Assignme Thu 17:02 in C++Wi xin Beginne L My Drive × O Untitled X G calculate x G unt anve x G setand g x G cheggsx a solved:× calculati chapter x 3pdf Assignment 36 PROBLEM 2: Payroll processing (includes DATA VALIDATION) Create a class called Employee that represents the following payroll information (private) for Name Hourly rate (decimal n Create the following public member functions. (Note that the program may not require all functions to be used, but they should all exist for a complete class.) Set value for namesee ba set value tor rate see belo Set value for hours (see bal Calculates and returns the gross pay ¡see note below) Returns the hours worked Returns the hourly rate (use bool return for data validation). Data must be validated in the set functions (NOT main). User data is passed to the set (hours/rate/name) which will test the data first and use a boolean return value to signal if the data was good or bad. If any data is invalid, error message is given IN MAIN and the user is allowed to re-enter. Writ e a test program to prompt the user to input the name, h Calculate and display the gross pay. (Note: Make sure overtime hours are paid at time-and-a- half) See sample output below. Note that you may not use ALL of the class functions in the application, but they should still all be there to have a complete classs. Sample Output (note formattin Fnter employee's name: Name cannot be blank, re-enter: John Doe Enter houra 7orkea: -50 lours must be positive re enter O Enter hourly rate: -10 Hourly rate must be positive, re-enter 10 lab03.pdf Show allxExplanation / Answer
If you have any doubts, please give me comment...
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Employee
{
public:
bool setName(string name){
if(name=="")
return false;
this->name = name;
return true;
}
bool setRate(double rate){
if(rate<0)
return false;
this->rate = rate;
return true;
}
bool setHours(double hours){
if(hours<0)
return false;
this->hours = hours;
return true;
}
double getPay(){
double pay = hours*rate;
if(hours>40)
pay += (hours-40)*rate*0.5;
return pay;
}
double getHours(){
return hours;
}
double getRate(){
return rate;
}
string getName(){
return name;
}
private:
string name;
double hours;
double rate;
};
int main()
{
string name;
double hours, rate;
Employee *emp = new Employee;
char another;
do{
cout<<"Enter employee's name: ";
while(1){
getline(cin, name);
if(emp->setName(name))
break;
cout<<"Name cannot be blank, re-enter: ";
}
cout<<"Enter hours worked: ";
while(1){
cin>>hours;
if(emp->setHours(hours))
break;
cout<<"Hours must be positive. re-enter: ";
}
cout<<"Enter hourly rate: ";
while(1){
cin>>rate;
if(emp->setRate(rate))
break;
cout<<"Hourly rate must be positive, re-enter: ";
}
cout<<setprecision(2)<<fixed;
cout<<" Gross pay for "<<emp->getName()<<": $"<<emp->getPay()<<endl<<endl;
cout<<"Another employee? (Y/N): ";
cin>>another;
//for buffering
getline(cin, name);
}while(another!='Y' || another!='y');
cout<<"Press any key to continue";
cin>>another;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.