In C++, using my program stack.h and stack.cpp (shown below the instructions), Create the postfix.cpp file the converts an infix expression into a postfix expression. You must use the stack.h and stack.cpp implemented in Part 1. The program must allow the user inputs, and the inputs should not include any alphabets. You need to handle '(', '‘)', ‘'+', '-', '%', '*' and '%' operators. "^' will not be considered in this program. Also, please consider only one digit numbers. Stack h

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
topIndex = -1;
}
// destructor
Stack::~Stack() {
delete[] data;
}
// push an element onto the stack
void Stack::push(int element) {
if (isFull()) {
}
cout << "Stack overflow!" << endl;
return;
topIndex++;
data[topIndex] = element;
}
// remove and return the top element from the stack
int Stack::pop() {
if (isEmpty()) {
}
cout << "Stack underflow!" << endl;
return -1;
}
int element = data[topIndex];
topIndex--;
return element;
}
// return the top element of the stack
int Stack::top() {
if (isEmpty()) {
cout << "Stack is empty!" << endl;
return -1;
}
return data[topIndex];
}
// check if the stack is empty
bool Stack::isEmpty() {
return topIndex == -1;
}
// check if the stack is full
bool Stack::isFull) {
return topIndex == capacity - 1;
}
// get the number of elements in the stack
int Stack::size() {
return topIndex + 1;
}
// print the elements in the stack
void Stack::print() {
cout << "Stack elements: ";
for (int i topIndex; i >= 0; i--) {
cout <<data[i] << " ";
}
cout << endl;
Transcribed Image Text:topIndex = -1; } // destructor Stack::~Stack() { delete[] data; } // push an element onto the stack void Stack::push(int element) { if (isFull()) { } cout << "Stack overflow!" << endl; return; topIndex++; data[topIndex] = element; } // remove and return the top element from the stack int Stack::pop() { if (isEmpty()) { } cout << "Stack underflow!" << endl; return -1; } int element = data[topIndex]; topIndex--; return element; } // return the top element of the stack int Stack::top() { if (isEmpty()) { cout << "Stack is empty!" << endl; return -1; } return data[topIndex]; } // check if the stack is empty bool Stack::isEmpty() { return topIndex == -1; } // check if the stack is full bool Stack::isFull) { return topIndex == capacity - 1; } // get the number of elements in the stack int Stack::size() { return topIndex + 1; } // print the elements in the stack void Stack::print() { cout << "Stack elements: "; for (int i topIndex; i >= 0; i--) { cout <<data[i] << " "; } cout << endl;
In C++, using my program stack.h and stack.cpp (shown below the instructions),
Create the postfix.cpp file the converts an infix expression into a postfix expression. You must use
the stack.h and stack.cpp implemented in Part 1. The program must allow the user inputs, and the
inputs should not include any alphabets. You need to handle ‘(', ‘)', ‘+', ‘-', ‘/', ‘*' and '%'
operators. "^' will not be considered in this program. Also, please consider only one digit numbers.
Stack.h
#pragma once
#ifndef STACK_H
#define STACK_H
class Stack {
private:
int* data; //array to store elements of the stack
int capacity; //maximum number of elements that can be stored in the stack
int topIndex; //index of the top element in the stack
public:
Stack(int capacity); //constructor
~Stack();
//destructor
void push(int element); //pushes an element onto the stack
int pop(); //removes and returns the top element from the stack
//returns the top element from the stack without removing it
int top();
bool isEmpty(); //checks if stack is empty-returns true if stack is empty and
bool isFull(); //checks if stack is full-returns true if stack is full and false //otherwise
int size();
//gets the number of elements in the stack
void print(); //prints the elements in the stack
};
#endif /* STACK_H */
Stack.cpp
#include "stack.b"
#include <iostream>
using namespace std;
// constructor
Stack::Stack(int capacity) {
data = new int[capacity];
this->capacity = capacity;
//false otherwise
Transcribed Image Text:In C++, using my program stack.h and stack.cpp (shown below the instructions), Create the postfix.cpp file the converts an infix expression into a postfix expression. You must use the stack.h and stack.cpp implemented in Part 1. The program must allow the user inputs, and the inputs should not include any alphabets. You need to handle ‘(', ‘)', ‘+', ‘-', ‘/', ‘*' and '%' operators. "^' will not be considered in this program. Also, please consider only one digit numbers. Stack.h #pragma once #ifndef STACK_H #define STACK_H class Stack { private: int* data; //array to store elements of the stack int capacity; //maximum number of elements that can be stored in the stack int topIndex; //index of the top element in the stack public: Stack(int capacity); //constructor ~Stack(); //destructor void push(int element); //pushes an element onto the stack int pop(); //removes and returns the top element from the stack //returns the top element from the stack without removing it int top(); bool isEmpty(); //checks if stack is empty-returns true if stack is empty and bool isFull(); //checks if stack is full-returns true if stack is full and false //otherwise int size(); //gets the number of elements in the stack void print(); //prints the elements in the stack }; #endif /* STACK_H */ Stack.cpp #include "stack.b" #include <iostream> using namespace std; // constructor Stack::Stack(int capacity) { data = new int[capacity]; this->capacity = capacity; //false otherwise
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education