Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#ifndef BASEPLUS_H #define BASEPLUS_H #include <string> // C++ standard string c

ID: 3585251 • Letter: #

Question

#ifndef BASEPLUS_H
#define BASEPLUS_H

#include <string> // C++ standard string class

class BasePlusCommissionEmployee
{
public:
BasePlusCommissionEmployee( const std::string &, const std::string &,
const std::string &, double = 0.0, double = 0.0, double = 0.0 );

void setFirstName( const std::string & ); // set first name
std::string getFirstName() const; // return first name

void setLastName( const std::string & ); // set last name
std::string getLastName() const; // return last name

void setSocialSecurityNumber( const std::string & ); // set SSN
std::string getSocialSecurityNumber() const; // return SSN

void setGrossSales( double ); // set gross sales amount
double getGrossSales() const; // return gross sales amount

void setCommissionRate( double ); // set commission rate
double getCommissionRate() const; // return commission rate

void setBaseSalary( double ); // set base salary
double getBaseSalary() const; // return base salary

double earnings() const; // calculate earnings
void print() const; // print BasePlusCommissionEmployee object
private:
std::string firstName;
std::string lastName;
std::string socialSecurityNumber;
double grossSales; // gross weekly sales
double commissionRate; // commission percentage
double baseSalary; // base salary
}; // end class BasePlusCommissionEmployee

#endif

---------------------------------------------------------------------

#include <iostream>
#include <stdexcept>
#include "BasePlusCommissionEmployee.h" // class definition
using namespace std;

// constructor
BasePlusCommissionEmployee::BasePlusCommissionEmployee(
const string &first, const string &last, const string &ssn,
double sales, double rate, double salary )
{
firstName = first; // should validate
lastName = last; // should validate
socialSecurityNumber = ssn; // should validate
setGrossSales( sales ); // validate and store gross sales
setCommissionRate( rate ); // validate and store commission rate
setBaseSalary( salary ); // validate and store base salary
} // end BasePlusCommissionEmployee constructor

// set first name
void BasePlusCommissionEmployee::setFirstName( const string &first )
{
firstName = first; // should validate
} // end function setFirstName

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

// set last name
void BasePlusCommissionEmployee::setLastName( const string &last )
{
lastName = last; // should validate
} // end function setLastName

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

// set social security number
void BasePlusCommissionEmployee::setSocialSecurityNumber(
const string &ssn )
{
socialSecurityNumber = ssn; // should validate
} // end function setSocialSecurityNumber

// return social security number
string BasePlusCommissionEmployee::getSocialSecurityNumber() const
{
return socialSecurityNumber;
} // end function getSocialSecurityNumber

// set gross sales amount
void BasePlusCommissionEmployee::setGrossSales( double sales )
{
if ( sales >= 0.0 )
grossSales = sales;
else
throw invalid_argument( "Gross sales must be >= 0.0" );
} // end function setGrossSales

// return gross sales amount
double BasePlusCommissionEmployee::getGrossSales() const
{
return grossSales;
} // end function getGrossSales

// set commission rate
void BasePlusCommissionEmployee::setCommissionRate( double rate )
{
if ( rate > 0.0 && rate < 1.0 )
commissionRate = rate;
else
throw invalid_argument( "Commission rate must be > 0.0 and < 1.0" );
} // end function setCommissionRate

// return commission rate
double BasePlusCommissionEmployee::getCommissionRate() const
{
return commissionRate;
} // end function getCommissionRate

// set base salary
void BasePlusCommissionEmployee::setBaseSalary( double salary )
{
if ( salary >= 0.0 )
baseSalary = salary;
else
throw invalid_argument( "Salary must be >= 0.0" );
} // end function setBaseSalary

// return base salary
double BasePlusCommissionEmployee::getBaseSalary() const
{
return baseSalary;
} // end function getBaseSalary

// calculate earnings
double BasePlusCommissionEmployee::earnings() const
{
return baseSalary + ( commissionRate * grossSales );
} // end function earnings

// print BasePlusCommissionEmployee object
void BasePlusCommissionEmployee::print() const
{
cout << "base-salaried commission employee: " << firstName << ' '
<< lastName << " social security number: " << socialSecurityNumber
<< " gross sales: " << grossSales
<< " commission rate: " << commissionRate
<< " base salary: " << baseSalary;
} // end function print

--------------------------------------------------------------

#include <iostream>
#include <iomanip>
#include "BasePlusCommissionEmployee.h" // class definition
using namespace std;

int main()
{
// instantiate BasePlusCommissionEmployee object
BasePlusCommissionEmployee
employee( "Bob", "Lewis", "333-33-3333", 5000, .04, 300 );

// set floating-point output formatting
cout << fixed << setprecision( 2 );

// get commission employee data
cout << "Employee information obtained by get functions: "
<< " First name is " << employee.getFirstName()
<< " Last name is " << employee.getLastName()
<< " Social security number is "
<< employee.getSocialSecurityNumber()
<< " Gross sales is " << employee.getGrossSales()
<< " Commission rate is " << employee.getCommissionRate()
<< " Base salary is " << employee.getBaseSalary() << endl;

employee.setBaseSalary( 1000 ); // set base salary

cout << " Updated employee information output by print function: "
<< endl;
employee.print(); // display the new employee information

// display the employee's earnings
cout << " Employee's earnings: $" << employee.earnings() << endl;
} // end main

In this assignment you will modify the BasePlusCommissionEmployee code figures 11.7 thru 11.9 to handle a new class of employees that receive Per Diem pay for a special project. Per Diem pay is a flat amount per day that each employee gets in addition to the salary and commission. Per Diem pay cannot be a negative number but can be zero. Per Diem is added to earnings after base salary and commissions are calculated The output that is displayed to the user should show all of the information that is currently in BasePlusCommissionEmployee plus the amount of the Per Diem that they received.

Explanation / Answer

Hi,
Given we have to add a new field perDiem, we need to add this to the class definiton and change the methods accordingly, here is the full code, you can use the follwing code,
the header file:
#ifndef BASEPLUS_H
#define BASEPLUS_H
#include <string> // C++ standard string class
class BasePlusCommissionEmployee
{
public:
BasePlusCommissionEmployee( const std::string &, const std::string &,
const std::string &, double = 0.0, double = 0.0, double = 0.0 ,double=0.0);//added default 0

void setFirstName( const std::string & ); // set first name
std::string getFirstName() const; // return first name
void setLastName( const std::string & ); // set last name
std::string getLastName() const; // return last name
void setSocialSecurityNumber( const std::string & ); // set SSN
std::string getSocialSecurityNumber() const; // return SSN
void setGrossSales( double ); // set gross sales amount
double getGrossSales() const; // return gross sales amount
void setCommissionRate( double ); // set commission rate
double getCommissionRate() const; // return commission rate
void setBaseSalary( double ); // set base salary
double getBaseSalary() const; // return base salary
/*changes in next 2 lines*/
void setperDiem( double ); // set per diem
double getperDiem() const; // return per diem
double earnings() const; // calculate earnings
void print() const; // print BasePlusCommissionEmployee object
private:
std::string firstName;
std::string lastName;
std::string socialSecurityNumber;
double grossSales; // gross weekly sales
double commissionRate; // commission percentage
double baseSalary; // base salary
double perDiem;//declaring variable
}; // end class BasePlusCommissionEmployee
#endif
CPP file
#include <iostream>
#include <stdexcept>
#include "BasePlusCommissionEmployee.h" // class definition
using namespace std;
// constructor
BasePlusCommissionEmployee::BasePlusCommissionEmployee(
const string &first, const string &last, const string &ssn,
double sales, double rate, double salary,double perdiem )
{
firstName = first; // should validate
lastName = last; // should validate
socialSecurityNumber = ssn; // should validate
setGrossSales( sales ); // validate and store gross sales
setCommissionRate( rate ); // validate and store commission rate
setBaseSalary( salary ); // validate and store base salary
setperDiem(perdiem); //setting per diem value
} // end BasePlusCommissionEmployee constructor
// set first name
void BasePlusCommissionEmployee::setFirstName( const string &first )
{
firstName = first; // should validate
} // end function setFirstName
// return first name
string BasePlusCommissionEmployee::getFirstName() const
{
return firstName;
} // end function getFirstName
// set last name
void BasePlusCommissionEmployee::setLastName( const string &last )
{
lastName = last; // should validate
} // end function setLastName
// return last name
string BasePlusCommissionEmployee::getLastName() const
{
return lastName;
} // end function getLastName
// set social security number
void BasePlusCommissionEmployee::setSocialSecurityNumber(
const string &ssn )
{
socialSecurityNumber = ssn; // should validate
} // end function setSocialSecurityNumber
// return social security number
string BasePlusCommissionEmployee::getSocialSecurityNumber() const
{
return socialSecurityNumber;
} // end function getSocialSecurityNumber
// set gross sales amount
void BasePlusCommissionEmployee::setGrossSales( double sales )
{
if ( sales >= 0.0 )
grossSales = sales;
else
throw invalid_argument( "Gross sales must be >= 0.0" );
} // end function setGrossSales
// return gross sales amount
double BasePlusCommissionEmployee::getGrossSales() const
{
return grossSales;
} // end function getGrossSales
// set commission rate
void BasePlusCommissionEmployee::setCommissionRate( double rate )
{
if ( rate > 0.0 && rate < 1.0 )
commissionRate = rate;
else
throw invalid_argument( "Commission rate must be > 0.0 and < 1.0" );
} // end function setCommissionRate
// return commission rate
double BasePlusCommissionEmployee::getCommissionRate() const
{
return commissionRate;
} // end function getCommissionRate
// set base salary
void BasePlusCommissionEmployee::setBaseSalary( double salary )
{
if ( salary >= 0.0 )
baseSalary = salary;
else
throw invalid_argument( "Salary must be >= 0.0" );
} // end function setBaseSalary
// return base salary
double BasePlusCommissionEmployee::getBaseSalary() const
{
return baseSalary;
} // end function getBaseSalary
/* add 2 new method */
void BasePlusCommissionEmployee::setperDiem( double perdiem )
{
if ( perdiem >= 0.0 )
perDiem = perdiem;
else
throw invalid_argument( "perdiem must be >= 0.0" );
} // end function setperDiem
double BasePlusCommissionEmployee::getperDiem() const
{
return perDiem;
} // end function getperDiem
// calculate earnings
double BasePlusCommissionEmployee::earnings() const
{
return baseSalary + ( commissionRate * grossSales )+perDiem; //adding perDiem
} // end function earnings
// print BasePlusCommissionEmployee object
void BasePlusCommissionEmployee::print() const
{
cout << "base-salaried commission employee: " << firstName << ' '
<< lastName << " social security number: " << socialSecurityNumber
<< " gross sales: " << grossSales
<< " commission rate: " << commissionRate
<< " base salary: " << baseSalary;
} // end function print
main file

#include <iostream>
#include <iomanip>
#include "BasePlusCommissionEmployee.h" // class definition
using namespace std;
int main()
{
// instantiate BasePlusCommissionEmployee object
BasePlusCommissionEmployee
employee( "Bob", "Lewis", "333-33-3333", 5000, .04, 300,1.0 );//add one more arguement for perdiem

// set floating-point output formatting
cout << fixed << setprecision( 2 );
// get commission employee data
cout << "Employee information obtained by get functions: "
<< " First name is " << employee.getFirstName()
<< " Last name is " << employee.getLastName()
<< " Social security number is "
<< employee.getSocialSecurityNumber()
<< " Gross sales is " << employee.getGrossSales()
<< " Commission rate is " << employee.getCommissionRate()
<< " Base salary is " << employee.getBaseSalary()
<< " perDiem is " << employee.getperDiem() << endl;//add print statement
employee.setBaseSalary( 1000 ); // set base salary
cout << " Updated employee information output by print function: "
<< endl;
employee.print(); // display the new employee information

// display the employee's earnings
cout << " Employee's earnings: $" << employee.earnings() << endl;
} // end main
I have added extra comments wherever i made changes

Thumbs up if this was helpful, otherwise let me know in comments