You will write a console program that will meet the followin

You will write a console program that will meet the following requirements: Create a console program where you will implement coding constructs classes and variables that are needed for this program. Create an employee class. Declare all class variables as private. Declare class variables for salary, a string paygrade, and a constant double variable for base salary, string variables for employee last name, employee first name and an integer variable for employee job level. Create and implement properties (accessors) to get/set the values for employee last name, employee first name and employee level class variables. These should NOT be automatic properties; they will be used wherever these three class variables are referenced in the class. Create an employee class constructor that will receive the string last name, string first name and integer level when the class object is instantiated and use the accessors to assign the passed values. Create a public class method to calculate the salary, a public class method to set the paygrade and a public class method to display the output (as shown in the output example). The set paygrade class method will check the employee level and assign the string value of \"Entry Level\" if the level passed in is 1, \"Mid-Level\" if the level passed in is 2 and \"Senior Level\" if the level passed in is 3. The calculate salary class method will compute salary based on the following: If the level is 1 and paygrade is entry level then salary is the base salary times 1. If the level is 2 and paygrade is mid level then salary is the base salary times 3. If the level is 3 and paygrade is senior level then salary is the base salary times 5. The public display class method will display the information as shown in the output example shown below. In Main you will: Instantiate three (3) employee object passing the following to the constructor last name, first name and level number 1, 2 or 3 for each object respectively. For each instantiated object you will call the set paygrade, calculate salary and display employee class methods following instantiation of each object. You should format your output to look like the following: Employee Jack Spratt is a Entry Level with a salary of $35,000.00 Employee Jane Doe is a Mid-Level with a salary of $105,000.00 Employee John Smith is a Senior Level with a salary of $175,000.00 Press any key to continue . . .

Solution

#include<iostream>
#include<string.h>
using namespace std;
class Employee
{
//Private member of class
double salary;
int employeeJobLevel;
string payGrade, firstName, lastName;
static const double baseSalary = 5000;
public:
//Constructor
Employee(string, string, int);
//Get and set method declaration
string getFirstName();
void setFristName(string);
string getLastName();
void setLastName(string);
int getEmployeeJobLevel();
//Sets the employee job level
void setEmployeeJobLevel(int);
//Calculates the salary
void calculateSalary();
//Sets the pay grade
void setPayGrade();
//Display employee information
void display();
};
//Display employee information
void Employee::display()
{
cout<<\"\ Employee \"<<getFirstName()<<\" \"<<getLastName()<<\" is a \"<<getEmployeeJobLevel()<<\" with a salary of \"<<salary;
}
//Calculates employee salary
void Employee::calculateSalary()
{
//if job level is 1 then salary one time increase
if(employeeJobLevel == 1)
salary = baseSalary + baseSalary;
//if job level is 2 then salary three time increase
else if(employeeJobLevel == 2)
salary = baseSalary + (baseSalary * 3);
//if job level is 3 then salary five time increase
else if(employeeJobLevel == 3)
salary = baseSalary + (baseSalary * 5);
//For wrong level
else
cout<<\"\ ERROR: Wrong Level \";
}
//sets the pay grade
void Employee::setPayGrade()
{
//if level is 1
if(employeeJobLevel == 1)
payGrade = \"Entry Level\";
//if level is 2
else if(employeeJobLevel == 2)
payGrade = \"Mid-Level\";
//if level is 3
else if(employeeJobLevel == 3)
payGrade = \"Senior Level\";
//For wrong level
else
cout<<\"\ ERROR: Wrong Level \";
}
//Constructor for initializing
Employee::Employee(string fn, string ln, int l)
{
setFristName(fn);
setLastName(ln);
setEmployeeJobLevel(l);
}
//sets the employee job level
void Employee::setEmployeeJobLevel(int n)
{
employeeJobLevel = n;
}
//sets the last name
void Employee::setLastName(string s)
{
lastName = s;
}
//sets the first name
void Employee::setFristName(string s)
{
firstName = s;
}
//returns the first name
string Employee::getFirstName()
{
return firstName;
}
//returns the last name
string Employee::getLastName()
{
return lastName;
}
//returns the employee job level
int Employee::getEmployeeJobLevel()
{
return employeeJobLevel;
}
int main()
{
//creates 3 objects using parameterized constructor
Employee e1(\"Bishnu\", \"Sahu\", 1);
Employee e2(\"Sasmita\", \"Panda\", 2);
Employee e3(\"Pyari\", \"Mohan\", 3);

//call the setpaygrade method to set the grade
e1.setPayGrade();
e2.setPayGrade();
e3.setPayGrade();

//call the calculate salary to calculate salary for all employees
e1.calculateSalary();
e2.calculateSalary();
e3.calculateSalary();

//Displays the all employees information
e1.display();
e2.display();
e3.display();
}

Output:

Employee Bishnu Sahu is a 1 with a salary of 10000
Employee Sasmita Panda is a 2 with a salary of 20000
Employee Pyari Mohan is a 3 with a salary of 30000

You will write a console program that will meet the following requirements: Create a console program where you will implement coding constructs classes and vari
You will write a console program that will meet the following requirements: Create a console program where you will implement coding constructs classes and vari
You will write a console program that will meet the following requirements: Create a console program where you will implement coding constructs classes and vari

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site