Question: Main.cpp #include #include #include #include #include stack.h using namespace std; int main ( int argc, char * argv [ ] ) { ifstream inputs;

Main.cpp #include #include #include #include #include "stack.h" using namespace std; int main(int argc, char* argv[]){ ifstream inputs; // Input file for commands char op; // Hold operation and optional char input int value; // Value input from file string comment; Il Holds comment from file Stack* sPtr = NULL; // Will point to TemplateQ object Il Output usage message if one input file name is not provided if (argc !=2){ cout << "Usage:In project03
"; return 1; }11 Attempt to open input file -- terminate if file does not open inputs.open(argv[1]); if (!inputs){ cout << "Error - unable to open input file" << endl; return 1; }// Input and echo header comment from file getline(inputs, comment); cout << endl <<"# << comment << endl; // Process commands from input file inputs >> op; 11 Attempt to input first command while (inputs){ switch (op)// Process operation input from file { case '#': // Test file comment getline inputs, comment); // Input and echo the comment appearing in the test file cout <<'#'<< comment << endl; break; case 'c': // Parameterized Constructor inputs >> value; cout << endl << "Stack("<< value <<")"; try { sPtr = new Stack(value); Il Attempt to create a stack object with array size value cout <<"-- Successful" << endl; } catch (std::bad_alloc){ cout << "Failed : Terminating now..." << endl; return 1; } break; case '+': // Push inputs >> value; cout << "Push("<< value <<")"; try { sPtr->push(value); cout <<"-- successful"; } catch (StackFull){ cout <<"-- Failed Full Stack"; } cout << endl; break; case '-': // Pop cout << "Pop()--"; try { sPtr->PopO; cout << "successful"; } catch (StackEmpty){ cout << "Failed Empty Stack"; } cout << endl; break; case 'f': // IsFull cout << "IsFullo try { if (sPtr->IsFull) cout << "true"; else cout << "false"; } catch (...){ cout << "operation failed"; } cout ss endi: break; case 'e': // IsEmpty cout << "IsEmpty()--"; try { if (sPtr->IsEmpty) cout << "true"; else cout << "false"; } catch (...){ cout << "operation failed"; } cout << endl; break; case 'm': // Make Empty SPtr->MakeEmpty(); cout << "MakeEmpty" << endl; break; case 'p': // Print Stack cout << "Print()--"; sPtr->print(); break; case 't': // Top of Stack try { cout << "Top()--"<< sPtr->Top()<< endl; } catch (StackEmpty){ cout << "Top()-- Failed Empty Stack" << endl; } break; case '>'; // Max value within Stack try { cout << "Max()--"<< sPtr->Max()<< endl; } catch (StackEmpty){ cout << "Max()-- Failed Empty Stack" << endl; } break; case '<': // Min value within Stack try { cout << "Min()--"<< sPtr->Min()<< endl; } catch (StackEmpty){ cout << "Min()-- Failed Empty Stack" << endl; } break; case '?': // Peek(n) Stack inputs >> value; try { cout << "Peek("<< value <<")--"<< SPtr->Peek(value)<< endl; } catch (StackInvalidPeek){ cout << "Peek("<< value <<")-- Failed Invalid Peek" << endl; } break; case 's'; // Size of Stack cout << "Size()--"<< SPtr->Size()<< endl; } break; case 's': // Size of Stack cout << "Size()--"<< SPtr->Size()<< endl; break; case 'z': Il Capacity of Stack cout << "Capacity()--"<< sPtr->Capacity()<< endl; break; case 'd': // Destructor delete sPtr; sPtr = NULL; cout <<"-Stack()"<< endl << endl; break; default: // Error cout << "Error - unrecognized operation "<< op <<"'"'<< endl; cout << "Terminating now..." << endl; return 1; break; } inputs >> op; Il Attempt to input next command } return 0; }// End main() Stack.h // Specification file for Stack class, a stack of integers implemented Il as a linked list of nodes. Il //***** DO NOT MODIFY OR SUBMIT THIS FILE ***** Il #include using namespace std; #ifndef STACK_H #define STACK_H class StackEmpty {// Exception class-throw an object of this type when stack is empty // Hint: there is no code for exception classes }; class StackFull {// Exception class - throw an object of this type when stack is full }; class StackInvalid Peek {// Exception class - throw an object of this type when invalid peek position is used }; class Stack // Models stack of integers ADT implemented as a dynamically allocated array { private: int* array; // Points to the stack array // Holds max number of elements that may be stored in stack array int top; // Holds the index of the top data value stored on the stack void Resize(int n); Il Attempts to increase size of stack array to 2*num and then push n onto stack // If unable to resize, throw StackFull exception public: Stack(int n); // Parameterized constructor dynamically allocates an empty stack array // that may hold no more than n elements and initializes other private variable-Stack(); // Destructor deallocates all dynamically-allocated memory Il associated with the object void Push(int n); // Pushes integer n onto top of stack. If stack is full, attempts to int num; Il resize stack and then push n. If unable to resize, throws StackFull exception. void PopO; // Removes to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!