C++

C++ 문제 풀이

khon98 2021. 1. 11. 16:06

[부모 클래스]

  조건2. class Cleaning cpp 구현해야 되는 내용

 

     - static int m_total_personner; .cpp 파일에서 초기화 합니다.

     - int m_personnel;  .cpp 생성자에서 초기화합니다..

 

     해당 함수는 부모 클래스(class Cleaning)에 구현합니다.

     void setCleaningPersonnel(int person);

     int getCleaningPersonner();

 

 [분야별 클래스 구현]

    1 바닥청소 / 창문청소 / 화장실 청소 분야별 클래스를 부모클래스를 상속받아 구현합니다.

    2 각 분야별 청소 객체를 main 함수에서 동적 생성합니다.

    3 각 분야 객체별로 setCleaningPersonnel 함수를 사용해서 바닥청소 5 / 창문청소 10 / 화장실청소 8명으로 지정하고

아래 [결과물] [결과물]과 같이 출력되야 됩니다.

      

       - 청소 준비 : (생성자)에서생성자) 출력

       - 청소 시작 : run() 함수에서 출력

       - 총 청소 인원 : main 함수에서 출력

       - 청소 종료 : (소멸자)에서소멸자) 출력

 

[결과물]

 

 [청소 준비]

 [Child] 바닥 청소 클래스 준비!

 [Child] 창문 청소 클래스 준비!

 [Child] 화장실 청소 클래스 준비!

 

 [청소 시작]

 ==>[실행] 바닥 청소 5명 시작!

 ==>[실행] 창문 청소 10명 시작!

 ==>[실행] 화장실 청소 8명 시작!

 

 [총 청소 인원]

 ==>[실행] 23명이 청소를 하고 있습니다.

 

 [청소 종료]

 [Child] 바닥 청소 클래스 종료!

 [Child] 창문 청소 클래스 종료!

 [Child] 화장실 청소 클래스 종료!

 

--------------------------------------------------

main.cpp

 

#include <iostream>
#include "Cleaning.hpp"
#include "FloorCleaning.hpp"
#include "WindowCleaning.hpp"
#include "BathroomCleaning.hpp"

using namespace std;

int main(int argc, const char * argv[]) {
    FloorCleaning* fc = new FloorCleaning;
    WindowCleaning* wc = new WindowCleaning;
    BathroomCleaning* bc = new BathroomCleaning;
    
    fc->setCleaningPersonnel(5);
    wc->setCleaningPersonnel(10);
    bc->setCleaningPersonnel(8);
    
    fc->run();
    wc->run();
    bc->run();
    
    printf(" 총 청소 인원 : 총 %d명이 청소를 하고 있습니다\r\n", Cleaning::getTotalCleaningPersonner());
    
    delete fc;
    delete wc;
    delete bc;
    
    return 0;
}

--------------------------------------------------

 

 

--------------------------------------------------

Cleaning.cpp

 

#include <iostream>
#include "Cleaning.hpp"

// 구현부

int Cleaning::m_total_personner = 0; // 전체 청소 인원수 초기화

Cleaning :: Cleaning() { // 생성자
    m_personnel = 0; // 분야별 청소 인원수 초기화
}

Cleaning :: ~Cleaning() { // 소멸자
}

//분야별 청소 인원 세팅
void Cleaning :: setCleaningPersonnel(int person){
    m_personnel = person;
    m_total_personner += person;
}

//분야별 청소 인원 수 가져오는 함수
int Cleaning:: getCleaningPersonner() {
    return m_personnel;
}

// 전체 청소 인원수
int Cleaning::getTotalCleaningPersonner() {
    return m_total_personner;
}

--------------------------------------------------

 

 

--------------------------------------------------

FloorCleaning.cpp

 

#include <iostream>
#include "FloorCleaning.hpp"

using namespace std;

FloorCleaning :: FloorCleaning() {
    cout << " 청소 준비 : 바닥 청소 클래스 준비" << endl;
}

FloorCleaning :: ~FloorCleaning() {
    cout << " 청소 종료 : 바닥 청소 클래스 청소 종료" << endl;
}

void FloorCleaning :: run() {
    printf(" 청소 시작 : 바닥 청소 %d명 시작\r\n", getCleaningPersonner());
}

--------------------------------------------------

 

 

--------------------------------------------------

WindowCleaning.cpp

 

#include <iostream>
#include "WindowCleaning.hpp"

using namespace std;

WindowCleaning::WindowCleaning(){
    cout << " 청소 준비 : 창문 청소 클래스 청소 준비" << endl;
}

WindowCleaning::~WindowCleaning(){
    cout << " 청소 종료 : 창문 청소 클래스 청소 종료" << endl;
}

void WindowCleaning::run(){
    printf(" 청소 시작 : 창문 청소 %d명 시작\r\n", getCleaningPersonner());
}

--------------------------------------------------

 

 

--------------------------------------------------

BathroomCleaning.cpp

 

#include <iostream>
#include "BathroomCleaning.hpp"

using namespace std;

BathroomCleaning::BathroomCleaning(){
    cout << " 청소 준비 : 화장실 청소 클래스 청소 준비" << endl;
}

BathroomCleaning::~BathroomCleaning(){
    cout << " 청소 종료 : 화장실 청소 클래스 청소 종료" << endl;
}

void BathroomCleaning::run(){
    printf(" 청소 시작 : 화장실 청소 %d명 청소 시작\r\n", getCleaningPersonner());
}

--------------------------------------------------

 

 

--------------------------------------------------

Cleaning.hpp

 

//
//  CCleaning.hpp
//  Test201226
//
//  Created by DongOh Lim on 2020/12/26.
//

#ifndef CCleaning_hpp
#define CCleaning_hpp

#include <stdio.h>

// 선언부
class Cleaning {
private:
    static int m_total_personner; // 전체 청소 인원수
    int m_personnel;              // 분야별 청소 인원수
public:
    Cleaning();             // 생성자
    virtual ~Cleaning();    // 소멸자
    
    //분야별 청소 인원 세팅
    void setCleaningPersonnel(int person);
    
    //분야별 청소 인원 수 가져오는 함수
    int getCleaningPersonner();
    
    //전체 청소인원
    static int getTotalCleaningPersonner();
    
    // 청소 시작 함수
    virtual void run() = 0;
};

#endif

--------------------------------------------------

 

 

--------------------------------------------------

FloorCleaning.hpp

 

#ifndef FloorCleaning_hpp
#define FloorCleaning_hpp

#include <iostream>
#include <stdio.h>
#include "Cleaning.hpp"

using namespace std;

class FloorCleaning : public Cleaning {
public:
    FloorCleaning();
    
    ~FloorCleaning();
    
    virtual void run();
};
#endif /* FloorCleaning_hpp */

--------------------------------------------------

 

 

--------------------------------------------------

WindowCleaning.hpp

 

#ifndef WindowCleaning_hpp
#define WindowCleaning_hpp

#include <stdio.h>
#include "Cleaning.hpp"

class WindowCleaning : public Cleaning {
public:
    WindowCleaning();
    
    ~WindowCleaning();
    
    virtual void run();
};

#endif /* WindowCleaning_hpp */

--------------------------------------------------

 

 

--------------------------------------------------

BathroomCleaning.hpp

 

#ifndef BathroomCleaning_hpp
#define BathroomCleaning_hpp

#include <stdio.h>
#include "Cleaning.hpp"

class BathroomCleaning : public Cleaning {
public:
    BathroomCleaning();
    
    ~BathroomCleaning();
    
    virtual void run();
};

#endif /* BathroomCleaning_hpp */

--------------------------------------------------