Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

IT Language 연습실

고용, 정규, 영업, 임시직 관련 된 클래스 만들기 본문

C++

고용, 정규, 영업, 임시직 관련 된 클래스 만들기

akongman 2024. 2. 25. 14:22
//고용 클래스
#include <iostream>
using namespace std;

namespace RISK_LEVEL { 
    enum {RISK_A = 30, RISK_B = 20, RISK_C = 10};
}

class employee {  //고용 클래스  
    const char *name;
    public :
    employee(const char *name) :name(name) {}
    
    void name_show() const { 
        cout<<"name: "<<name<<endl;
    }
    
    virtual void show()  const = 0; //순수가상함수 
    virtual int Getpay() const  = 0; 
};

class permanent_worker : public employee { //정규직 클래스
    int salary;
    public : 
    permanent_worker(const char *name, int pay) :employee(name), salary(pay) {}
    
    void show() const { 
        name_show();
        cout<<"salary: "<<Getpay()<<endl;
        cout<<endl;
    }
    
    int Getpay() const { 
       return salary; 
    }
    
}; 

class temporary_employee : public employee { //임시직 클래스
    int time_money; //시간당 급여 
    int run_time; // 일한 시간 
    public : 
    temporary_employee(const char * name, int pay) 
       : employee(name), time_money(pay), run_time(0) {}
       
    void run_time_init(int n) {  
        run_time += n; 
    }
    
    void show() const { 
        name_show();
        cout<<"salary: "<<Getpay()<<endl;
        cout<<endl;
    }
    
    int Getpay() const { 
        return time_money * run_time;
    }
    
};

class sales : public permanent_worker {  //영업직 클래스
    int sales_figures; //판매실적 
    double Incentive; //인센티브 
    
    public : 
    sales(const char *name, int pay, double p_Incentive) 
        : permanent_worker(name,pay), sales_figures(0), Incentive(p_Incentive) {}
        
    void sales_figures_init(int n) { 
        sales_figures += n;
    }
    
    void show() const { 
        name_show();
        cout<<"salary: "<<Getpay()<<endl;
        cout<<endl;
    }
    
    int Getpay() const { 
        return permanent_worker::Getpay() + (int)(sales_figures * Incentive);
    }
    
};

class ForeignSalesWorker : public sales{ //해외 영업직
    const int risk_Incentive; 
    
    public : 
    ForeignSalesWorker(const char *name, int pay, double p_Incentive, int p_risk_Incentive) 
       : sales(name,pay,p_Incentive), risk_Incentive(p_risk_Incentive) {}
    
    void show() const { 
        name_show();
        cout<<"salary: "<<Getpay()<<endl;
        cout<<"risk pay: "<<risk_pay()<<endl;
        cout<<"sum: "<<Getpay()+risk_pay()<<endl;
        cout<<endl;
    }
    
    int Getpay() const { 
        return sales::Getpay();
    }
    
    int risk_pay() const { 
        return Getpay() * (risk_Incentive/100.0);
    }
    
};

class employee_handler { //컨트롤 클래스
    employee *array[50];   
    int length;
    
    public : 
    void addpeple(employee *ptr) { 
        array[length++] = ptr;
    }
    
    void allinformation_show() { 
        for(int i=0; i<length; i++) { 
            array[i]->show();   //*(array[i])가 가리키고 있는 것은 정규직이고 배열의 타입은 employee임. 
        }
    }
    
    void pay_information() { 
       int sum = 0 ;
       for(int i=0; i<length;i++) { 
           sum += array[i]->Getpay();
       }
       cout<<"salary sum: "<<sum<<endl;
    }
    
    ~employee_handler() { 
        for(int i=0; i<length; i++) { 
            delete array[i];
            cout<<"삭제"<<endl;
        }
    }
    
};

int main() {
    /********************************** 정규직 ***********************************/
    employee_handler handler;
    handler.addpeple(new permanent_worker("Kim", 1000));  // 정규직 사원 등록
    handler.addpeple(new permanent_worker("Lee", 1500));
    
    /********************************** 임시직 ***********************************/
    temporary_employee *t_handler = new temporary_employee("Jung", 700);
    t_handler->run_time_init(5);
    handler.addpeple(t_handler); // 임시직 사원 등록.
    
    /********************************** 영업직 ***********************************/
    sales *s_handler = new sales("Hong", 1000, 0.1);
    s_handler->sales_figures_init(7000);
    handler.addpeple(s_handler); // 영엄직 사원 등록. 
    
    /********************************** 해외 영업직 ***********************************/
    ForeignSalesWorker *Foreign_handler = new ForeignSalesWorker("Hong", 1000, 0.1, RISK_LEVEL::RISK_A);
    Foreign_handler->sales_figures_init(7000);
    handler.addpeple(Foreign_handler); // 해외 영업직 사원 등록 
    
    ForeignSalesWorker *Foreign_handler2 = new ForeignSalesWorker("Lee", 1000, 0.1, RISK_LEVEL::RISK_B);
    Foreign_handler2->sales_figures_init(7000);
    handler.addpeple(Foreign_handler2); // 해외 영업직 사원 등록 
    
    ForeignSalesWorker *Foreign_handler3 = new ForeignSalesWorker("Yoon", 1000, 0.1, RISK_LEVEL::RISK_C);
    Foreign_handler3->sales_figures_init(7000);
    handler.addpeple(Foreign_handler3); // 해외 영업직 사원 등록 
    
    handler.allinformation_show();  // 모든 사원 정보 출력.
    handler.pay_information(); // 이번 달 총 지출 급여 출력.
}

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

C++ split( )  (0) 2024.03.23
C++ 공부하면서 정리한 것들  (0) 2024.02.25
C++ 스타일에 맞는 형변환  (0) 2024.02.25
template (4) 클래스 ver  (0) 2024.02.23
스마트 포인터 (Smart Pointer)  (0) 2024.02.22