Question: 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

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.

Write a program that opens a text file, and displays the contents

header file

#ifndef STACKOFCHARS_H_INCLUDED #define STACKOFCHARS_H_INCLUDED

using namepsace std;

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

else // pop value off top of stack { num = top->value; temp = top->next; delete top; top = temp; } }

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

template

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

if (!top) { status = true; }

return status; }

#endif // STACKOFCHARS_H_INCLUDED

This is the original file..elif lanigiro eht si sihT Process returned 0 (0x0 excution time 0.234 s Press any key to continue

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!