Can anyone convert this c++ code to python?   //THIS PROGRAM IS CREATED TO DEMONSTRATE THE OPERATIONS PERFORMED ON STACK & ITS IMPLEMENTATION USING ARRAYS #include #include #include #include #include //Defining the maximum size of the stack #define MAXSIZE 7 using namespace std; //A class initialized with public and private variables and functions class STACK_ARRAY     {     int stack[MAXSIZE];     int Top;     public:         //constructor is called and Top pointer is initialized to -1 when an object is created for the class  STACK_ARRAY()     {         Top = -1;     }     void push();     void pop();     void traverse();     };      //This function will add/insert an element to Top of the stack void STACK_ARRAY::push() {  int item;  //if the top pointer already reached the maximum allowed size then we can say that the stack is full or overflow  if (Top == MAXSIZE-1)     {     cout << "\nThe Stack Is Full";     }  //Otherwise an element can be added or inserted by incrementing the stack  pointer Top as follows  else     {         cout << "\nEnter The Element (number) To Be Inserted: "; cin >> item;         stack[++Top] = item;     } } //This function will delete an element from the Top of the stack void STACK_ARRAY::pop()     {         int item;  //If the Top pointer points to NULL, then the stack is empty. That is NO element is there to delete or pop     if (Top == -1)         cout << "\nThe Stack Is Empty";  //Otherwise the top most element in the stack is popped or deleted by decrementing the Top pointer  else     {         item = stack[Top--];         cout << "\nThe Deleted Element (number) Is: " << item;     } } //This function to print all the existing elements in the stack void STACK_ARRAY::traverse(){  int i;  //If the Top pointer points to NULL, then the stack is empty. That is NO element is there to delete or pop  if (Top == -1)     cout << "\nThe Stack is Empty";  //Otherwise all the elements in the stack is printed  else     {         cout << "\nThe Element(s) in the Stack(s) is/are: ";         for(i = Top; i >= 0; i--)             cout << stack[i] << " ";         cout << "\n";     } } int main() {  int choice;  char ch;  //Declaring an object to the class  STACK_ARRAY ps;  do {     //A menu for the stack operations     cout << "MAIN MENU\n\n";     cout << "STACK using Array \n\n";     cout << "[1] PUSH (Add number)\n";     cout << "[2] POP (Delete number)\n";     cout << "[3] TRAVERSE (Display number)\n";     cout << "[4] QUIT\n\n";     cout << "Enter Your Choice: "; cin >> choice;     switch(choice)     {         case 1://Calling push() function by class object             ps.push();             break;         case 2://calling pop() function             ps.pop();             break;         case 3://calling traverse() function             ps.traverse();             break;         case 4:             exit(0);         default:             cout << "\nYou Entered wrong Choice";     }     cout << "\n\nPress (Y/y) To Continue... ";     cin >> ch;     cout << "\n";  } while(ch == 'Y' || ch == 'y'); }     And the out put should look like in the picture below.

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter8: Arrays
Section: Chapter Questions
Problem 2MQ2
icon
Related questions
Question
100%

Can anyone convert this c++ code to python?

 

//THIS PROGRAM IS CREATED TO DEMONSTRATE THE OPERATIONS PERFORMED ON STACK & ITS IMPLEMENTATION USING ARRAYS

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <process.h>

//Defining the maximum size of the stack
#define MAXSIZE 7

using namespace std;

//A class initialized with public and private variables and functions
class STACK_ARRAY
    {
    int stack[MAXSIZE];
    int Top;
    public:
        //constructor is called and Top pointer is initialized to -1 when an object is created for the class
 STACK_ARRAY()
    {
        Top = -1;
    }
    void push();
    void pop();
    void traverse();
    };
    
//This function will add/insert an element to Top of the stack
void STACK_ARRAY::push()
{
 int item;
 //if the top pointer already reached the maximum allowed size then we can say that the stack is full or overflow
 if (Top == MAXSIZE-1)
    {
    cout << "\nThe Stack Is Full";
    }
 //Otherwise an element can be added or inserted by incrementing the stack 
pointer Top as follows
 else
    {
        cout << "\nEnter The Element (number) To Be Inserted: "; cin >> item;
        stack[++Top] = item;
    }
}

//This function will delete an element from the Top of the stack
void STACK_ARRAY::pop()
    {
        int item;
 //If the Top pointer points to NULL, then the stack is empty. That is NO element is there to delete or pop
    if (Top == -1)
        cout << "\nThe Stack Is Empty";
 //Otherwise the top most element in the stack is popped or deleted by decrementing the Top pointer
 else
    {
        item = stack[Top--];
        cout << "\nThe Deleted Element (number) Is: " << item;
    }
}

//This function to print all the existing elements in the stack
void STACK_ARRAY::traverse(){
 int i;
 //If the Top pointer points to NULL, then the stack is empty. That is NO element is there to delete or pop
 if (Top == -1)
    cout << "\nThe Stack is Empty";
 //Otherwise all the elements in the stack is printed
 else
    {
        cout << "\nThe Element(s) in the Stack(s) is/are: ";
        for(i = Top; i >= 0; i--)
            cout << stack[i] << " ";
        cout << "\n";
    }
}

int main()
{
 int choice;
 char ch;
 //Declaring an object to the class
 STACK_ARRAY ps;
 do
{
    //A menu for the stack operations
    cout << "MAIN MENU\n\n";
    cout << "STACK using Array \n\n";
    cout << "[1] PUSH (Add number)\n";
    cout << "[2] POP (Delete number)\n";
    cout << "[3] TRAVERSE (Display number)\n";
    cout << "[4] QUIT\n\n";
    cout << "Enter Your Choice: "; cin >> choice;
    switch(choice)
    {
        case 1://Calling push() function by class object
            ps.push();
            break;
        case 2://calling pop() function
            ps.pop();
            break;
        case 3://calling traverse() function
            ps.traverse();
            break;
        case 4:
            exit(0);
        default:
            cout << "\nYou Entered wrong Choice";
    }
    cout << "\n\nPress (Y/y) To Continue... ";
    cin >> ch;
    cout << "\n";
 } while(ch == 'Y' || ch == 'y');
}

 

 

And the out put should look like in the picture below.

eskton
D:\c++\practice1\bin\Debug\practice1.exe
ΜΑIΝ ΜΕΝU
STACK using Array
[1] PUSH (Add number)
[2] POP (Delete number)
[3] TRAVERSE (Display number)
[4] QUIT
Enter Your Choice:
Transcribed Image Text:eskton D:\c++\practice1\bin\Debug\practice1.exe ΜΑIΝ ΜΕΝU STACK using Array [1] PUSH (Add number) [2] POP (Delete number) [3] TRAVERSE (Display number) [4] QUIT Enter Your Choice:
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Stack
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
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,