How do you delete the front cell of an array in an array based circular queue?

Here's the Queue cpp functions

#include <iostream>
#include <string>
#include "Contributor.h"
#include "myQueue.h"
using namespace std;

myQueue::myQueue()
	{
	         front=0;
		rear =0;
		Index=0;
		size= 0;
		ArrayQ[10];
	}


myQueue::myQueue(const myQueue &CCmyQueue)
{	
	for(int i=0;i < CCmyQueue.Index;i++)
		{			
			ArrayQ[i]=CCmyQueue.ArrayQ[i]; 
			front= CCmyQueue.front;
			rear =CCmyQueue.rear;
			Index=CCmyQueue.Index;
			size =CCmyQueue.size;
		}
}


myQueue &myQueue:: operator =(const myQueue & RHS) 
{
if(this!= &RHS)
	{
	  for (int i=0; i<RHS.Index;i++)
	  {
		ArrayQ[i]= RHS.ArrayQ[i];
		Index = RHS.Index;
		rear= RHS.rear;
		front= RHS.front;
		size= RHS.size;
	  }
	}
return *this;
}


myQueue::~myQueue()
{
cout<< "default D-Tor"<<endl;
}


bool myQueue::enQueue(Contributor InData)
{
	if(IsFull())
		{
			cout<< " Queue is full"<<endl;
			return false;
	         }
           else
                 {
			ArrayQ[rear]=InData;
			step(rear);
			Index++;
	        }
	cout<<"Index ="<<Index<<endl;
	return true;
}


bool myQueue::deQueue()
{
	if(IsEmpty())
	    {
			cout<<"the IsEmpty()"<< endl;
	    }
         else
          {
			//code for deleting the front data?
			step(front);
			--Index;
	}
return true;
}


bool myQueue::IsFull()
{
	if(Index==MAXSIZE)
		{
		return true;
		}
		return false;
}


bool myQueue::IsEmpty()
{
	if(Index==0)
	{
	     return true;
	}
	     return false;
}

void myQueue::step(int &num)
{
	if(num==(size-1))
	  {
	         num=0;
	  }
           else
            {
	        num++;
            }
}
void myQueue::ShowFront()
{
	cout<<"this is the Front Object"<<endl;
	cout<<ArrayQ[front]<<endl;
}

void myQueue::ShowRear()
{
	cout<<"this is the Rear Object "<<endl;
	cout<<ArrayQ[rear-1]<<endl;
}

void myQueue::PrintQ()
{
	for (int i=0;i<Index;++i)
	{
	        cout<<ArrayQ[i];
	}
}

The problem may be in my print function as well. I have it printing using the index, so it doesn't print out empty elements. Now I'm trying to delete the front element in the code above, and it appears to be working until I print the queue.

When I print the queue, the supposedly deleted element prints out, but the last element does not. I've attached all the functions if it will help.

Attachments
//*****************************************************************************
// TITLE:                           Contributor Class Header
// FILENAME:                        Contributor.h
// PREPARED FOR:                    CS 230 Lab 1
// PROGRAMMER:                      Jerry Gill
// DEVELOPMENT DATE:                22 July 08
// COMPILER USED:                   Visual Studio 2005
// TARGET PLATFORM:                 Win XP
//=============================================================================
//                      PROJECT FILES
//       LIST ALL PROGRAM AND HEADER FILES IN THE PROJECT
// Contributor Class.h		Contributor Class.cpp		Contributor Main.cpp
// Test.cpp
// 
//=============================================================================
//                      REVISION HISTORY
//             List revision made to the progman
//    DATE			PROGRAMMER         DESCRIPTION OF CHANGES MADE
// 22 July 08		Jerry Gill             Original program
//
//=============================================================================
//                       INCLUDE FILES
#pragma once
#include <string>
#include <iostream>
//=============================================================================
//                      CONSTANT DEFINITIONS
//
//=============================================================================
//                    GLOBAL CONSTANTS/OBJECTS
//                   
//=============================================================================
//					  START CLASS PROTOTYPE(S)
//=============================================================================

using namespace std;

enum gender {none,male,female};

class Contributor
{
	public:
		Contributor();
		Contributor (string Name, double Donation =0.0, gender sex=none, int IDKey=0);
		Contributor (const Contributor& CCContributor);
		friend ostream& operator << (ostream& out, const Contributor& InContributor);
		friend istream& operator >> (istream& in, Contributor& InContributor);
		Contributor& operator = (const Contributor& rhs);
		bool operator <  (const Contributor& rhs)const;
		bool operator >  (const Contributor& rhs)const;
		bool operator == (const Contributor& rhs)const;
		bool operator != (const Contributor& rhs)const;
		~Contributor();

	private:
		string Name;
		double Donation;
		int IDKey;
		gender Sex;		
};
//*****************************************************************************
// TITLE:                           Contributor Class 
// FILENAME:                        Contributor.cpp
// PREPARED FOR:                    CS 230 Lab 1
// PROGRAMMER:                      Jerry Gill
// DEVELOPMENT DATE:                22 July 08
// COMPILER USED:                   Visual Studio 2005
// TARGET PLATFORM:                 Win XP
//=============================================================================
//                      PROJECT FILES
//       LIST ALL PROGRAM AND HEADER FILES IN THE PROJECT
// Contributor Class.h		Contributor Class.cpp		Contributor Main.cpp
// Test.cpp
// 
//=============================================================================
//                      REVISION HISTORY
//             List revision made to the progman
//    DATE			PROGRAMMER         DESCRIPTION OF CHANGES MADE
// 22 July 08		Jerry Gill             Original program
//
//=============================================================================
// Class Description: A class of contributors for future use in the course
//						
// INPUTS: Inputs are currently interactive in the ostream function, but in the 
//         next release, interactivity will be removed.
//
// OUTPUTS: Outputs are currently sent to the screen 
//=============================================================================
//							CONSTANT DEFINITIONS
//            
//=============================================================================
//						   EXTERNAL CLASS VARIABLES                                     
//
//=============================================================================        
//						START CLASS MEMBER FUNCTION CODE
//*****************************************************************************

#include "Contributor Class.h"  //other necessary includes are in the header

		
Contributor::Contributor()		//default constructor
{
	Donation=0.0;
	Sex=none;
	IDKey=0;
}

Contributor::Contributor (std::string Name, double Donation, gender Sex, int IDKey)  //overloaded constructor
{
	this->Name=Name;
	this->Donation=Donation;
	this->Sex=Sex;
	this->IDKey=IDKey;
}

		
Contributor::Contributor (const Contributor& CCContributor)     //copy constructor
{
	Name=CCContributor.Name;
	Donation=CCContributor.Donation;
	Sex=CCContributor.Sex;
	IDKey=CCContributor.IDKey;
}


ostream& operator << (ostream& out, const Contributor& InContributor) //interactive input 
{
	out << "The Contributor's information is: " << endl << endl;
	out << " Name: " << InContributor.Name << endl;
	out << " Donation: " << InContributor.Donation << endl;
	out << " Sex: ";
		switch (InContributor.Sex)
		{
			case male: out << " Male "; break;
			case female: out << " Female "; break;
			default: out << " No information available ";
		}
		out << endl;
	out << " IDKey: " << InContributor.IDKey << endl << endl;
	return out;
}

istream& operator >> (istream& in, Contributor& InContributor)  //output to screen
{
	int sel=0;
	in.clear();
	in.ignore(in.rdbuf()->in_avail(),'\n');
	
	//cout << "Please enter the name of the contributor: "<< endl << endl;
	//getline (in, InContributor.Name);
	//cout << endl;
	//cout << "Please enter the amount of the donation from the contributor: "<< endl << endl;
	//in >> InContributor.Donation;
	//cout << endl;
	//cout << "Please enter number of the sex of the contributor: "<< endl << endl;
		//cout << "0 = Not Disclosed " << endl;
		//cout << "1 = The Contributor is male " << endl;
		//cout << "2 = The Contributor is female "<<endl;
	//in >> sel;

	//switch (sel)
	//{
	//	case 1: InContributor.Sex = male; break;
	//	case 2: InContributor.Sex = female; break;
	//	default: InContributor.Sex = none; break;
	//}
	//cout << endl;
	//cout << "Please enter the ID Key of the contributor: "<< endl << endl;
	//in >> InContributor.IDKey;
	//cout << endl << endl;
	return in;
}

Contributor& Contributor::operator = (const Contributor& rhs) //overload assignment operator
{
	if (&rhs != this)
	{
		this->Name=rhs.Name;
		this->Donation=rhs.Donation;
		this->Sex=rhs.Sex;
		this->IDKey=rhs.IDKey;
	}
	return *this;
}
		
bool Contributor::operator <  (const Contributor& rhs)const  //overload < operator
{
	if (Name < rhs.Name)
		return true;
	else
		return false;
}

bool Contributor::operator >  (const Contributor& rhs)const //overload > operator
{
	if (Name > rhs.Name)
		return true;
	else
		return false;
}

bool Contributor::operator == (const Contributor& rhs)const  //overload equality operator
{
	if ((Name==rhs.Name) && (Donation == rhs.Donation) && (Sex == rhs.Sex) && (IDKey == rhs.IDKey))
		return true;
	else
		return false;
}

bool Contributor::operator != (const Contributor& rhs)const    //overload inequality operator
{
	return ! (*this == rhs);
}

Contributor::~Contributor()				
{
	//for test// cout << "Killing Contributor" <<endl;
}
#include "Queue Class.h"

using namespace std;

int main()
{
	Queue theQueue;

	Contributor C1("Jerry", 1200.00, male,10);		
	Contributor C2("Lynnette", 1500.00, female, 11);
	Contributor C3("Sarah", 1700.00, female, 12) ;
	Contributor C4("Chuck", 800.00, male, 13);
	Contributor C5("Phil", 1000.00, male, 14);
	Contributor C6("Amanda", 1400.00, female, 15);
	
	theQueue.enQueue(C1);
	theQueue.enQueue(C2);
	theQueue.enQueue(C3);
	theQueue.enQueue(C4);
	theQueue.enQueue(C5);
	theQueue.enQueue(C6);
	theQueue.print();
	theQueue.qfront();
	theQueue.qrear();

	theQueue.deQueue();
	theQueue.print();
	theQueue.qfront();
	theQueue.qrear();

	return 0; 
}
//***************************************************************
// TITLE:                      	Contributor	
// FILEInContrib:                   	Contributor.cpp
// PREPARED FOR:               	CS230 Section <section number>
// PROGRAMMER(S):              	< Phillip Harris>
// DEVELOPMENT DATE:           	< 07/09/08>
// COMPILER USED:      		    <MS visual studio 2005>
// TARGET PLATFORM:         	< WIN XP >
//================================================================
//                           PROJECT FILES
//    	contributor.h, contributor.cpp,	Lab1.cpp
//================================================================
//                          REVISION HISTORY
//   DATE     PROGRAMMER            DESCRIPTION OF CHANGES MADE
//	<07/08/08	Phil Harris				Original >
//================================================================


#include "Queue Class.h"
using namespace std;

Queue::Queue()
	{
		front=0;
		rear =0;
		index=0;
		size= 0;
		Qarray[10];
	}
Queue::Queue(const Queue &CCQueue)
{	
	for(int i=0;i < CCQueue.index;i++)
		{			
			Qarray[i]=CCQueue.Qarray[i]; 
			front= CCQueue.front;
			rear =CCQueue.rear;
			index=CCQueue.index;
			size =CCQueue.size;
		}
}
Queue &Queue:: operator =(const Queue & RHS) 
{
if(this!= &RHS)
	{
	  for (int i=0; i<RHS.index;i++)
	  {
		Qarray[i]= RHS.Qarray[i];
		index = RHS.index;
		rear= RHS.rear;
		front= RHS.front;
		size= RHS.size;
	  }
	}
return *this;
}
Queue::~Queue()
{
cout<< "Burning the Evidence"<<endl;
}
bool Queue::enQueue(Contributor In)
{
	if(full())
		{
			cout<< " There is no more room"<<endl;
			return false;
		}else{
			Qarray[rear]=In;
			step(rear);
			index++;
		}

	cout << " The index is now " << index << endl;   //to make sure index is working

	return true;
}

bool Queue::deQueue()
{
	if(empty())
	    {
			cout <<" Joo didn't put anything in yet!! " << endl;
		}
	else
		{
			//delete front;
			step(front);
			--index;
		}

	cout << " The index is now " << index << endl;   //to make sure index is still working 

return true;
}

bool Queue::full()
{
	if(index==Max)
	{
		return true;
	}
		return false;
}

bool Queue::empty()
{
	if(index==0)
	{
		return true;	
	}
		return false;
}

void Queue::step(int &num)
{
	if(num==(size-1))
		{
			num=0;
		}else{
			num++;
		}
}
void Queue::qfront()
{
	cout <<"The Contributor in front: "<< endl;
	cout << Qarray[front] << endl;
}

void Queue::qrear()
{
	cout <<"The Contributor bringing up the rear: "<< endl;
	cout << Qarray[rear-1] << endl;
}

void Queue::print()
{
	for (int i=0;i<index;++i)
	{
		cout << Qarray[i] << endl;
	}
}
#pragma once
#include <iostream>
#include <string>
#include "Contributor Class.h"
using namespace std;
const int Max=10;
class Queue
{

public:

	Queue();
	Queue(Contributor In);
	Queue(const Queue &CCQueue);
	Queue &operator=(const Queue & RHS);
	~Queue();
	bool enQueue(Contributor In);
	bool deQueue();
	bool full();
	bool empty();
	void step(int &num);
	void qfront();
	void qrear();
	void print();
	
private:
	int front; 
	int rear; 
	int index;
	int size;
	Contributor Qarray[Max];
	Contributor dataIn;
};

I think you maybe misunderstand the meaning of index and size. There are some errors in your code, please see my comments below. I attached my code, which is base on yours. Please refer to it.

How do you delete the front cell of an array in an array based circular queue?

Here's the Queue cpp functions

#include <iostream>
#include <string>
#include "Contributor.h"
#include "myQueue.h"
using namespace std;

myQueue::myQueue()
	{
	         front=0;
		rear =0;
		Index=0;
		size= 0;
		ArrayQ[10];  //what does this mean? I think it's not necessary
	}


myQueue::myQueue(const myQueue &CCmyQueue)
{	
	for(int i=0;i < CCmyQueue.Index;i++)
		{			
			ArrayQ[i]=CCmyQueue.ArrayQ[i]; 
// you should get the following four lines out of this loop
			front= CCmyQueue.front;
			rear =CCmyQueue.rear;
			Index=CCmyQueue.Index;
			size =CCmyQueue.size;
		}
}


myQueue &myQueue:: operator =(const myQueue & RHS) 
{
if(this!= &RHS)
	{
	  for (int i=0; i<RHS.Index;i++)
	  {
		ArrayQ[i]= RHS.ArrayQ[i];
// the same as in the copy constructor 
		Index = RHS.Index;
		rear= RHS.rear;
		front= RHS.front;
		size= RHS.size;
	  }
	}
return *this;
}


myQueue::~myQueue()
{
cout<< "default D-Tor"<<endl;
}


bool myQueue::enQueue(Contributor InData)
{
	if(IsFull())
		{
			cout<< " Queue is full"<<endl;
			return false;
	         }
           else
                 {
			ArrayQ[rear]=InData;
			step(rear);
			Index++;
	        }
	cout<<"Index ="<<Index<<endl;
	return true;
}


bool myQueue::deQueue()
{
	if(IsEmpty())
	    {
			cout<<"the IsEmpty()"<< endl;
	    }
         else
          {
			//code for deleting the front data?
			step(front);
			--Index;
	}
return true;
}


bool myQueue::IsFull()
{
	if(Index==MAXSIZE)
		{
		return true;
		}
		return false;
}


bool myQueue::IsEmpty()
{
	if(Index==0)
	{
	     return true;
	}
	     return false;
}

void myQueue::step(int &num)
{
	if(num==(size-1))
	  {
	         num=0;
	  }
           else
            {
	        num++;
            }
}
void myQueue::ShowFront()
{
	cout<<"this is the Front Object"<<endl;
	cout<<ArrayQ[front]<<endl;
}

void myQueue::ShowRear()
{
	cout<<"this is the Rear Object "<<endl;
	cout<<ArrayQ[rear-1]<<endl;
}

void myQueue::PrintQ()
{
	for (int i=0;i<Index;++i)
	{
	        cout<<ArrayQ[i];
	}
}

okay, I understand most of what you've done, what does including the windows.h file give me? I've never used it before

okay, I understand most of what you've done, what does including the windows.h file give me? I've never used it before

I just glanced at littlestone's code, so I'm not sure whether you need windows.h to use it. I didn't see anywhere at first glance where you needed it, which doesn't mean that i couldn't have missed something. Try compiling with and without that #include line. Delete it if it makes no difference. windows.h is Windows-specific. Unless there's something in this assignment where you NEED to only have it work on Windows, and it doesn't appear to me that there is, don't use windows.h.

http://en.wikipedia.org/wiki/Windows.h

Thanks for the heads up Vernon. BTW I figured out the linked list thing thanks to your tips on the node class and how data was being passed in.

Sorry for troubling you with the windows.h. I included it just for using Sleep function to debug your code. After debugging I deleted the Sleep function but forgot to delete the windows.h.

This question has already been answered. Start a new discussion instead.