I need to figure out the test program for this problem. the one Ihave doesn\'t w
ID: 3618880 • Letter: I
Question
I need to figure out the test program for this problem. the one Ihave doesn't work.Create
a class called Employee that includes three pieces ofinformation as
data membersa first name (type string), a last name(type
string) and a monthly salary (type int). [Note:In subsequent chapters, we'll use numbers that
contain decimal points (e.g., 2.75)called floating-point valuestorepresent
dollar amounts.] Your class should have a constructor thatinitializes the three
data members. Provide a set and a get function for each datamember. If the monthly
salary is not positive, set it to 0. Write a test programthat
demonstrates class Employee's capabilities. Create two
Employee objects and display each object's yearly salary.Then give each Employee a 10
percent raise and display each Employee's yearly salaryagain.
#include<iostream>
using namespace std;
class Employee //Sample Class for the C++ Tutorial
{
private:
string firstName;//Data member
string lastName;// Data member
doublemonthlySalary; // Data member
public:
Employee(stringfname, string lname, double msalary) //Constructor for the C++tutorial
{
this.setFirstName(fname);
this.setLastName(lname);
this.setMonthlySalary(msalary);
}
~Employee() //destructor forthe C++ Tutorial
{ }
voidsetFirstName(string fname)
{
firstName = fname;
}
stringgetFirstName(void)
{
return firstName;
}
voidsetLastName(string lname)
{
lastName = lname;
}
stringgetLastName(void)
{
return lastName;
}
voidsetMonthlySalary(double msalary)
{
if(msalary >= 0)
this.setMonthlySalary(msalary);
else
cout<<"-------------Invalid Salary--------- "
}
doublegetMonthlySalary(void)
{
return monthlySalary;
}
doublecalculateYearlySalary(void)
{
return this.getMonthlySalary() * 12;
}
voidprint(void)
{
cout<<"/nFirst Name : "<<this.getFirstName();
cout<<"/nLast Name : "<<this.getLastName();
cout<<"/nMonthly Salary : "<<this.getMonthlySalary();
cout<<"/nYearly Salary : "<<this.calculateYearlySalary();
}
};
Explanation / Answer
x.