(Employee Class) Create a class called Employee that includes three pieces of information as data members—a 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 values—to represent dollar amounts.] Your class should have a constructor that

initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Em- ployee a 10 percent raise and display each Employee’s yearly salary again.

What will be an ideal response?


```
// Employee class definition.

#include // program uses C++ standard string class
using namespace std;

// Employee class definition
class Employee
{
public:
Employee( string, string, int ); // constructor sets data members
void setFirstName( string ); // set first name
string getFirstName(); // return first name
void setLastName( string ); // set last name
string getLastName(); // return last name
void setMonthlySalary( int ); // set monthly salary
int getMonthlySalary(); // return monthly salary
private:
string firstName; // Employee's first name
string lastName; // Employee's last name
int monthlySalary; // Employee's salary per month
}; // end class Employee
```
```
// Employee class member-function definitions.
#include
#include "Employee.h" // Employee class definition
using namespace std;

// Employee constructor initializes the three data members
Employee::Employee( string first, string last, int salary )
{
setFirstName( first ); // store first name
setLastName( last ); // store last name
setMonthlySalary( salary ); // validate and store monthly salary
} // end Employee constructor

// set first name
void Employee::setFirstName( string name )
{
firstName = name; // no validation needed
} // end function setFirstName

// return first name
string Employee::getFirstName()
{
return firstName;
} // end function getFirstName

// set last name
void Employee::setLastName( string name )
{
lastName = name; // no validation needed
} // end function setLastName

// return last name
string Employee::getLastName()
{
return lastName;
} // end function getLastName

// set monthly salary; if not positive, set to 0
void Employee::setMonthlySalary( int salary )
{
if ( salary > 0 ) // if salary is positive
monthlySalary = salary; // set monthlySalary to salary

if ( salary <= 0 ) // if salary is not positive
monthlySalary = 0; // set monthlySalary to 0
} // end function setMonthlySalary

// return monthly salary
int Employee::getMonthlySalary()
{
return monthlySalary;
} // end function getMonthlySalary
```
```
// Create and manipulate two Employee objects.
#include
#include "Employee.h" // include definition of class Employee
using namespace std;

// function main begins program execution
int main()
{
// create two Employee objects
Employee employee1( "Lisa", "Roberts", 4500 );
Employee employee2( "Mark", "Stein", 4000 );

// display each Employee's yearly salary
cout << "Employees' yearly salaries: " << endl;

// retrieve and display employee1's monthly salary multiplied by 12
int monthlySalary1 = employee1.getMonthlySalary();
cout << employee1.getFirstName() << " " << employee1.getLastName()
<< ": $" << monthlySalary1 * 12 << endl;

// retrieve and display employee2's monthly salary multiplied by 12
int monthlySalary2 = employee2.getMonthlySalary();
cout << employee2.getFirstName() << " " << employee2.getLastName()
<< ": $" << monthlySalary2 * 12 << endl;

// give each Employee a 10% raise
employee1.setMonthlySalary( monthlySalary1 + monthlySalary1 / 10 );
employee2.setMonthlySalary( monthlySalary2 + monthlySalary2 / 10 );

// display each Employee's yearly salary again
cout << "\nEmployees' yearly salaries after 10% raise: " << endl;

// retrieve and display employee1's monthly salary multiplied by 12
monthlySalary1 = employee1.getMonthlySalary();
cout << employee1.getFirstName() << " " << employee1.getLastName()
<< ": $" << monthlySalary1 * 12 << endl;

monthlySalary2 = employee2.getMonthlySalary();
cout << employee2.getFirstName() << " " << employee2.getLastName()
<< ": $" << monthlySalary2 * 12 << endl;
return 0; // indicate successful termination
} // end main
```
Employees' yearly salaries:
Lisa Roberts: $54000
Mark Stein: $48000
Employees' yearly salaries after 10% raise:
Lisa Roberts: $59400
Mark Stein: $52800

Computer Science & Information Technology

You might also like to view...

What does the command line vty 0 5 mean?

What will be an ideal response?

Computer Science & Information Technology

A(n) ____is a single, separate file with a .css file extension that can be attached to a page in a web site.

A. inline style sheet B. format-specific style sheet C. internal style sheet D. external style sheet

Computer Science & Information Technology

Describe the Windows 8 reset ability.

What will be an ideal response?

Computer Science & Information Technology

A Chief Information Security Officer (CISO) is concerned the development team, which consists of contractors, has too much access to customer data. Developers use personal workstations, giving the company little to no visibility into the development activities. Which of the following would be BEST to implement to alleviate the CISO's concern?

A. DLP B. Encryption C. Test data D. NDA

Computer Science & Information Technology