I need The output for this code, The exercise is below for reference:
Using ListQueue Structure:
10. File Filter Write a program that opens a text file and reads its contents into a queue of characters. The program should then dequeue each character, convert it to uppercase, and store it in a second file. They gave me these header files to work with: all I need is the output:
LinkedList.h
#pragma once #ifndef _LINKED_LIST #define _LINKED_LIST
#include "ListInterface.h" #include "Node.h" #include "PrecondViolatedExcep.h" #include #include
using namespace std;
template class LinkedList : public ListInterface { private: Node* headPtr; int itemCount;
Node* getNodeAt(int anEntry) const;
public: LinkedList(); LinkedList(const LinkedList& aList); virtual ~LinkedList();
bool isEmpty() const; int getLength() const; bool insert(int newPosition, const ItemType& newEntry); bool remove(int position); void clear(); void print() const; void Find(int ID); bool contains(const int& anEntry) const; void printCurrent(int anItemNumber) const;
ItemType getEntry(int position) const throw(PrecondViolatedExcep);
}; template LinkedList::LinkedList() : headPtr(nullptr), itemCount(0) { }
template inline LinkedList::LinkedList(const LinkedList& aList) { }
template LinkedList::~LinkedList() { clear(); }
template bool LinkedList::isEmpty() const { return itemCount == 0; }
template int LinkedList::getLength() const { return itemCount; }
template bool LinkedList::insert(int newPosition, const ItemType& newEntry) { bool ableToInsert = (newPosition >= 1) && (newPosition <= itemCount + 1); if (ableToInsert) { Node* newNodePtr = new Node(newEntry); if (newPosition == 1){ newNodePtr->setNext(headPtr); headPtr = newNodePtr; } else{ Node* prevPtr = getNodeAt(newPosition - 1); newNodePtr->setNext(prevPtr->getNext()); prevPtr->setNext(newNodePtr); } itemCount++; } return ableToInsert; }
template bool LinkedList::remove(int position) { bool ableToRemove = (position >= 1) && (position <= itemCount); if (ableToRemove) { Node* curPtr = nullptr; if (position == 1){ curPtr = headPtr; headPtr = headPtr->getNext(); } else{ Node* prevPtr = getNodeAt(position - 1); curPtr = prevPtr->getNext(); prevPtr->setNext(curPtr->getNext()); }
curPtr->setNext(nullptr); delete curPtr; curPtr = nullptr;
itemCount--; }
return ableToRemove; }
template void LinkedList::clear() { while (!isEmpty()) remove(1); }
template ItemType LinkedList::getEntry(int position) const throw(PrecondViolatedExcep) { bool ableToGet = (position >= 1) && (position <= itemCount); if (ableToGet) { Node* nodePtr = getNodeAt(position); return nodePtr->getItem(); } else { string message = "getEntry() called with an empty list or "; message = message + "invalid position."; throw(PrecondViolatedExcep(message)); } // end if }
template Node* LinkedList::getNodeAt(int position) const { Node* curPtr = headPtr; for (int skip = 1; skip < position; skip++) curPtr = curPtr->getNext();
return curPtr; }
template bool LinkedList::contains(const int& anEntry) const { return (getNodeAt(anEntry) != nullptr); }
template void LinkedList::print() const { Node* curPtr = headPtr; while (curPtr != nullptr) { cout << curPtr->getItem() << endl; curPtr = curPtr->getNext(); } }
template void LinkedList::printCurrent(int anEntry) const { Node* entryNodePtr = getNodeAt(anEntry); while (!isEmpty() && (entryNodePtr != nullptr)) { cout << entryNodePtr->getItem() << endl; break; } } template void LinkedList::Find(int ID) { Node* curPtr = headPtr; while (curPtr != nullptr) { if (curPtr->getItem() == ID) { cout << curPtr->getItem() << endl; } else { curPtr = curPtr->getNext(); cout << "No "; } } } #endif
ListInterface.h
#pragma once
#ifndef _LIST_INTERFACE #define _LIST_INTERFACE
template class ListInterface { public: virtual bool isEmpty() const = 0; virtual int getLength() const = 0; virtual bool insert(int newPosition, const ItemType& newEntry) = 0; virtual bool remove(int position) = 0; virtual void clear() = 0; virtual ItemType getEntry(int position) const = 0; virtual void setEntry(int position, const ItemType& newEntry) = 0; }; #endif
ListQueue.h
#ifndef _LIST_QUEUE #define _LIST_QUEUE
#include "QueueInterface.h" #include "LinkedList.h" #include "PrecondViolatedExcep.h"
template class ListQueue : public QueueInterface { private: LinkedList* listPtr;
public: ListQueue(); ListQueue(const ListQueue& aQueue); ~ListQueue(); bool isEmpty() const; bool enqueue(const ItemType& newEntry); bool dequeue();
ItemType peekFront() const throw(PrecondViolatedExcep); };
template ListQueue::ListQueue() { }
template ListQueue::ListQueue(const ListQueue& aQueue) : listPtr(aQueue.listPtr) { }
template ListQueue::~ListQueue() { }
template bool ListQueue::isEmpty() const { return listPtr->isEmpty(); }
template bool ListQueue::enqueue(const ItemType& newEntry) { return listPtr->insert(listPtr->getLength() + 1, newEntry); }
template bool ListQueue::dequeue() { return listPtr->remove(1); }
template ItemType ListQueue::peekFront() const throw(PrecondViolatedExcep) { if (isEmpty()) throw PrecondViolatedExcep("peekFront() called with empty queue.");
return listPtr->getEntry(1); } #endif
Node.h
#ifndef _NODE #define _NODE #include
template class Node {
private: ItemType item;
public: Node* next; Node(); Node(const ItemType& anItem); Node(const ItemType& anItem, Node* nextNodePtr); void setItem(const ItemType& anItem); void setNext(Node* nextNodePtr); ItemType getItem() const; Node* getNext() const; };
template Node::Node() : next(nullptr) {
}
template Node::Node(const ItemType& anItem) : item(anItem), next(nullptr) {
}
template Node::Node(const ItemType& anItem, Node* nextNodePtr) : item(anItem), next(nextNodePtr) {
}
template void Node::setItem(const ItemType& anItem) { item = anItem; }
template void Node::setNext(Node* nextNodePtr) { next = nextNodePtr; }
template ItemType Node::getItem() const { return item; }
template Node* Node::getNext() const { return next; }
#endif
PrecondViolatedExcep.h
#ifndef _PRECOND_VIOLATED_EXCEP #define _PRECOND_VIOLATED_EXCEP #include #include
using namespace std;
class PrecondViolatedExcep : public logic_error { public: PrecondViolatedExcep(const string& message = ""); }; // end PrecondViolatedExcep
PrecondViolatedExcep::PrecondViolatedExcep(const string& message) : logic_error("Precondition Violated Exception: " + message) { } #endif
QueueInterface.h
#pragma once
#ifndef _QUEUE_INTERFACE #define _QUEUE_INTERFACE
template class QueueInterface { public: virtual bool isEmpty() const = 0; virtual bool enqueue(const ItemType& newEntry) = 0; virtual bool dequeue() = 0; virtual ItemType peekFront() const = 0; }; #endif