//******************************************************************** // // base_commission.cpp // CSCI 241 Inheritance and Polymorphism Example // //******************************************************************** #include #include "base_commission.h" using std::cout; using std::endl; using std::string; /** * Constructor for base salary plus commission employee. * * @param first_name The employee's first name. * @param last_name The employee's last name. * @param ssn The employee's Social Security Number. * @param sales The employee's gross sales for the week. * @param rate The employee's commission rate. * @param salary The employee's base weekly salary. * * @note The first name, last name, ssn, sales, and rate are passed * to the base class constructor. ********************************************************************/ base_commission::base_commission(const string& first_name, const string& last_name, const string& ssn, double sales, double rate, double salary) : commission(first_name, last_name, ssn, sales, rate) { set_salary(salary); } /** * Accessor function for base weekly salary data member. * * @return The employee's base weekly salary. ********************************************************************/ double base_commission::get_salary() const { return salary; } /** * Mutator function for base weekly salary data member. * * @param wage The new base weekly salary. * * @note If an attempt is made to set the salary to a negative value, * the salary will instead be set to 0. ********************************************************************/ void base_commission::set_salary(double salary) { this->salary = (salary < 0.0) ? 0.0 : salary; } /** * Computes the employee's earnings for the week. * * @return The computed earnings. ********************************************************************/double base_commission::earnings() const { return salary + commission::earnings(); } /** * Prints information for base salary plus commission employee. ********************************************************************/ void base_commission::print() const { cout << "Base salary plus commission employee:\n"; // Call employee version of print() to print name and ssn. employee::print(); // Print remaining information. cout << "Base salary: $" << salary << endl; cout << "Gross sales: $" << get_sales() << endl; cout << "Commission rate: " << get_rate() << endl; }