I am writing a program to calculate my paycheck. I am including in this program two functions to calculate sickleave and vacation leave.

I have a hireDate data member in the format of mm/dd/yyyy, how would I figure out length of employment to calculate aquired vacation and sick leave?

I have not used the ctime std lib and couldn't find much help on the net.

Heres what I have so far for my program

#ifndef HIREDATE_H
#define HIREDATE_H

class HireDate 
{
public:
   HireDate( int = 1, int = 1, int = 1900 ); // default constructor
   void print() const; // print date in month/day/year format
   ~HireDate(); // provided to confirm destruction order
private:
   int month; // 1-12 (January-December)
   int day; // 1-31 based on month
   int year; // any year

   // utility function to check if day is proper for month and year
   int checkDay( int ) const; 
}; // end class Date

#endif
#include <iostream>
using std::cout;
using std::endl;

#include "HireDate.h" // include Date class definition

// constructor confirms proper value for month; calls
// utility function checkDay to confirm proper value for day
HireDate::HireDate( int mn, int dy, int yr )
{
   if ( mn > 0 && mn <= 12 ) // validate the month
      month = mn;
   else 
   {                     
      month = 1; // invalid month set to 1
      cout << "Invalid month (" << mn << ") set to 1.\n";
   } // end else

   year = yr; // could validate yr
   day = checkDay( dy ); // validate the day
} // end Date constructor

// print Date object in form month/day/year
void HireDate::print() const
{
   cout << month << '/' << day << '/' << year; 
} // end function print

// HireDate Destructor
HireDate::~HireDate()
{ 

} // end ~Date destructor

// utility function to confirm proper day value based on 
// month and year; handles leap years, too
int HireDate::checkDay( int testDay ) const
{
   static const int daysPerMonth[ 13 ] = 
      { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

   // determine whether testDay is valid for specified month
   if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
      return testDay;

   // February 29 check for leap year 
   if ( month == 2 && testDay == 29 && ( year % 400 == 0 || 
      ( year % 4 == 0 && year % 100 != 0 ) ) )
      return testDay;

   cout << "Invalid day (" << testDay << ") set to 1.\n";
   return 1; // leave object in consistent state if bad value
} // end function checkDay
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include "HireDate.h"

#include <string>
using std::string;

class Employee
{
public:
    Employee( const string &, const string &, const string &, const HireDate & );
    ~Employee();

    void setFirstName( const string & );
    string getFirstName() const; 

    void setLastName( const string & );
    string getLastName() const;

    void setSocialSecurityNumber( const string & );
    string getSocialSecurityNumber() const;

    void print() const;

private:
    string firstName;
    string lastName;
    string socialSecurityNumber;
    const HireDate hireDate;
};

#endif
#include <iostream>
using std::cout;
using std::endl;

#include "Employee.h"
#include "HireDate.h"

//constructor
Employee::Employee(const string &first, const string &last, const string &ssn, const HireDate &dateOfHire )
    : firstName( first ), lastName( last ), socialSecurityNumber( ssn ), hireDate( dateOfHire )
{

}

Employee::~Employee()       //destructor
{

}

//function to set Employee's first name
void Employee::setFirstName( const string &first )
{
    firstName = first;
}

//function to get Employee's first name
string Employee::getFirstName() const
{
    return firstName;
}

//function to set Employee's last name
void Employee::setLastName( const string &last )
{
    lastName = last;
}

//function to get Employee's last name
string Employee::getLastName() const
{
    return lastName;
}

// function to set Employee's Social Security Number
void Employee::setSocialSecurityNumber( const string &ssn )
{
    socialSecurityNumber = ssn;
}

//function to get Employee's Social Security Number
string Employee::getSocialSecurityNumber() const
{
    return socialSecurityNumber;
}

//function to print Employee object
void Employee::print() const
{
    cout << "Employee: " << getFirstName() << ' ' << getLastName()
        << "\nSocial Security Number: " << getSocialSecurityNumber()
        << "\nDate Hired: " << &hireDate << endl;
}

Your comments and help is much appreciated

SHWOO

You obviously didn't look hard enough.

These are basic duration examples.

I need help using my mm/dd/yyyy, which is three int variables and getting a length of employment with the company so I can calculate the amount of vacation and sick leave.

The ctime library uses seconds since jan 1, 1970 and mine is three int so I don't know how I would do it.

Use the tm structure and the mktime function to convert your date into time_t. Then you can use difftime to calculate the difference in seconds. Then convert the seconds into units that you want.

And I stumbled upon this tutorial also.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.