Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#ifndef STACK_H #define STACK_H namespace Stack { // node definition struct Stac

ID: 3629727 • Letter: #

Question

 #ifndef STACK_H
#define STACK_H

 namespace Stack
{

  // node definition
 struct StackNode
 {
  char data;
  StackNode *link;
 };

 // define a type for pointers to nodes
 typedef StackNode* StackNodePtr;

// define the Stack Class
 class Stack
 {
 public:
  // default constructor initializes an empty stack
  Stack();

 private:
  StackNodePtr top;
 };

Remember, you should always check the stack to make sure it is not empty before you call pop(). If the stack is empty when it shouldn’t be, print an error message as appropriate. Your program should gracefully handle this case.

Explanation / Answer

Dear.. #include<iostream.h>
#include<fstream.h> #include"apstring.h" #include"apvector.h" #include"apstring.cpp" #include"classes.h" int main ()
{     int pushnum=0;     apstring choice;     apstring calcchoice;     RPN b;     do{         cout<<"Enter 'push' or 'pop', and 'q' once you wish to make the calculations: ";         cin>>choice;         if(choice == "q")         {             break;         }         if(choice == "pop")         {             if(!b.isEmpty())             {                    b.pop();                    cout<<" Current number is: "<<b.current()<<endl<<endl;                    }else{                          cout<<" Pop limit reached!"<<endl<<endl;                          }         }         if(choice == "push")         {                    cout<<" Enter number to push: ";                    cin>>pushnum;                    b.push(pushnum);                    cout<<" Current number is: "<<pushnum<<endl<<endl;         }         }while(choice != "q");         do{         cout<<" Enter 'add', 'sub', 'mult', 'div', or 'q' to quit: ";         cin>>calcchoice;         if(b.isCalcEmpty())         {             cout<<" Calculator memory is empty!"<<endl<<endl;             break;         }         if(calcchoice == "q")         {             break;         }         if(calcchoice == "add")         {             b.add();         }                 if(calcchoice == "sub")         {             b.sub();         }         if(calcchoice == "mult")         {             b.mult();         }         if(calcchoice == "div")         {             b.div();         } }while(calcchoice != "q");       system("PAUSE"); return 1; } class STACK {       private:               struct NODE                      {                          double num;                              NODE *next;                            };                      NODE *temp, *temp2;                         NODE *head;                      NODE *head;        public:              STACK();              ~STACK();              void push(double temp);              double pop();              bool isEmpty()              {                  if(head==NULL){                               return true;                               }else{                                     return false;                                     }              }              bool isCalcEmpty()              {                   if(head->next==NULL){                               return true;                               }else{                                     return false;                                     }              }              double current ()                  {                  return temp->num;                  } }; class RPN: public STACK {     public:         RPN();         void add();         void sub();         void mult();         void div(); }; RPN::RPN() { } void RPN::add() {     double first=0, second=0, ans=0;     first = pop();     second= pop();     push(first + second);     ans=first+second;     cout<<" Result of addition: " <<ans<<endl<<endl; } void RPN::sub() {     double first=0, second=0, ans=0;     first = pop();     second= pop();     push(first - second);     ans=first-second;     cout<<" Result of subtraction: " <<ans<<endl<<endl; } void RPN::mult() {     double first=0, second=0, ans=0;     first = pop();     second= pop();     push(first * second);     ans=first*second;     cout<<" Result of multiplication: " <<ans<<endl<<endl; } void RPN::div() {     double first=0, second=0, ans=0;     first = pop();     second= pop();     push(first / second);     ans=first/second;     cout<<" Result of division: " <<ans<<endl<<endl; } STACK::STACK() { head=NULL; } void STACK::push (double x) {     NODE* newNode;     newNode=new NODE;     newNode->num = x;     newNode->next = head;     head = newNode;     newNode = NULL; //clear Node address     delete newNode; //delete Node memory } double STACK::pop () {     temp = head;     head = head->next;     return temp->num; } STACK::~STACK()
{     delete []head;     delete []temp;     delete []temp2; }