I am having trouble with the program not pushing the strings and only part of the characters from the file. I really hope one of you can help me because this is due in the morning
here is the actual assignment
Learning Objectives: The purpose of this lab is to gain experience with a templete Deque ADT implementations.
Problem Statement: A Deque is similar to a Queue, except that elements can be added and removed from both ends. You will implement it with a circular array, just as you did the Queue. In this lab, you are going to create a template Deque class and test it. The Deque ADT has the following functions:
• default constructor (same as Queue – initialize to empty Deque)
• empty (same as Queue)
• push_front (new function – add to front)
• push_back (same as AddQ in Queue)
• front (same as Front in Queue)
• back (new function – return the element at the back of the Deque)
• pop_front (same as RemoveQ in Queue)
• pop_back (new function – remove element from back of the Deque)
• an overloaded output operator to output items in the Deque.
Assignment: Design, Implement, and Test a template class Deque.
Test Driver The main function should test each of the above functions for the Deque class and clearly label which function is being tested, and its results. When you conduct testing, please test with a deque of strings as well as a deque of integers.
Your test driver should also be able to perform the following tasks: first ask the user for a filename, then read in the file, one character at a time, placing all lower case letters at the front of deque, and all other characters at the back of deque. Please use the two provided files for testing.
Additionally, the main file should contain a void function SwapFrontBack, which
• receives a non-empty Deque reference object dq
• swaps the front and the back of dq
Test this function, and clearly output results to demonstrate that it is working correctly.
For testing, set the capacity of the array in Deque to 10, so the "Deque full" message can be tested.
Follow our class coding standard to complete this lab, compile and run it, check out for credit.
here is my code for Dequeue.h
#include <iostream>
#include <string>
using namespace std;
const int CAPACITY = 10;
template <typename T>
class Dequeue
{
private:
int myFront, myBack;
T m_array[CAPACITY];
public:
Dequeue();
bool empty();
void push_front(T item);
void push_back(T item);
T front();
T back();
void pop_front();
void pop_back();
friend ostream& operator<<(ostream& out, const Dequeue<T>& Q)
{
for(int i = Q.myFront; i != Q.myBack; i = (i+1)%CAPACITY)
out << Q.m_array[i] << endl;
return out;
}
};
template<typename T>
Dequeue<T>::Dequeue()
{
myFront = 0;
myBack = 0;
}
template<typename T>
bool Dequeue<T>::empty()
{
if(myFront==myBack)
return true;
else
return false;
}
template<typename T>
void Dequeue<T>::push_front(T item)
{
if(myFront!=myBack && myFront-1 == -1)
{
myFront = CAPACITY;
if(myFront != myBack)
m_array[myFront] = item;
else
{
myFront = 0;
cout << "dequeue is full, cannot add to front\n";
}
}
else if(myFront != myBack)
{
if(myFront-1 == myBack)
cout << "deque is full, cannot add to front\n";
else
{
myFront = myFront -1;
m_array[myFront] = item;
}
}
}
template<typename T>
void Dequeue<T>::push_back(T item)
{
if((myBack+1) % CAPACITY != myFront)
{
m_array[myBack] = item;
myBack = (myBack+1) % CAPACITY;
}
else
cout << "Que is full, cannot add to back\n";
}
template<typename T>
T Dequeue<T>::front()
{
return m_array[myFront];
}
template<typename T>
T Dequeue<T>::back()
{
return m_array[myBack];
}
template<typename T>
void Dequeue<T>::pop_front()
{
if(!empty())
{
myFront = (myFront+1) % CAPACITY;
}
else
cout << "Que is empty\n";
}
template<typename T>
void Dequeue<T>::pop_back()
{
if(!empty())
{
myBack = (myBack-1) % CAPACITY;
}
else
cout << "Que is empty\n";
}
here is the code for my driver
#include "Dequeue.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string myString;
char input;
fstream characterFile;
string myfile = "char document.txt";
Dequeue<int> intQ;
Dequeue<string> strQ;
Dequeue<char> charQ;
characterFile.open(myfile, ios::in);
for(int i = 0; i < 11; i ++)
{
if((i%2) == 0)
{
cout << "even number push to back: " << i << endl;
intQ.push_back(i);
}
else
{
cout << "odd number push to front: " << i << endl;
intQ.push_front(i);
}
}
cout << intQ;
cout << "enter 4 strings\n";
for(int i = 0; i < 4; i++)
{
getline(cin, myString);
if(myString.length() > 10)
{
cout << "string longer than 10 char push to back: " << myString << endl;
strQ.push_back(myString);
}
else
{
cout << "string is 10 char or shorter push to front: " << myString << endl;
strQ.push_front(myString);
}
}
cout << strQ;
while(characterFile >> input)
{
if(islower(input))
charQ.push_front(input);
else
charQ.push_back(input);
}
cout << charQ;
int end;
cin >> end;
return 0;
}