C++ Programming Ch.8 Exercise 6 Solution

Problem: 문제 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; } }; Write a 스택으로 작동하는 MyStack class that inherits from the BaseArray class. ...

March 9, 2020 · 3 min · Sobamemil

C++ Programming Ch.7 Exercise 11 Solution

Problem: 스택 클래스 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; Execution Result: ...

March 6, 2020 · 2 min · Sobamemil