/*
 EmployeeManager3.cpp
*/

#include <iostream>
#include <string.h>

using std::cout;
using std::endl;

/*=======================================*/
/*           */
/*    Employee Class    */
/*           */
/*=======================================*/

class Employee
{
protected :
    char name[20];

public :
    Employee(const char* _name);
    const char* GetName() const;
};

Employee::Employee(const char* _name)
{
    strcpy(name, _name);
}

const char* Employee::GetName() const
{
    return name;
}


/*=======================================*/
/*           */
/*        Permanent Class           */
/*           */
/*=======================================*/

class Permanent : public Employee
{
private :
    int salary;

public :
    Permanent(const char* _name, int sal);
    int GetPay() const;
};

Permanent::Permanent(const char* _name, int sal) : Employee(_name)
{
    salary = sal;
}

int Permanent::GetPay() const
{
    return salary;
}

/*=======================================*/
/*           */
/*        Temporary Class            */
/*           */
/*=======================================*/
class Temporary : public Employee
{
private :
    int time;
    int pay;

public :
    Temporary(const char* _name, int _time, int _pay);
    int GetPay() const;
};

Temporary::Temporary(const char *_name, int _time, int _pay) : Employee(_name)
{
    time = _time;
    pay  = _pay;
}

int Temporary::GetPay() const
{
    return time * pay;
}

/*=======================================*/
/*           */
/*        Department Class           */
/*           */
/*=======================================*/
class Department
{
private :
    Employee* empList[100];
    int index;

public :
    Department() : index(0) {};
    void AddEmployee(Employee* emp);
    void ShowList() const;
};

void Department::AddEmployee(Employee *emp)
{
    empList[index++] = emp;
}

void Department::ShowList() const
{
    for(int i = 0; i < index; i++)
    {
        cout<<"name   : "<<empList[i]->GetName()<<endl;
        //cout<<"salary : "<<empList[i]->GetPay()<<endl;
        cout<<endl;
    }
}

/*=======================================*/
/*           */
/*         Main Function             */
/*           */
/*=======================================*/
int main(void)
{
    Department dept;

    //직원등록
    dept.AddEmployee(new Permanent("KIM", 1000));
    dept.AddEmployee(new Permanent("PARK", 1500));

    dept.AddEmployee(new Temporary("HAN", 10, 200));
    dept.AddEmployee(new Temporary("JANG", 12, 300));

    dept.ShowList();

    return 0;
}

반응형

'C, C++, Java' 카테고리의 다른 글

P304.cpp  (0) 2014.05.02
CPointer2.cpp  (0) 2014.05.02
Person.cpp  (0) 2014.04.30
P256.cpp  (0) 2014.04.30
Student.cpp  (0) 2014.04.30

+ Recent posts