Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with question A. Need to define Push and Pop method in C++ stack.cpp #include stack.hpp using namespace std; template void Stack ::push(T c){

Need help with question A.

Need to define Push and Pop method in C++

image text in transcribed

stack.cpp

#include "stack.hpp"

using namespace std;

template void Stack::push(T c){ //define the push method here }

template T Stack::pop(){ //define the pop method here }

template T Stack::peek(){ if(topIndex

template int Stack::size(){ return topIndex+1; }

template void Stack::display(){ for(int i=topIndex; i>=0; --i){ cout

template class Stack; template class Stack;

stack.hpp

//#include #include #include #include #include

// Ideally this would not be a huge number, you could also use a vector #define MAXSIZE 100000

using namespace std; template class Stack{ private: T arr[MAXSIZE]; // the actual stack int topIndex; // index of the top element public: Stack(){ topIndex = -1; // constructor }; ~Stack(){}; // destructor void push(T c); // push c to the list T pop(); // return and remove the top element in the stack T peek(); // return the top element in the stack int size(); // returns the size of the stack void display(); // display the stack in stdout };

(100 points +10 bonus points) Instructions: Submit your answers and code on Canvas in a zip file. Include a brief README file explaining your code, especially if you implemented some of the suggestions for extra credit. We are providing some sample code and input files: public/ balancing.cpp - main method to check whether an expression is balanced infix2postfix.cpp - main method to transform an infix expression into postfix input_balanced.txt - test cases for balancing.cpp input_infix2postfix.txt - test cases for infixtopostfix.cpp input_postfixEval.txt - test cases for postfixEval.cpp postfixEval.cpp - main method to evaluate postfix expressions stack.cpp - stack implementation stack.hpp - stack header file extra_credit - work on the extra credit here Please use CSE machine to compile and execute your code. You can find how to use CSE machine on Canvas (CSE_machine.pdf). - To compile, run $ g++ stack.cpp balancing.cpp $g++ stack.cpp postfixEval.cpp $g++ stack.cpp infixtopostfix.cpp - To run each program, run \$./a.out - The test cases follow this format: expected_solution input. Given input, your job is to implement code that gets the expected_solution. Obviously, you need to calculate expected_solution, not just print it. - balancing.cpp must balance round parentheses, and square and curly brackets (O[]{}) - While we provide a few test cases, you are expected to add more to make sure your code works. Question: (a). (30points) Based on the stack.hpp file, implement a stack using array in the stack.cpp file. Specifically, you need to complete the push and pop method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago