Part 1: Static Stack In this part, you are going to design a stack of characters. Assume a simple static array implementation. Complete the code below as specified by the comments below. const int MAX = 5; // define an alias for the element type class Stack { private: // declare an array of chars with MAX slots // and an integer to hold the index of the top element public: // Write the prototype of the following public methods // constructor, push, pop, isEmpty, isFull, displayAll } ; // implement the public methods here int main () { Stack s; char c; cout << " initial stack contents" << endl; s.displayAl1 (); s.pop(c); s.push('a'); cout << endl << " stack contents after pushing a: " << endl; s.displayAl1 (); s.push ( 'b'); cout << endl << " stack contents after pushing b: s.displayAl1(); << endl; s.push('c'); s.push('d’); s.push('e'); s.push('f'); s.push ( 'g'); cout << endl << " stack contents after pushing c-g: << endl; s.displayAl1(); s.pop (c); cout << endl << c << endl; cout << endl << " stack contents after popping one element: << endl; s.displayAl1(); s.pop(c); cout << endl << " popped element: << c << endl; cout << endl << " stack contents after popping another element: << endl; s.displayAl1(); s.pop (c); s.pop (c); s.pop (c); cout << endl << " stack contents after popping 3 more elements: << endl; s.displayAl1 (); s.pop (c); s.push ( 'a'); s.push( 'b'); cout << endl << final stack contents << endl; s.displayAl1(); return 0; }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

in C++ please

Part 1: Static Stack
In this part, you are going to design a stack of characters. Assume a simple static array
implementation. Complete the code below as specified by the comments below.
const int MAX =
5;
// define an alias for the element type
class Stack {
private:
// declare an array of chars with MAX slots
// and an integer to hold the index of the top element
public:
// Write the prototype of the following public methods
// constructor, push, pop, isEmpty, isFull, displayAll
} ;
// implement the public methods here
int main ()
{
Stack s;
char c;
cout << " initial stack contents" << endl;
s.displayAl1 ();
s.pop(c);
s.push('a');
cout << endl << "
stack contents after pushing a:
" << endl;
s.displayAl1 ();
s.push ( 'b');
cout << endl << " stack contents after pushing b:
s.displayAl1();
<< endl;
Transcribed Image Text:Part 1: Static Stack In this part, you are going to design a stack of characters. Assume a simple static array implementation. Complete the code below as specified by the comments below. const int MAX = 5; // define an alias for the element type class Stack { private: // declare an array of chars with MAX slots // and an integer to hold the index of the top element public: // Write the prototype of the following public methods // constructor, push, pop, isEmpty, isFull, displayAll } ; // implement the public methods here int main () { Stack s; char c; cout << " initial stack contents" << endl; s.displayAl1 (); s.pop(c); s.push('a'); cout << endl << " stack contents after pushing a: " << endl; s.displayAl1 (); s.push ( 'b'); cout << endl << " stack contents after pushing b: s.displayAl1(); << endl;
s.push('c');
s.push('d’);
s.push('e');
s.push('f');
s.push ( 'g');
cout << endl << "
stack contents after pushing c-g:
<< endl;
s.displayAl1();
s.pop (c);
cout << endl << c << endl;
cout << endl << "
stack contents after popping one element:
<< endl;
s.displayAl1();
s.pop(c);
cout << endl << "
popped element:
<< c << endl;
cout << endl << " stack contents after popping another element:
<< endl;
s.displayAl1();
s.pop (c);
s.pop (c);
s.pop (c);
cout << endl << "
stack contents after popping 3 more elements:
<< endl;
s.displayAl1 ();
s.pop (c);
s.push ( 'a');
s.push( 'b');
cout << endl <<
final stack contents << endl;
s.displayAl1();
return 0;
}
Transcribed Image Text:s.push('c'); s.push('d’); s.push('e'); s.push('f'); s.push ( 'g'); cout << endl << " stack contents after pushing c-g: << endl; s.displayAl1(); s.pop (c); cout << endl << c << endl; cout << endl << " stack contents after popping one element: << endl; s.displayAl1(); s.pop(c); cout << endl << " popped element: << c << endl; cout << endl << " stack contents after popping another element: << endl; s.displayAl1(); s.pop (c); s.pop (c); s.pop (c); cout << endl << " stack contents after popping 3 more elements: << endl; s.displayAl1 (); s.pop (c); s.push ( 'a'); s.push( 'b'); cout << endl << final stack contents << endl; s.displayAl1(); return 0; }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning