Programming Homework Help

DAC Specifications for The Word and WordStack Classes Program

 

Finish the provided specifications for the Word and WordStack classes. The WordStack Class will act as a stack of Word objects. You must implement your own linked list for this assignment. Additionally create a driver to demonstrate the features of the WordStack class. The driver will read and write files to reverse all of the words of some input file.

Finish the Word class implementation in Word.cpp

Use the provided Word.h. Complete the implementation of the Word class in a Word.cpp file.

Finish the WordStack class in WordStack.cpp

Use the provided WordStack.h. Complete the implementation of the WordStack class in a WordStack.cpp file.

Create a WordStack class with pop, push, and isEmpty.

This Wordstack holds Word objects using a linked list of Nodes.

The Stack class has the following methods:

void push(Word)

push accepts a Word object, then inserts it into the stack of Words

Word Pop()

The pop()method takes no arguments and returns the Word object from the top of the stack. This method also discards the top element from the stack. Throw an exception when popping from an empty stack.

bool isEmpty()

isEmpty returns True when the stack is empty. Return false when not empty.

Driver

Create a simple text file with some arbitrary text of your choice. This is the program input file.

Next, write a driver program to read an input file, save the words in a new file in reverse order. Do this using the WordStack class.

The Driver should do the following at minimum.

  • Open the input text file and read the contents into a WordStack.This must insert one word at a time into the stack.
  • Close the input file.
  • Open a new file for program output. This file begins empty.
  • The program should then pop all of the Words from the stack and save each word into an output file. This output file storesall of the words that were popped from the stack.
  • Close the output file.
  • The order of the words saved in the output file should be the reverse of their order in the input file.

Class Source Code

The classes must be defined in a header file with no implementation. Additionally, create an implementation file with all of the implementation code. See the provided Die class example for an example of this format.

.—————————————

word.h

#ifndef WORD_H_
#define WORD_H_
#include <string>;

class Word
{
private:
std::string word;

public:
Word();
std::string getWord() const;
void setWord(std::string);
};

#endif

---------------------------
wordStack.h
#ifndef WORDSTACK_H_
#define WORDSTACK_H_

#include "Word.h"

class WordStack{
private:
   struct StackNode
   {
       Word word;
       StackNode *next;
   };

   StackNode *top;

public:
   void push(Word);
   Word pop();
   bool isEmpty() const;
};

#endif /* WORDSTACK_H_ */