I can not get this code to compile...Not sure why?

// This program demonstrates the IntQueue class
#include <iostream>
#include "IntQueue.h"
using namespace std;
int main()
{
IntQueue iQueue(5);
cout << "Enqueuing 5 items...\n";

//Enqueue 5 items.
for (int k = 1; k <= 5; k++)
iQueue.enqueue(k*k);

// Dequeue and retrieve all items in the queue.
cout << "The value in the queue were: ";
while (!Queue.isEmpty())
{
int value;
iQueue.dequeue(value);
cout << value << " ";
}
cout <<endl;

return 0;
}





#include <iostream>
#include "IntQueue.h"
using namespace std;

//*******************************************************
// Constructor. *
//*******************************************************
IntQueue::IntQueue(int s)
{
queueArray = new int[s];
queueSize = s;
front = -1;
rear = -1
numItems = 0
}

//*******************************************************
// Destructor. *
//*******************************************************
IntQueue::~IntQueue()
{
delete [] queueArray;
}

//********************************************************
// Function enqueue inserts the value in num *
// at the rear of the queue. *
//********************************************************
void IntQueue::enqueue(int num)
}
if (isFull())
{
cout << "The queue is full.\n";
exit(1);
}
else
{
//Calculate the new rear position.
rear = (rear + 1) % queueSize;
// Insert new item.
queueArray[rear] = num;
// Update item count.
numItem++;
}
}

//**********************************************************
// Function dequeue removes the value at the *
// front of the queue, and copies it into num. *
//**********************************************************
void IntQueue::dequeue(int &num)
{
if (isEmpty())
{
cout << "The queue is empty.\n"
exit(1);
}
else
{
//Move front.
front = (front + 1) % queueSize;
//Retrieve the front item.
num = queueArray[front];
//Update item count.
numItems--;
}
}

//***********************************************************
// Function isFull returns true if the queue *
// is full, and false otherwise. *
//***********************************************************
bool IntQueue::isEmpty()
{
if (numItems > 0)
return false;
else
return true;
}

//************************************************************
// Function clear resets the front and rear *
// indices, and sets numItems to 0. *
//************************************************************
bool IntQueue::isFull()
{
if (numItems < queueSize)
return false;
else
return true;
}

//*************************************************************
// Function clear resets the front and rear *
// indices, and sets numItem to 0. *
//*************************************************************
void IntQueue::clear()
{
front = -1;
rear = -1;
numItem = 0;
}




#ifndef INTQUEUE_H
#define INTQUEUE_H

class IntQueue
{
private:
int *queueArray;
int queueSize;
int front;
int rear;
int numItems;
public;
IntQueue(int);
~IntQueue();
void enqueue(int);
void dequeue(int &);
bool isEmpty();
bool isFull();
void clear();
};
#endif
First:
http://cplusplus.com/forum/beginner/1/#msg6680

Second, [code] tags please.

Third, look at your class declaration and the definition of your constructor. See any excess/missing semicolons?

-Albatross
Read the compiler error messages. They make it clear.

IntQueue.h:12: error: expected ‘:’ before ‘;’ token

You must put a ':' after public, not a ';'

72.cpp: In function ‘int main()’:
72.cpp:15: error: ‘Queue’ was not declared in this scope

You've tried to use an object named Queue, which does not exist. Perhaps you meant iQueue?


IntQueue.cpp:14: error: expected ‘;’ before ‘numItems’

You've missed some semi-colons from the end of some lines.

IntQueue.cpp:30: error: expected initializer before ‘}’ token

You've put a closing brace where you meant to put an opening brace.

IntQueue.cpp:34: error: ‘exit’ was not declared in this scope

You've left out a needed header file to use the exit function.

IntQueue.cpp:43: error: ‘numItem’ was not declared in this scope

You've tried to use an object that does not exist. Perhaps you meant numItems?

There are more.


Last edited on
Topic archived. No new replies allowed.