Getting this Object Oriented logic to work

As a fore note: This program is troubling me for what i want to achieve. Please help as much as you can

The program that I have been given as a homework processes payroll for employees.
There are four types of employees. I have taken their birth date and hire date

Two things I want to achieve:

1- If current month = birth month of employee, then add 100 $ bonus to employee's earnings

2- Add 10% to the salary if the boss wants

Please help me in achieving these two objectives.

This is my base-class employee:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// employee.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <string>

#include "date.h"

using namespace std;

class Employee
{

public:

    Employee(const string &, const string &, const int, const Date &, const Date &);	  // constructor
    ~Employee();			// destructor

    void setFirstName(const string &);						  // sets first name
    string getFirstName() const;						      // returns first name

    void setLastName(const string &);				          // sets last name
    string getLastName() const;			                      // returns last name
    
    void setDepartmentCode(const int);					      // sets dept. code
    int getDepartmentCode() const;					          // returns dept. code

	Date getBirthDateObject() const;
	Date getHireDateObject() const;

	bool checkBirthMonth();									  // checks employee's birth month
    void addBonus();										  // adds bonus to employee's salary

    virtual double earnings() const = 0;		              // calculate earnings, pure virtual
    virtual void print() const;			                      // print employee's info, virtual 

private:
    
	string firstName;				// data member for employee's first name
    string lastName;				// data member for employee's second name

	Date birthDate;				    // object of class Date
	Date hireDate;					// object of class Date

	int departmentCode;				// data member for employee's department code
};  					// end class "Employee"

#endif 					// end 'employee.h' 


I don't know how to implement checkBirthMonth() and addBonus...

Here is my main function..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// main.cpp

#include <iostream>
#include <vector>

#include "salaried.h"
#include "hourly.h"
#include "base_plus_commissioned.h"

using namespace std;

int main()
{
	cout << "Employee payroll processed successfully!" << endl << endl;

	Date currentDate(20, 5, 2014);
	
	Date birth_emp1(5, 7, 1975);
	Date hire_emp1(3, 4, 1992);
	Salaried salEmp1("John", "Roberts", 25, 500, birth_emp1, hire_emp1);

    Date birth_emp2(2, 8, 1978);
	Date hire_emp2(15, 4, 1995);
	Hourly hrlyEmp1("Phil", "Brooks", 23, 5, 10, birth_emp2, hire_emp2);

	Date birth_emp3(25, 4, 1985);
	Date hire_emp3(30, 6, 2001);
    Commissioned commEmp1("Andy", "Leo", 12, 100, 500, birth_emp3, hire_emp3);

	Date birth_emp4(18, 7, 1960);
	Date hire_emp4(29, 4, 1989);
    Base_Plus_Commissioned bpcEmp1("Jack", "Benson", 43, 700, 250, 3000, birth_emp4, hire_emp4);
	
	// polymorphic action starts here

	vector<Employee *> empPtr(4);			// creating a vector of 4 base class pointers

	empPtr[0] = &salEmp1;
    empPtr[0]->print();
    cout << endl << "Total earnings: $" << empPtr[0]->earnings() << endl << endl;

    empPtr[1] = &hrlyEmp1;
	empPtr[1]->print();
    cout << endl << "Total Earnings: $" << empPtr[1]->earnings() << endl << endl;

    empPtr[2] = &commEmp1;
	empPtr[2]->print();
    cout << endl << "Total Earnings: $" << empPtr[2]->earnings() << endl << endl;

    empPtr[3] = &bpcEmp1;
	empPtr[3]->print();
    cout << endl << "Total Earnings: $" << empPtr[3]->earnings() << endl << endl;

	return 0;
}


The currentDate object doesnt seem to working here in this case..
Pleae tell me how to set current date and should I compare months one time in base class and add bonus as necessary or should I compare in every type of employee subclass?
Last edited on
What is Date? It looks like it's a class or a struct, but how does it work internally? Is it just a struct of three ints, or does it have member functions to help you?
I thinks I have managed to solve this problem... Thanks anyone for considering it. :)
Topic archived. No new replies allowed.