Question: //myStack.h #ifndef STACK_H #define STACK_H #define MAX 1000 template class myStack { int CurrentSize; //An indicator that contains the current size of the stack public:

//myStack.h
#ifndef STACK_H
#define STACK_H
#define MAX 1000
template
class myStack
{
int CurrentSize; //An indicator that contains the current size of the stack
public:
userType holder[MAX]; //Maximum size of the stack
myStack();
bool push(userType x);
userType pop();
bool isEmpty();
};
template
myStack::myStack()
{
//Todo: initialize the value of the currentSize.
}
template
bool myStack::push(userType x)
{
if (isEmpty)
{
//Todo
//Push the item x to myStack.
//Update the value of the currentSize.
return true;
}
else
{
//Todo:
//print a meaningful error message
return false;
}
}
template
userType myStack::pop()
{
//Todo:
//Pop the currentSize element of the stack (e.g. x).
//update the value of the currentSize.
//return x.
}
template
bool myStack::isEmpty()
{
//Check if the size of the stack is still less than the MAX value.
}
#endif // STACK_H
#pragma once
main.cpp
#include
#include
#include "myStack.h"
#include
#include
#include
using namespace std;
int main()
{
cout
cout
cout
//Todo: Create your stack
char inputItem;
bool flag = true;
while (true)
{
cout
cout
while (flag)
{
cin >> inputItem;
if (inputItem == 'H')
{
cout
cout
cout
return 0;
}
else if (inputItem == 'c')
{
//Todo:
//1) Check if the input line is in the correct format.
//2) If true, compute the results based on the algorithm and print for the user.
//3) Otherwise, print a meaningful error message and pop all items of the stack.
flag = false;
}
else if (isspace(inputItem))
{
continue;
}
else if ((inputItem == '+') || (inputItem == '/') || (inputItem == '-') || (inputItem == '*'))
{
//Follow the steps mentioned in the algorithm for operators.
//myQueue.h
#ifndef myQueue_H #define myQueue_H #define MAX 1000
class myQueue { public: myQueue(); bool push(int x); int pop(); bool isFull(); bool isEmpty(); void print(); private: int rear, front; int holder[MAX]; };
#endif // myQueue_H
}
else
{
int num = inputItem - '0';
if ((num >= 0) && (num
{
//Follow the steps mentioned in the algorithm for integer values.
}
else
{
cout
flag = false;
//Pop all input items
while ((getchar() != ' '));
}
}
}
flag = true;
}
}
//myQueue.cpp
#include "myQueue.h"
myQueue::myQueue() { //initialize the value of the rear and front indicator based on your implementation. }
bool myQueue::push(int x) {
if(!isFull()) { //Todo: //Check if the queue is full or not.
//If so, insert an item into the back of the myQueue. //Update the value of the front indicator //Otherwise, print a meaningful error message return true; } else { //Todo: print a meaningfull message return false;
} }
int myQueue::pop() {
//Todo: //Remove the front item from the myQueue //Update the value of the rear indicator
}
bool myQueue::isFull() {
//Check if the myQueue still has empty space at its rear or the front. }
bool myQueue::isEmpty() {
//Check if the myQueue is empty based on the value of the front and rear indicator. }
void myQueue::print() {
//Todo: print all items of the myQueue. //Hint: use a variable to store a copy of the front value. itterate over the queue until you reached //to the rear element.
}
//main.cpp
#include
#include
using namespace std;
int main()
{
char choice;
cout
cout
cout
//Todo: Create your queue
do
{
cout
cout
cout
cout
cout
cin>>choice;
//Todo: check if the choice has a valid value.
if(choice=='1')
{
char toCheck;
bool flag=true;
int inputItem;
cout
while(flag)
{
cin>>toCheck;
if(toCheck=='c')
flag=false;
if(flag)
{
inputItem = toCheck-'0';
//Todo: push the inputItem into queue.
//Print an error message if the queue is full.
//Set the value of the flag to false if it is already full.
}
}
cout
}
else if(choice=='2')
{
char toCheck;
bool flag=true;
int count;
cout
cin>>toCheck;
if(toCheck=='c')
flag=false;
while(flag)
{
count = toCheck-'0';
//Todo: Check if the queue is already empty or not
//If true, pop from the front, update the count value and print the poped item for the
//user.
//Otherwise, print a meaningfull error message and set the flag value to false.
}
cout
}
else if(choice=='3')
{
//Todo: Print all items of the queue.
}
else if(choice=='4')
{
cout
cout
cout
return 0;
}
else
{
cout
}
}while(true);
}
In this question, you are going to implement a stack data structure in part 1 and then use t to create postfix mini-calculator in section 2. 1. 1.1. Use the myStack.h to implement a stack template. It should be able to work for arbitrary data types (char, int, double, etc.). 1.2. Postfix calculator Complete the provided main script to implement a mini postfix calculator for integer numbers. We use infix notation in regular calculations like 2+4*3, while its postfix notation is 243* +. Use your stack data structure from part 1.1 and the following algorithm to to create the postfix calculator: Read a line from terminal as the user input. . If the input is a valid integer, you push that integer onto the stack. If the input is a valid operator (+, *, /, -)pop two integers off the stack, perform the requested operation, and push the result back onto the stack. If there were less than 2 integers remained in the stack, print a meaningful error message. If the user enters "c", you need to print the final result. If the user input line If the user enters "H", you halt the program without performing any For any other input characters, print a meaningful error message. was not in a correct format, you should print a meaningful message. additional computations. 2. Use the myQueue.cpp and myQueue.h to implement a queue data structure for integer data type: To keep track of the front and rear of the queue, you can use two integer indicators. . Be careful about the "empty" and "full" state. You can use one of the three implementations that distinguish these two states. Complete the main script of this
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
