I am trying to figure out why I am reading in strange characters from the input file. My input is just "MerryChristmas". I have tried putting spaces in between the letters and without spaces. I am inserting my code. I really need this back by Monday. Can anyone help me.. I am tearing my hair out..........................
Code:
#include <iostream>
#include <cstdlib>
//#include "QueueTypeImp.cpp"
#include "QueSpec.h"
#include<fstream>
using namespace std;
//function prototypes
void Fill_Queue(queue& Q);
el_t Remove_First(queue& Q);
//void Recursive_Reverse(queue& Q);
void Print_Queue(queue& Q);
//void Sucessor_Q(queue& Q);
//void Replace_Q(queue Q, el_t old_val, el_t newval);
// declaring file stream variables
ifstream inQData;
ofstream outQData;
int main()
{
//declaration of variables
el_t element, first_q_element;
el_t old_val = 'a', newval = 'z';
queue original_q;
//Opening of files
inQData.open("a:/queueinfo.txt");
outQData.open("a:/queueoutput.txt");
//fills stack with at least 25 elements from an input file
//inQData>>element;
while ((!original_q.QueueIsFull()) && (inQData ))
{
inQData>>element;
if ( element != '\0')
original_q.Enqueue(element);
//inQData>>element;
}
// Function Calls & Function Operations
outQData.flush();
first_q_element = Remove_First(original_q);
outQData<<"The first element in the Queue is :"<<first_q_element<<endl;
Print_Queue(original_q);/*
outQData<<endl;
outQData<<"The queue in reverse order is: ";
Recursive_Reverse(original_q);
outQData<<endl;
outQData<<"The queue printed again is: ";
Print_Queue(original_q);
outQData<<endl;
outQData<<"The queue printed with its successor element is : ";
Sucessor_Q(original_q);
outQData<<endl;
outQData<<"The queue printed when replacing a with z is: ";
Replace_Q(original_q, old_val, newval);
outQData<<endl;
outQData<<"old val"<<old_val<<newval;
*/
//Close files
inQData.close();
outQData.close();
system("PAUSE");
return 0;
}
//Function to remove the first element of queue and print it. The first
//element in queue should now be the last element.
el_t Remove_First(queue& Q)
{
el_t e;
if(!Q.QueueIsEmpty())
{
Q.Dequeue(e);
//outQData<<e1;
Q.Enqueue(e);
}
return e;
}//End of Remove First Function
//Function will print the elements in reverse order.
void Recursive_Reverse(queue& Q)
{
el_t e;
if (!Q.QueueIsEmpty())
{
Q.Dequeue(e);
Recursive_Reverse(Q);
Q.Enqueue(e);
outQData<<e;
}
}//End of Recursive Reverse Function
//Function will print the queue and leave it unchanged
void Print_Queue(queue& Q)
{
el_t e;
queue temp;
while(!Q.QueueIsEmpty())
{
Q.Dequeue(e);
outQData<<e;
temp.Enqueue(e);
}
while(!temp.QueueIsEmpty())
{
temp.Dequeue(e);
Q.Enqueue(e);
}
}//End of print Function
//Function will print out the successor of each element in the Queue
//and leave the Queue unchanged
void Sucessor_Q(queue& Q)
{
el_t e, suc_val;
queue temp;
while(!Q.QueueIsEmpty())
{
Q.Dequeue(e);
temp.Enqueue(e);
}
while(!temp.QueueIsEmpty())
{
temp.Dequeue(e);
suc_val = e + 1;
Q.Enqueue(suc_val);
outQData<<suc_val;
}
}//End Sucessor Function
//Function will repalce every value of a with z, leaving the queue
//otherwise unchanged.
void Replace_Q(queue Q, el_t old_val, el_t newval)
{
queue temp;
el_t e1;
while(!Q.QueueIsEmpty())
{
Q.Dequeue(e1);
if(e1 == old_val)
temp.Enqueue(newval);
else
temp.Enqueue(e1);
}
while(!temp.QueueIsEmpty())
{
temp.Dequeue(e1);
outQData<<e1;
Q.Enqueue(e1);
}
}//End of Replace Function