C++

[C++] 명품 C++ 프로그래밍 실습문제 9장 5번

Hs’s Coding vlog 2023. 1. 14. 15:31

[C++]명품 C++ 프로그래밍 실습문제 9장 5번

[C++]명품 C++ programming 실습문제 9장 5번

명품 C++ 프로그래밍실습문제/연습문제 /C++

 

#include <iostream>
#include <string>

using namespace std;

class AbstractGate {
protected:
    bool x,y;
public:
    void set(bool x, bool y){this->x =x; this->y=y;}
    virtual bool operation()=0;
};




class ANDGate :public AbstractGate{
public:
    bool operation(){
        return x&y;
    }
};


class XORGate :public AbstractGate{
public:
    bool operation(){
        return x^y;
    }
};

class ORGate: public AbstractGate{
public:
    bool operation(){
        return x||y;
        
    }
    
};

int main(){
    
    ANDGate andGate;
    XORGate xorGate;
    ORGate  orGate;
    
    andGate.set(true,false);
    orGate.set(true,false);
    xorGate.set(true,false);
    cout.setf(ios::boolalpha); //불린 값을 true or false 문자열로 출력할것을 지시
    
    cout << andGate.operation() << endl;
    cout << orGate.operation() << endl;
    cout << xorGate.operation() << endl;


    return 0;
};