Lab 10
Lab 10
Enjoy!
Lab 10 - Learning Outcomes
At the end of this Lab 10, we will be able to …
Solve a problem by developing a C++ program along with some classes,
following the four steps of the software development process.
Use the class construct to develop a Stack data collection class and a
StackNode class.
Differentiate between private and public access modifiers and select the most
appropriate access modifiers when developing classes.
Write constructors, destructor, getters, setters and class-specific methods
(push(), pop(), peek()) for a Stack data collection class.
Sample Input 1:
Please, enter a word: rotator
Sample Output 1:
“rotator” is a palindrome.
Sample Input 2:
Please, enter a word: Yay! It works!
Sample Output 2:
“Yay! It works!” is not a palindrome.
Copyright © Anne Lavergne, School of Computing Science, Simon Fraser University 7
Lab Exercise
Step 1 - Problem Statement and Requirements:
There are many ways of solving this problem. In this Lab 10 Exercise, your
solution must make use of a Stack data collection class.
This Stack data collection class must use a linked list as its data structure.
This linked list must be made of Node (or StackNode) objects instantiated from
a Node (or StackNode) class. Therefore we cannot use typedef nor struct.
The data members of our classes must be private, expect for the Node (or
StackNode) class where public data members are acceptable.
The method members of our classes must be public. We can also have a few
private method members if necessary.
Algorithm:
Note that the steps in our algorithm can be used as comments in our program!
Attributes of a Stack:
Data structure (in this Lab 10: linked list)
Operations of a Stack:
push: Insert an element onto the top of the stack
pop: Remove the top most element of the stack
peek: Retrieve the top most element of the stack (but do not remove the
element)
isEmpty: Is the stack empty?
pop method only pops the element on the top of the Stack
peek method only peeks at the element on the top of the Stack
Therefore it is important to clearly define and indicate where the top of the
Stack is located.
3 7 5 8
top? top?
Enjoy!