Question: I only need help with myStack.h and main.cpp. Basically, the first two parts, 1.1 and 1.2. //myStack.h #ifndef STACK_H #define STACK_H #define MAX 1000 template
I only need help with myStack.h and main.cpp. Basically, the first two parts, 1.1 and 1.2.
//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
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.
}
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;
}
}
1. 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. 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+43, while its postfix notation is 2 4 3+ 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 To keep track of the front and rear of the queue, you can use two integer Be careful about the "empty" and "full" state. You can use one of the three data type: indicators 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
