Sunday, December 17, 2017

Programming Challenge 14.6 - Personell Report

Example Files: PersonellReport.7z

The following changes have been applied to the TimeOff.h and TimeOff.cpp files:
- A constructor accepting a string object and an integer and a default constructor has been added
- The ternary previously in the constructor has been placed in the setMaxVacation() function. This, function is now also called from the constructor.
- MAX_PAID has been moved to the global space of the classes header file

PersonellReport.h


#ifndef PERSONELL_REPORT_H_
#define PERSONELL_REPORT_H_

#include "TimeOff.h"

const int SICK_DAYS = 8;                // The number of sick days added per month
const int VAC_DAYS = 12;                // The number of paid vacation days added per month

class PersonellReport
{
    private:
        int     monthsEmployed;            // To hold a number of months
        TimeOff daysOff;                    // A TimeOff object
       
    public:
        PersonellReport(const TimeOff &, int);

        void addMaxSickDays(int m)
        {
            daysOff.setMaxSick(m * SICK_DAYS);
        }

        void addMaxVacation(int m)
        {
            daysOff.setMaxVacation(m * VAC_DAYS);
        }

        void print();

        int getMonthsEmployed() const
        { return monthsEmployed; }
};

#endif

PersonellReport.cpp


#include "PersonellReport.h"

#include <iostream>
using std::cout;

/* **********************************************************
       PersonellReport::PersonellReport() : Constructor
   ********************************************************** */

PersonellReport::PersonellReport(const TimeOff &t, int m)
{
    daysOff = t;
    monthsEmployed = m;

    addMaxSickDays(m);
    addMaxVacation(m);
}

/* **********************************************************
            PersonellReport::print()  
    This function outputs an employee's ID, name, months of
    employment, the number of days of sick leave, 8 per month,
    and the number of days of paid vacation, 12 per month, the
    employee is entitled to consume.
   ********************************************************** */

void PersonellReport::print()
{
    cout << "\nEmployee ID:   " << daysOff.getEmployeeID() << "\n";
    cout << "Employee Name:  " << daysOff.getEmployeeName() << "\n";
    cout << "Employed since: " << getMonthsEmployed() << " month(s)\n\n";

    cout << "This employee is granted the following:\n\n";
    cout << "A maximum number of " << daysOff.getMaxSick() << " sick days.\n";
    cout << "A maximum number of " << daysOff.getMaxVacation() << " days of paid vacation.";
}

PersonellReportDm.cpp


#include "PersonellReport.h"
#include "TimeOff.h"

#include <iostream>
using std::cin;
using std::cout;

int main()
{
    int months = 0;

    TimeOff empOne("Precious Ramotswe", 1);
   
    cout << "No. 1 Ladies' Detective Agency - Personell Report\n\n";
    cout << "Employee ID:   " << empOne.getEmployeeID() << "\n";
    cout << "Employee Name: " << empOne.getEmployeeName() << "\n\n";
       
    cout << "Enter number of months of employement (1 through 360): ";
    cin >> months;

    while (months <= 0 || months > 360)
    {
        cout << "Enter number of months of employement (1 through 360): ";
        cin >> months;
    }

    PersonellReport one(empOne, months);
    one.print();

    cin.get();
    cin.ignore();
   return 0;
}

Example Output:



No comments:

Post a Comment