0

I am trying to write the class that will take in objs from another class and put it into a circular array without using the STL. O I wrote the class and in Main I delcared an obj of the queue called (myQueue myQ) so this is the obj but how do I make it an array?

thanks for any help.

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

#include <iostream>
#include <string>
#include <iomanip>
#include "Contributor.h"
#include "myQueue.h"

using namespace std;

int main()
{
	Contributor obj_A("phillip", 300.98, Male, 32); 
	Contributor obj_B("Debbie", 2500.24, Female, 112); 
	Contributor obj_C("Nanny MCfee", 23.08, Female, 132); 
	Contributor obj_D("David", 330.66, Male, 123); 
	Contributor obj_E("Thomas", 420.22, Male, 2); 
	Contributor obj_F("Stacie", 3.93, Male, 11); 

myQueue myQ;//this makes a myQueue

cout<<myQ(obj_B);
myQ.IsEmpty();

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 <iostream>
#include <string>
#include <iomanip>
#include "Contributor.h"
#include "myQueue.h"
using namespace std;

myQueue::myQueue()
	{		
		front;
		rear;
		Index;
		size;
		ArrayQ[2];
		//cout<<ArrayQ<<front<<rear<<Index<<size<<endl;
	}

	myQueue::~myQueue()
	{
		cout<<"Qdtor ran"<<endl;
	}

	bool myQueue::IsEmpty()
	{
		if (Index == 0){return true;}
		else{return false;} 
	}
	
	bool myQueue::IsFull()
	{
		cout<<"the size is :"<<size<<endl;
		cout <<"the index: " << Index<< endl;
		if (Index == size){return true;}
		else{return false;}
	}

	bool myQueue::enqueue(Contributor)
	{
		if(IsFull()){cout<<"this is myQueue is FULL"<<endl;}
		else 
		{
			((front ==rear)&&(size == 0))
			ArrayQ[rear] = contributor;
		}
		if(IsEmpty())
		{
			if(front==size ){front= 0;}
			if (rear==size){rear= 0;}
			ArrayQ[rear]= Contributor; 
			rear ++;
		}
	
	}
	/*bool DeQueue ()
		{
		delete qArray[front]= NULL;
		++front
		}
	InFront()
	{
	cout<<qArray[front]<<endl;
	}
	InRear()
	{
	cout<<qArray[rear]<<endl;
	}
	myQueue operator=(myQueue &RHS)
	{
	
	}
	myQueue (const myQueue &CCmyQueue)
	{
	
	}
*/
#ifndef	myQueue_H 
#define myQueue_H
#include <iostream>
#include <string>
#include "Contributor.h"
using namespace std;

class myQueue
{
public:
	myQueue(); 
	myQueue(const myQueue & CCqueue);
	myQueue & operator = (const myQueue & RHS); 
	~myQueue();
	
	int ArrayQ[7];
	void enqueue(const myQueue & Contributor);
	void dequeue(); 
	bool IsEmpty();
	bool IsFull();
	
private:
	int front;//this is front
	int rear;//this is rear
	int Index;
	int size;

};

#endif
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by phillipeharris
0

To make a class act like an array you can overload the [] operator to simulate the same kind of indexing:

class myQueue {
public:
  myQueue(); 
  myQueue(const myQueue & CCqueue);
  myQueue& operator =(const myQueue& rhs); 
  ~myQueue();

  void enqueue(const myQueue& Contributor);
  void dequeue(); 
  bool IsEmpty();
  bool IsFull();

  int& operator[](int i)
  {
    return GetAt(i);
  }

  const int& operator[](int i) const
  {
    return GetAt(i);
  }

private:
  int& GetAt(int i)
  {
    // TODO: Get the value at i modulo size
  }

  int array[7];
  int front;//this is front
  int rear;//this is rear
  int index;
  int size;
};
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.