Please I submit this assignment before but I didn\'t get the right answer, I nee
ID: 3746939 • Letter: P
Question
Please I submit this assignment before but I didn't get the right answer, I need three files .cpp .h and the main file in separate files
Create an Employee class that includes three private data members— firstName (type string), lastName (type string), and monthlySalary (type int ).
It also includes several public member functions.
1. A constructor initializes the three data members.
2. A setFirstName function accepts a string parameter and does not return any data. It sets the firstName.
3. A getFirstName function does not accept any parameter and returns a string. It returns the firstName.
4. A setLastName function accepts a string parameter and does not return any data. It sets the lastName.
5. A getLastName function does not accept any parameter and returns a string. It returns the lastName.
6. A setMonthlySalary function accepts an integer parameter and does not return any data. It sets the monthlySalary. If the monthly salary is less than or equal zero, set it to 1000 and it displays the employee’s first name, last name and the inputted salary with a statement “**==The salary is set to $1000.”
7. A getMonthlySalary function does not accept any parameter and returns an integer. It returns the monthlySalary.
8. An increaseMonthlySalary function accepts an integer parameter and does not return any data. It increases the monthlySalary by integer%. The increase could be positive or negative. When this function is called the salary adjusted employee’s name and salary information will be displayed (please see the following image for details).
Explanation / Answer
Please fine below the required class
//employee.h
#include<string>
#include<iostream>
using namespace std;
//employee class
class Employee{
private:
string firstName,lastName;
int monthlySalary;
public:
Employee(string,string,int);
void setFirstName(string);
void setLastName(string);
void setMonthlySalary(int);
string getFirstName();
string getLastName();
int getMonthlySalary();
void increaseMonthlySalary(int);
};//end
//employee.cpp
/*
Implementation of employee class
*/
#include "employee.h"
Employee::Employee(string f, string l, int s){
firstName=f;
lastName=l;
setMonthlySalary(s);
}
void Employee::setFirstName(string f){
firstName = f;
}
void Employee::setLastName(string l){
lastName=l;
}
void Employee::setMonthlySalary(int s){
if(s<=0){
monthlySalary = 1000;
cout<<"The salary is set to $1000 for "<<firstName<<" "<<lastName<<endl;
}
else{
monthlySalary = s;
}
}
string Employee::getFirstName(){
return firstName;
}
string Employee::getLastName(){
return lastName;
}
int Employee::getMonthlySalary(){
return monthlySalary;
}
void Employee::increaseMonthlySalary(int i){
if(i==0){
return;
}
//if hike is negative
if(i<0){
int t = abs(i);
int amount = (getMonthlySalary() * t)/100;
setMonthlySalary(getMonthlySalary()-amount);
}//if hike is positive
else{
int amount = (getMonthlySalary() * i)/100;
setMonthlySalary(getMonthlySalary()+amount);
}
}//end
//main.cpp
#include "employee.h"
void print_emp(Employee);
int main(int argc, char const *argv[])
{
//created a employee object
Employee e("Rakesh","Kumar",2000);
print_emp(e);
cout<<"increasing salary to 10 % "<<endl;
e.increaseMonthlySalary(10);
cout<<"salary after hike : "<<e.getMonthlySalary()<<endl;
return 0;
}
void print_emp(Employee e){
cout<<"-----------Employee Info -----------------"<<endl;
cout<<"First Name : "<<e.getFirstName()<<endl;
cout<<"Last Name : "<<e.getLastName()<<endl;
cout<<"Monthly Salary : "<<e.getMonthlySalary()<<endl;
cout<<"------------------------------------------"<<endl;
}//end
//After saving them in three seprate file you can execute it with below command if uare using gnu compiler
g++ employee.cpp main.cpp -o emp
//after successfully compilation a exectuale emp will be generated you can run emp
//OUT put for my main
-----------Employee Info -----------------
First Name : Rakesh
Last Name : Kumar
Monthly Salary : 2000
------------------------------------------
increasing salary to 10 %
salary after hike : 2200
//You can add as many employee in main
//Please do let me know if u have any concern...