Another C++ Issue

theraapster

Member
Established Member
Joined
Apr 25, 2004
Messages
661
Location
NKY
I am working on my final project for this class and I can't figure out this compile error.
The code:
Code:
	queue<Customer> sweepstakes[750];
	for(int i = 0; i < 1000; i++) {
		if(A[i].getEntersSweepstakes())
			sweepstakes.enqueue(A[i]); //error here
	}

The Error:
c:\documents and settings\my documents\cecs 302\finalproject\usecustomer.cpp(34) : error C2228: left of '.enqueue' must have class/struct/union

queue is a class that was made and works separate, and Customer is a class that we made and works separately. A is an array of Customer instances. I am trying to make a queue of all customers that are going to enter the sweepstakes.

The complete code can be found here.

Thanks in advance
 

Tabres

Not without incident
Established Member
Joined
Jan 31, 2003
Messages
9,818
Location
Bloomington, Il
Shouldn't this be:
sweepstakes.queue(A); //error here


and not the enqeue you have listed? Or is enqueue another class?

I can't make heads or tails of the arrayQueue source because the formatting is way the hell screwed up in folder of the complete code.

-edit- spelling
 
Last edited:

theraapster

Member
Established Member
Joined
Apr 25, 2004
Messages
661
Location
NKY
Tabres said:
Shouldn't this be:
sweepstakes.queue(A); //error here


and not the enqeue you have listed? Or is enqeue another class?


enqueue is a member function of the queue class that actually enqueues the item. Other member functions of the queue class are:
Code:
      queue();
      queue(int queueSize);

      // a destructor is necessary, since the container is dynamically allocated
      ~queue();     


      void enqueue(element_type element);  // add an element to tail
      element_type dequeue();              // remove element from head
      bool isEmpty();       
      bool isFull();
      int size();
      element_type top();               // return element on stack top
 

Tabres

Not without incident
Established Member
Joined
Jan 31, 2003
Messages
9,818
Location
Bloomington, Il
Are you missing a variable type for sweepstakes? Or is that what queue<Customer> is? Seems like it's something to do with how sweepstakes is declared...

Then again I could be way off because it's been a long time since I've done anything significant in C++...
 

theraapster

Member
Established Member
Joined
Apr 25, 2004
Messages
661
Location
NKY
Tabres said:
Are you missing a variable type for sweepstakes? Or is that what queue<Customer> is? Seems like it's something to do with how sweepstakes is declared...

Then again I could be way off because it's been a long time since I've done anything significant in C++...

Customer should be the variable type for queue. Just noticed you couldn't read the code so here you go:
Code:
// This file contains the definitions presented in class
// for a stack with a predefined container element type
// and using a bounded array for the container

#ifndef ARRAY_QUEUE_TEMPLATE_H
#define ARRAY_QUEUE_TEMPLATE_H
#define DEFAULT_MAX 1000

#include <cassert>
#include "Customer.h"
using namespace std;


template <class element_type>
class queue {
   public: 


      // Provide two constructors: the default constructor
      // and one that allows the programmer to specify stack size
      queue();
      queue(int queueSize);

      // a destructor is necessary, since the container is dynamically allocated
      ~queue();     


	  void enqueue(element_type element);  // add an element to tail
	  element_type dequeue();              // remove element from head
      bool isEmpty();       
      bool isFull();
      int size();
      element_type top();               // return element on stack top

   private:
      element_type *elements;           // container for the queue
      int numUsed;                      // number of items in the queue
      int maxQueueSize;                 // maximum size of the queue
	  int head;                         // beginning of queue
	  int tail;                          // end of queue
};

template <class element_type>
queue<element_type>::queue() {
 
   // Create a new array of elements using
   // the default maximum size
   elements = new element_type[DEFAULT_MAX];  
   maxQueueSize = DEFAULT_MAX;
   numUsed = 0;
   head = -1;
   tail = -1; 
}

template <class element_type>
queue<element_type>::queue(int queueSize) { 
 
    // Create a new array of elements based
    // on the queue size passed in
    elements = new element_type[queueSize];
    maxQueueSize = queueSize;
    numUsed = 0;
	head = 0;
	tail = -1;
}

template <class element_type>
queue<element_type>::~queue() {
   delete [] elements;
}

template <class element_type>
void queue<element_type>::enqueue(element_type element) {
   assert(!isFull());            // Make sure that we don.t add to a full queue
   tail++;
   elements[tail] = element;     // Add the new element to the tail of the queue
   numUsed++;
}

template <class element_type>
element_type queue<element_type>::dequeue() {
    element_type topElement;
    assert(!isEmpty());        // Can't dequeue from an empty queue
    topElement = top();
	head++;
    numUsed--;
   return(topElement);
}

template <class element_type>
bool queue<element_type>::isEmpty()   { return(head > tail); }

template <class element_type>
bool queue<element_type>::isFull()    { return(tail == (maxQueueSize - 1)); }

template <class element_type>
int queue<element_type>::size()       { return(numUsed); }

template <class element_type>
element_type queue<element_type>::top() {
   // This function returns the element at the head of the queue
   // without altering the queue

   assert(!isEmpty());     
   return(elements[head]);
}

#endif
 

bolinger06

New Member
Established Member
Joined
Aug 6, 2006
Messages
247
Location
Indiana
seeing stuff like this makes me not want to go to college at all. i get scared just looking at that stuff
 

azgardia

Wanderer
Established Member
Joined
Oct 5, 2003
Messages
801
Location
Montgomery NY
bolinger06 said:
seeing stuff like this makes me not want to go to college at all. i get scared just looking at that stuff
Anyone got some engineering questions?:lol:
Ill point this thread out to a friend of mine and see if he can help.
 
Joined
Aug 21, 2003
Messages
8,394
Location
Earth
bolinger06 said:
seeing stuff like this makes me not want to go to college at all. i get scared just looking at that stuff

Unless you plan on being a programmer, you're not going to encounter anything like this in college.
 

theraapster

Member
Established Member
Joined
Apr 25, 2004
Messages
661
Location
NKY
azgardia said:
Anyone got some engineering questions?:lol:
Ill point this thread out to a friend of mine and see if he can help.

I am a computer engineering major, haha. Any help from your friend by any chance?
 

gump

aka jamz
Established Member
Joined
Jun 10, 2005
Messages
4,853
Location
buford ga
bolinger06 said:
seeing stuff like this makes me not want to go to college at all. i get scared just looking at that stuff
there are 11-14 year olds who master everything from C++, VB, and all of the other programming languages out there.

Its about familiarizing yourself with it is all. I never took C ++, only VB6 is all.
 

Users who are viewing this thread



Top