Question
Overview This lab will have you make your first data structure of the semester, a Stack. We'll implement our stacks using the Node class we
Overview
This lab will have you make your first data structure of the semester, a Stack. We'll implement our stacks using the Node class we developed in lecture.
Please note, this is our first attempt at a Stack. We will make them more robust in future labs once we learn about templating and exceptions.
Provided Code
StackOfChar.h NOTE: We'll be using doxygen commenting format in our labs this semester. I've provided you example comments below.
But, you should comment all your files (top of file) and all class methods in your header files!
#ifndef STACKOFCHARS_H #define STACKOFCHARS_H class StackOfChars { private: Node* m_top; public: StackOfChars(); StackOfChars(const StackOfChars& orig); ~StackOfChars(); void operator=(const StackOfChars& rhs); /** Here's an example of a doxygen comment block. Do this for all methods * @pre None * @post entry is added to top of the stack * @param entry, the element to be added to the stack * @throw None **/ void push(char entry); /** Here's an example of a doxygen comment block. Do this for all methods * @pre Stack is non-empty * @post Top element is removed from the stack * @param None * @throw None **/ void pop(); char peek() const; bool isEmpty() const; }; #endif
Node.h
#ifndef NODE_H #define NODE_H class Node { private: char m_entry; Node* m_next; public: Node(char entry); char getEntry() const; void setEntry(char entry); Node* getNext() const; void setNext(Node* next); }; #endif
Do not add any more public methods to your Stack or Node classes.
Requirements
You will create a program that can ran in two modes, test mode and parser mode. From the command-line the user will decide if they want to launch your test suite (-t) or enter parser mode (-p).
Sample executions:
To enter test mode
$> ./lab02 -t
To enter parser mode
$> ./lab02 -p
Test Mode
Before attempting to use our Stacks to solve problems, we need to make sure they work. I have provided you with some starter tests that you must implement. You will also be required to add new tests for methods not mentioned here
Each test should be ran in isolation, meaning the tests could be run in any order and they don't share any objects/data.
Sample Test Output
$>./lab02 -t Test #1: New stack is empty: PASSED Test #2: Push on empty stack makes it non-empty: PASSED Test #3: Popping all all elements makes stack empty: FAILED Test #4: Copy constructor copies all elements in correct order: FAILED $>
StackTester class
- Runs a battery of tests to verify that our Stack is working
- Has a single entry point called runTests()
- Each test prints what test is currently running and if the Stack passed or failed
- Each test method should work in a vacuum, meaning tests shouldn't pass Stack objects from test to test
Sample StackTester.h
class StackTester { public: StackTester(); //This will call all your test methods void runTests(); private: /** * @brief Creates an empty stack and verifies isEmpty() returns true **/ void test01(); /** * @brief Creates an empty stack pushes 1 value, verifies isEmpty() returns false **/ void test02(); /** * @brief Creates an empty stack, then pushes once, pops once, and verifies isEmpty returns true **/ void test03(); //more test methods as needed };
Parser Mode
Once you know your Stack is working, begin working on parser mode. In this mode, the user will be allowed to enter a single string consisting of left and right curly braces. You must verify whether or not the sequence is balanced.
Example runs:
$>./lab02 -p Enter your sequence: {} Sequence is balanced. $>./lab02 -p Enter your sequence: }{ Sequence is not balanced. $>./lab02 -p Enter your sequence: {{{}} Sequence is not balanced. $>./lab02 -p Enter your sequence: {}{} Sequence is balanced. $>./lab02 -p Enter your sequence: {{{{{{}}}}}}{{{{{}}}}}{}{}{}{}{}{}{{}} Sequence is balanced.
I need some help with this lab. I have been working on it all week and I am pretty much lost altogether. At the very least if I could just get some help with the stacktester.h and stacktester.cpp, that would be very helpful. (C++)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started