Question 1
// employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
class Employee
{
private:
string firstName;
string lastName;
float salary;
public:
// constructors
Employee();
Employee(string fName, string lName, float slry);
// mutators
void setFirstName(string fName);
void setLastName(string lName);
void setSalary(float slry);
// accessors
string getFirstName();
string getLastName();
float getSalary();
// destructor
~Employee();
};
#endif
,// employee.cpp
#include "employee.h"
Employee::Employee()
{
firstName = "";
lastName = "";
salary = 0;
}
Employee::Employee(string fName, string lName, float slry)
{
firstName = fName;
lastName = lName;
salary = slry;
}
void Employee::setFirstName(string fName)
{
firstName = fName;
}
void Employee::setLastName(string lName)
{
lastName = lName;
}
void Employee::setSalary(float slry)
{
salary = slry;
}
string Employee::getFirstName()
{
return firstName;
}
string Employee::getLastName()
{
return lastName;
}
float Employee::getSalary()
{
return salary;
}
Employee::~Employee()
, {
}
// question1.cpp
#include "employee.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
Employee employee1("Joe", "Soap", 145600.00);
Employee employee2;
string fn, ln;
float slry;
cout << "Enter employee first name: ";
cin >> fn;
cout << "Enter employee last name: ";
cin >> ln;
cout << "Enter salary: ";
cin >> slry;
employee2.setFirstName(fn);
employee2.setLastName(ln);
employee2.setSalary(slry);
// Annual salary of each employee before raise
cout<<fixed<<setprecision(2);
cout << "Employee 1 annual salary: R" << employee1.getSalary() << endl;
cout << "Employee 2 annual salary: R" << employee2.getSalary() << endl;
// Adding the raise to the employees
cout << "Employee 1 annual salary with raise: R" <<
employee1.getSalary()*1.1 << endl;
cout << "Employee 2 annual salary with raise: R" <<
employee2.getSalary()*1.1 << endl;
return 0;
}
// employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
class Employee
{
private:
string firstName;
string lastName;
float salary;
public:
// constructors
Employee();
Employee(string fName, string lName, float slry);
// mutators
void setFirstName(string fName);
void setLastName(string lName);
void setSalary(float slry);
// accessors
string getFirstName();
string getLastName();
float getSalary();
// destructor
~Employee();
};
#endif
,// employee.cpp
#include "employee.h"
Employee::Employee()
{
firstName = "";
lastName = "";
salary = 0;
}
Employee::Employee(string fName, string lName, float slry)
{
firstName = fName;
lastName = lName;
salary = slry;
}
void Employee::setFirstName(string fName)
{
firstName = fName;
}
void Employee::setLastName(string lName)
{
lastName = lName;
}
void Employee::setSalary(float slry)
{
salary = slry;
}
string Employee::getFirstName()
{
return firstName;
}
string Employee::getLastName()
{
return lastName;
}
float Employee::getSalary()
{
return salary;
}
Employee::~Employee()
, {
}
// question1.cpp
#include "employee.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
Employee employee1("Joe", "Soap", 145600.00);
Employee employee2;
string fn, ln;
float slry;
cout << "Enter employee first name: ";
cin >> fn;
cout << "Enter employee last name: ";
cin >> ln;
cout << "Enter salary: ";
cin >> slry;
employee2.setFirstName(fn);
employee2.setLastName(ln);
employee2.setSalary(slry);
// Annual salary of each employee before raise
cout<<fixed<<setprecision(2);
cout << "Employee 1 annual salary: R" << employee1.getSalary() << endl;
cout << "Employee 2 annual salary: R" << employee2.getSalary() << endl;
// Adding the raise to the employees
cout << "Employee 1 annual salary with raise: R" <<
employee1.getSalary()*1.1 << endl;
cout << "Employee 2 annual salary with raise: R" <<
employee2.getSalary()*1.1 << endl;
return 0;
}