Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// This program simulate processes Stack. Change the program to do the following // 2. add more Stacks (list of stacks) // 3. add choices

// This program simulate processes Stack. Change the program to do the following
// 2. add more Stacks (list of stacks)
// 3. add choices in the menu to push and pop to/from a specific Stack
// 4. display the contents of a specific Stack
#include
#include
#define MAX_SIZE 10
using namespace std;
class Stack {
private:
int item, i;
int arr_stack[MAX_SIZE];
int top;
string description;
public:
Stack() {
top = 0;
}
void setDescription (string s){
description = s;
}
string getDescription (){
return description;
}
void push() {
if (top == MAX_SIZE)
cout << " Stack Reached Max!";
else {
cout << " Enter The customer number to be pushed: ";
cin>>item;
cout << " Position : " << top + 1 << " , Enqueue Customer Number : " << item;
cout << "***** " << top;
arr_stack[top++] = item;
}
}
void pop() {
if (top == 0)
cout << " Stack is Empty!";
else {
cout << " Position: " << top << " , Pop Customer Number:" << arr_stack[top];
top--;
}
}
void display() {
cout << " Number of Customers in Stack: " << (top);
for (i=1; i < top; i++)
cout << " Position : " << i << " , Customer Number: " << arr_stack[i];
}
};
int main() {
int choice, exit_p = 1;
Stack Process;
Process.setDescription("Stack 1");
cout << " Simple Stack Example - Class and Memeber Functions in C++";
do {
cout << " Stack Main Menu";
cout << " 1.Push a Customer 2.Pop a Customer 3.Display Stack Information Others to exit";
cout << " Enter Your Choice : ";
cin>>choice;
switch (choice) {
case 1:
Process.push();
break;
case 2:
Process.pop();
break;
case 3:
cout << " Stack Description: " << Process.getDescription();
Process.display();
break;
default:
exit_p = 0;
break;
}
} while (exit_p);
return 0;
}

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

Step: 3

blur-text-image

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

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

1. Give at least 10 examples of resources.

Answered: 1 week ago

Question

=+ What is the role of government in bargaining?

Answered: 1 week ago