The Date class

The Date class will accept and validate the date. If itís valid, print the date in a proper way. If not,
send the error messages.
The class has the following private data members:
 an int named day that stores the day. It chooses between 1 and 31 based on month.
 an int named month that stores the month. It chooses between 1 and 12.
 an int named year that stores the year.
The class has the following public member functions:
 a constructor that accepts the day, month and year of the date as arguments. Check month.
If itís invalid, set it to 1. Call function checkDay() to check day. If no value are specified
when the object is declared, the default values are assigned to 1, 1 and 1900, respectively.
 an int checkDay() function that tests proper day for month and year. If the date is invalid, send
error messages and assign day to 1. For example, there are 31 days in January but 30 days in
April. 29 days exist in the February of Year 2000, but only 28 days exist in the February of
Year 2009. Why? As we know, leap year! You can use following formula to check leap year:
if (year % 400 ==0) || (year % 4 == 0 && year % 100 != 0) that year is a leap year.
 a print() function that prints the date in mm/dd/yyyy format.

The Employee class

The Employee class will hold the information of the staff.
The class has four private data members:
 a double staffID stores the ID number of the employee.
 a char type stores the type of job, and P represents part-time and F represents full-time.
 a const Date birthDate stores the birthday of the employee.
 a const Date hireDate stores the hire date of the employee.
The class has following public member functions:
 a constructor that sets staffID and type, and calls Date class to set the birthDate and
hireDate as well.
 a print() function prints the staff ID number and the type of job.


Date Header(Date.h)
Code:
#include <iostream>
using namespace std;
#include <string>

#ifndef _DATE_
#define _DATE_

class Date
{
private:
	int day;
	int month;
	int year;
public:
	Date( int = 1, int = 1, int = 1990 );//default constructor
	int checkDay();
	int checkMonth();
	int checkYear();
    void print(); 
	
};


#endif
Date Implementation(Date.cpp)
Code:
#include <iostream>
using namespace std;
#include <string>
#include <iomanip>

#include "Date.h"

Date::Date(int d, int m, int y)
{
	day = d;
	month = m;
	year = y;
}
int Date::checkDay()
{
	if (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) //months containing 31 days
		{
			if(d<1 || d>31) //day for month m is invalid
			{
            	cout<<"Day is invalid. Day value should be between 1 and 31 for month "<<m<<endl;
            	d=1;
            }
        }
	else if(m==4 || m==6 || m==9 || m==11) //months containing 30 days
		{
			if(d<1 || d>30) //day for month m is invali
			{
                cout<<"Day is invalid. Day value should be between 1 and 30 for month "<<m<<endl;
                d=1;
            }
            }
            else //m==2 february month
			{
				// year is not leap year if it is not integral multiple of 4
                //or year is not leap year if it is integral multiple of 100
                //but not integral multiple of 400
                if(y%4!=0 || (y%100==0 && y%400!=0))//year not leap year
				{
                    if(d<1 || d>28) //day for frebruary is invalid
					{
                        cout<<"Day is invalid. Day value should be between 1 and 28 for february in non-leap year"<<endl;
                        d=1;
                     }
                     }
					else //year is the leap year
					{
						if(d<1 || d>29) //day for frebuary is invalid
						{
							cout<<"Day is invalid. Day value should be between 1 and 29 for february in leap year"<<endl;
                            d=1;
                                		}
                                	 }
                            }
}
int Date::checkMonth()
{
	if (m<1 || m>12) //month is invalid
	{
        cout<<"Month is invalid. Month value should be between 1 and 12"<<endl;
        m=1;
    }
}
int Date::checkYear()
{
	if(y<0)
	{
		cout<<"Invalid year"<<endl;
        y=1990;
    }
}
void Date::print()
{
	cout << month << '/' << day << '/' << year; 
}
Employee Header(Employee.h)
Code:
#include <iostream>
using namespace std;
#include <string>

#ifndef _EMPLOYEE_
#define _EMPLOYEE_
	
#include "Date.h"

class Employee
{
private:
	double staffID;
	char type;
	const birthdate;
	const hiredate;
public:
	Employee();
	void setstaffID();
	void settype();
	void setbirthdate();
	void sethiredate();
	void print();
};

#endif
Employee Implementation(Employee.cpp)
Code:
#include <iostream>
using namespace std;
#include <string>
#include <iomanip>
#include <cassert>
#include "Employee.h"
	
#include "Date.h"

Employee::Employee()
{
	staffID=0;
	type="";
}
void Employee::setstaffID();
{
	cout<<"/nstaffID  :";
       cin>>staffID;
}
void Employee::settype();
{
	cout<<"/nJobType :";
       cin>>type;
}
void Employee::setbirthdate();
{
	cout<<"BirthDate :";
       cin>>birthdate;
}
void Employee::sethiredate()
{
    cout<<"/nHireDate : ";
       cin>>hiredate;
}
void Employee::print()
{
	cout<<"staffID  :"<<staffID<<endl;
	cout<<"JobType :"<<type<<endl;
}


Driver of Employee(DriverofEmployee.cpp)
Code:
#include <iostream>

using namespace std;

#include "Employee.h"

int main()
{
    //create three Employee class objects
	Employee e1(1001, 'F', 7, 24, 1969, 3, 12, 1998);
	Employee e2(1002, 'F', 2, 29, 1980, 5, 18, 2000);
	Employee e3(1003, 'P', 2, 28, 1979, 3, 31, 2007);
        
    //display the detail of staff
	e1.print();
	e2.print();
	e3.print();

    //test Date constructor with invalid values
	cout << "\nTest Date constructor with invalid values:  \n";
	
	//test whether 14 is a valid month or not;
	//test whether 35 is a valid day in a month or not 
	Date d1(14, 35, 1994); 
    
	//test whether 1979 is a leap year or not
	Date d2(2, 29, 1979); 

	cout << endl;

	return 0;
}// end function main