Question: C++ Write a program that opens a text file, and displays the contents and stores the contents into a stack of characters. The program will

C++ Write a program that opens a text file, and displays the contents and stores the contents into a stack of characters. The program will then pop the characters from the stack, and save them in a second file in reverse order, then open the second file and read and display the contents.

here is the class

template class DynStack { private: struct StackNode { T value; StackNode *next; };

StackNode *top;

public: DynStack() { top = nullptr; } void push(T); void pop(T &); bool isEmpty(); }; //********************************************************* // Member function push pushes the argument onto the stack. * //*********************************************************

template void DynStack::push(T num) { StackNode *newNode = nullptr;

// Allocate a new node & store Num newNode = new StackNode; newNode->value = num;

// If there are no nodes in the list make newNode the first node if (isEmpty()) { top = newNode; newNode->next = nullptr; } else // Otherwise, insert NewNode before top { newNode->next = top; top = newNode; } }

//********************************************************* // Member function pop pops the value at the top of the stack off, * // and copies it into the variable passed as an argument. * //*********************************************************

template void DynStack::pop(T &num) { StackNode *temp = nullptr;

if (isEmpty()) { cout << "The stack is empty. "; } else // pop value off top of stack { num = top->value; temp = top->next; delete top; top = temp; } }

//********************************************************* // Member function isEmpty returns true if the stack * // is empty, or false otherwise. * //*********************************************************

template bool DynStack::isEmpty() { bool status = false;

if (!top) { status = true; } return status; }

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 Databases Questions!