Question: Here is the stack class: // implementation file for the stack class #include using namespace std; const int stack_size = 100; class stack { private:

 Here is the stack class: // implementation file for the stack
Here is the stack class:
// implementation file for the stack class
#include
using namespace std;
const int stack_size = 100;
class stack
{
private:
char data [stack_size]; // array of stack elements
int top; // top is the index of the top element of the stack
public:
stack (); // creates an empty stack
void push (char item); // pushes item on top of stack
char pop (); // removes and returns top of stack
bool empty (); // returns true if stack is empty
bool full (); // returns true if stack is full
};
// constructor creates an empty stack
stack::stack ()
{
top = -1;
}
// push adds item to the top of the stack
void stack::push (char item)
{
// if the stack is full, print an error message
if (full ())
{
cout
cout
}
else // ok to push
{
top++;
data [top] = item;
}
}
// pop removes and returns the top element of the stack
char stack::pop ()
{
// if the stack is empty, print an error message
if (empty ())
{
cout
cout
return '?';
}
else // ok to pop
{
top--;
return data [top + 1];
}
}
// empty returns true if the stack is empty, else
// it returns false
bool stack::empty ()
{
return top == -1;
}
// full returns true if the stack is full, else it
// returns false
bool stack::full ()
{
return top == stack_size - 1;
}
CIS 251 Lab 7.doc (Protected View) Word Insert Design Layout References Malings Review view Q Tea me what you to do CIS 251- Lab 7 Make the following changes to the implementation file: Due: March 29, 2017 Write a stack member function called elements that returns the number of elements in a stack (the stack should not be changed): Download the Lab cpp and stack.h files from the Lab 7 area of int element a Create C++ project and add the two files to it. Write a stack member function called print ends that prints the top element in the stack and then the bottom element in the stack uith a Take a look at the stack implementation space between them. It should not print alabel, just the values from the 1 Write an arithmetic expression that will compute the number ofelements void print ends 02 in a stack given the value oftop. Write a stack member function called change bottom that sets the 2. Does this expression give the correct answer for an empty stack? Explain. element at the bottom of the stack to its parameter. void change bottom (char new item) 3. What is that index ofthe top element of the stack Make the following changes to the application file (there are comments to help instruct you where to place each item): 4. What is the index of the bottom element of the stack? Declare a stack called stacky. Push the characters F.Lo w E, andRon the stack. 5. Write a C++ expression that gives the value stored at the top of the stack. Call your print ends function to print the stack. Change the bottom of the stack to P using change bottom 6. Write a C++ expression that gives the value stored at the bottom ofthe stack Pop the stack Call your print ends function to print the stack Print the number of elements in the stack (using the elements function A LOT or LATELY to find the number of elements) Plug the call into the already present Place your completed stack h and Lab 7 cpp source files in the Lab 7 area on Blackboard

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!