//******************************************************************** // // salaried.cpp // CSCI 241 Inheritance and Polymorphism Example // //******************************************************************** #include #include #include "salaried.h" using std::cout; using std::endl; using std::string; /** * Constructor for salaried 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 salary The employee's weekly salary. * * @note The first name, last name, and ssn are passed to the base * class constructor. ********************************************************************/ salaried::salaried(const string& first_name, const string& last_name, const string& ssn, double salary) : employee(first_name, last_name, ssn) { set_salary(salary); } /** * Accessor function for weekly salary data member. * * @return The employee's weekly salary. ********************************************************************/ double salaried::get_salary() const { return salary; } /** * Mutator function for weekly salary data member. * * @param wage The new 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 salaried::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 salaried::earnings() const { return salary; } /** * Prints information for salaried employee. ********************************************************************/ void salaried::print() const { cout << "Salaried employee:\n"; // Call employee version of print() to print name and ssn. employee::print(); // Print remaining information. cout << "Weekly salary: $" << salary << endl; }