명품 C++ programming 실습 문제 8장 6번

문제 : 문제 5~6에 적용되는 BaseArray 클래스는 다음과 같다. 1 2 3 4 5 6 7 8 9 10 11 12 class BaseArray { int capacity; // 배열의 크기 int *mem; // 정수 배열을 만들기 위한 메모리의 포인터 protected: // 생성자가 protected BaseArray(int capacity=100){ this->capacity = capacity; mem = new int [capacity]; } ~BaseArray() { delete [] mem; } void put(int index, int val) { mem[index] = val; } int get(int index) { return mem[index]; } int getCapacity() { return capacity; } }; BaseArray 클래스를 상속받아 스택으로 작동하는 MyStack 클래스를 작성하라. ...

March 9, 2020 · 3 min · Sobamemil

명품 C++ programming 실습 문제 7장 11번

문제 : 스택 클래스 Stack을 만들고 푸시(push)용으로 « 연산자를, 팝(pop)을 위해 » 연산자를, 비어 있는 스택인지를 알기 위해 ! 연산자를 작성하라. 다음 코드를 main()으로 작성하라. 1 2 3 4 5 6 7 8 9 Stack stack; stack « 3 « 5 « 10; // 3,5,10 순서대로 push while(true){ if(!stack) break; //stack empty int x; stack » x; //stack의 top에 있는 정수 pop cout « x « ’ ‘; } cout « endl; 실행 결과 : ...

March 6, 2020 · 2 min · Sobamemil