본문 바로가기

전체 글

(182)
명품 C++ programming 실습 문제 9장 6번 문제 : 다음 AbstractStack은 정수 스택 클래스로서 추상 클래스이다. 1 2 3 4 5 6 7 class AbstrackStack { public: virtual bool push(int n) = 0; // 스택에 n을 푸시한다. 스택이 full이면 false 리턴 virtual bool pop(int& n) = 0; // 스택에서 팝한 정수를 n에 저장하고 스택이 empty이면 false 리턴 virtual int size() = 0; }; Colored by Color Scripter 이를 상속받아 정수를 푸시, 팝하는 IntStack 클래스를 만들고 사용 사례를 보여라. 목적 및 힌트 : 스택을 추상 클래스로 표현하고 구현하기 실행 결과 : 코드 : 1 2 3 4 5 6 7 8 9 10 ..
명품 C++ programming 실습 문제 9장 5번 문제 : 디지털 회로에서 기본적인 게이트로 OR 게이트, AND 게이트, XOR 게이트 등이 있다. 이들은 각각 두 입력 신호를 받아 OR 연산, AND 연산, XOR 연산을 수행한 결과를 출력한다. 이 게이트들을 각각 ORGate, XORGate, ANDGate 클래스로 작성하고자 한다. ORGate, XORGate, ANDGate 클래스가 AbstractGatef를 상속받도록 작성하라. 1 2 3 4 5 6 7 class AbstractGate { // 추상 클래스 protected: bool x, y; public: void set(bool x, bool y) { this->x = x; this->y = y; } virtual bool operation()=0; }; Colored by Color ..
명품 C++ programming 실습 문제 9장 4번 문제 : 다음 추상 클래스 LoopAdder가 있다. 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 class LoopAdder { // 추상 클래스 string name; // 루프의 이름 int x, y, sum; // x에서 y까지의 합은 sum void read(); // x, y 값을 읽어드리는 함수 void write(); // sum을 출력하는 함수 protected: LoopAdder(string name="") { // 루프의 이름을 받는다. 초깃값은 "" this->name = name; } int getX() { return x; } int getY() { return y; } vi..
명품 C++ programming 실습 문제 9장 3번 문제 : 다음 추상 클래스 LoopAdder가 있다. 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 class LoopAdder { // 추상 클래스 string name; // 루프의 이름 int x, y, sum; // x에서 y까지의 합은 sum void read(); // x, y 값을 읽어 들이는 함수 void write(); // sum을 출력하는 함수 protected: LoopAdder(string name="") { // 루프의 이름을 받는다. 초깃값은 "" this->name = name; } int getX() { return x; } int getY() { return y; } v..
명품 C++ programming 실습 문제 9장 2번 문제 : 다음은 단위를 변환하는 추상 클래스 Converter이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Converter { protected: double ratio; virtual double convert(double src)=0; // src를 다른 단위로 변환한다. virtual string getSourceString()=0; // src 단위 명칭 virtual string getDestString()=0; // dest 단위 명칭 public: Converter(double ratio) { this->ratio = ratio; } void run(){ double src; cout
명품 C++ programming 실습 문제 9장 1번 문제: 다음은 단위를 변환하는 추상 클래스 Converter이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include using namespace std; class Converter { protected: double ratio; virtual double convert(double src)=0; // src를 다른 단위로 변환한다. virtual string getSourceString()=0; // src 단위 명칭 virtual string getDestString()=0; // dest 단위 명칭 public: Converter(double ratio) { this->ratio = ratio; } void run(){ double src; cout