I realize no one is going to want to read through this source code but if anyone does and is able to tell me why I'm getting the errors I'm getting I would be extremely grateful and would pay them back somehow. My code is as follows (I just put it all in one file to make it easier to read, in reality I have it broken up into a 5, 4 .h's and 2 drivers)
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <new>
using namespace std;
/*-- LQueue.h -------------------------------------------------------------
This header file defines a Queue data type.
Basic operations:
constructor: Constructs an empty queue
empty: Checks if a queue is empty
enqueue: Modifies a queue by adding a value at the back
front: Accesses the top queue value; leaves queue unchanged
dequeue: Modifies queue by removing the value at the front
display: Displays all the queue elements
-------------------------------------------------------------------------*/
class Call
{
public:
/***** Function Members *****/
/***** Constructor *****/
Call();
/*----------------------------------------------------------
Construct a Call object (default).
Precondition: None
Postcondition: All data members are initialized to 0.
-----------------------------------------------------------*/
int getArrivalTime() const;
/*----------------------------------------------------------
Accessor function for arrival time.
Precondition: None
Postcondition: Value of myTimeOfArrival was returned.
-----------------------------------------------------------*/
int getServiceTime() const;
/*----------------------------------------------------------
Accessor function for service time.
Precondition: None
Postcondition: Value of myServiceTime was returned.
-----------------------------------------------------------*/
void display(ostream & out) const;
/*----------------------------------------------------------
Display call
Precondition: ostream out is a reference parameter
Postcondition: Call has been output to out.
-----------------------------------------------------------*/
private:
/***** Data Members *****/
int myTimeOfArrival;
int myServiceTime;
}; // end of Timer class declaration
//--- Prototype for output operator
ostream & operator<<(ostream & out, const Call & aCall);
typedef int QueueElement;
class Queue
{
public:
/***** Function Members *****/
/***** Constructors *****/
Queue();
/*-----------------------------------------------------------------------
Construct a Queue object.
Precondition: None.
Postcondition: An empty Queue object has been constructed.
(myFront and myBack are initialized to null pointers).
-----------------------------------------------------------------------*/
Queue(const Queue & original);
/*-----------------------------------------------------------------------
Copy Constructor
Precondition: original is the queue to be copied and is received
as a const reference parameter.
Postcondition: A copy of original has been constructed.
-----------------------------------------------------------------------*/
/***** Destructor *****/
~Queue();
/*-----------------------------------------------------------------------
Class destructor
Precondition: None.
Postcondition: The linked list in the queue has been deallocated.
-----------------------------------------------------------------------*/
/***** Assignment *****/
const Queue & operator= (const Queue & rightHandSide);
/*-----------------------------------------------------------------------
Assignment Operator
Precondition: rightHandSide is the queue to be assigned and is
received as a const reference parameter.
Postcondition: The current queue becomes a copy of rightHandSide
and a reference to it is returned.
-----------------------------------------------------------------------*/
bool empty() const;
/*-----------------------------------------------------------------------
Check if queue is empty.
Precondition: None.
Postcondition: Returns true if queue is empty and false otherwise.
-----------------------------------------------------------------------*/
void enqueue(Call);
/*-----------------------------------------------------------------------
Add a value to a queue.
Precondition: value is to be added to this queue.
Postcondition: value is added at back of queue.
-----------------------------------------------------------------------*/
void display(ostream & out) const;
/*-----------------------------------------------------------------------
Display values stored in the queue.
Precondition: ostream out is open.
Postcondition: Queue's contents, from front to back, have been
output to out.
-----------------------------------------------------------------------*/
QueueElement front() const;
/*-----------------------------------------------------------------------
Retrieve value at front of queue (if any).
Precondition: Queue is nonempty.
Postcondition: Value at front of queue is returned, unless the queue
is empty; in that case, an error message is displayed and a
"garbage value" is returned.
-----------------------------------------------------------------------*/
void dequeue();
/*-----------------------------------------------------------------------
Remove value at front of queue (if any).
Precondition: Queue is nonempty.
Postcondition: Value at front of queue has been removed, unless
queue is empty; in that case, an error message is displayed
and execution allowed to proceed.
-----------------------------------------------------------------------*/
private:
/*** Node class ***/
class Node
{
public:
QueueElement value;
QueueElement data;
Node * next;
//--- Node constructor
Node(QueueElement value, Node * link = 0)
/*-------------------------------------------------------------------
Precondition: value and link are received
Postcondition: A Node has been constructed with value in its
data part and its next part set to link (default 0).
------------------------------------------------------------------*/
{ data = value; next = link; }
};
typedef Node * NodePointer;
/***** Data Members *****/
NodePointer myFront, // pointer to front of queue
myBack; // pointer to back of queue
}; // end of class declaration
const int NUM_CATEGORIES = 5;
class Timer
{
public:
/***** Function Members *****/
/***** Constructor *****/
Timer (int initTime = 0);
/*----------------------------------------------------------
Construct a Timer object.
Precondition: The initial value initTime to start the
timer is received.
Postcondition: myMinutes has been initialized to
initTime minutes (default 0).
-----------------------------------------------------------*/
/***** Set timer *****/
void set(int minutes);
/*----------------------------------------------------------
Set/reset the timer.
Precondition: None
Postcondition: myMinutes has been set to minutes.
-----------------------------------------------------------*/
/***** Decrement timer *****/
void tick();
/*----------------------------------------------------------
Advance the clock one minute.
Precondition: None
Postcondition: myMinutes has been decremented by 1.
-----------------------------------------------------------*/
/***** Check time remaining *****/
int timeRemaining() const;
/*----------------------------------------------------------
Find how much time remains on the countdown timer.
Precondition: None
Postcondition: Time left before timer runs out is
returned.
-----------------------------------------------------------*/
private:
/***** Data Members *****/
int myMinutes;
}; // end of class declaration
class Simulation
{
public:
/***** Function Members *****/
/***** Constructor *****/
Simulation();
/*-----------------------------------------------------------------------
Construct a Simulation object.
Precondition: None
Postcondition: Input data members have been initialized with values
entered by the user; output data members have been initialized
to 0; and random number generator has been initialized.
-----------------------------------------------------------------------*/
/***** Running the simulation *****/
void run();
/*-----------------------------------------------------------------------
Run the simulation.
Precondition: None.
Postcondition: Simulation of phone service has been completed and
performance statistics output.
-----------------------------------------------------------------------*/
/***** Output *****/
void display(ostream & out);
/*----------------------------------------------------------------------
Display results of the simulation.
Precondition: ostream out is open.
Postcondition: Total number of calls and the average waiting time
for calls have been output to out.
-----------------------------------------------------------------------*/
/***** Call processing *****/
void service(int & busyTimeRemaining);
/*----------------------------------------------------------------------
Service the current call (if any).
Precondition: None
Postcondition: busyTimeRemaining has been decremented by one if a call
was being serviced; otherwise, if there were incoming calls, a
call has been removed from myIncomingCalls, its service time
assigned to busyTimeRemaining, and its waiting time in the queue
added to myTotalWaitingTime.
-----------------------------------------------------------------------*/
void checkForNewCall();
/*----------------------------------------------------------------------
Check if a new call has arrived and if so, add it to the
queue of incoming calls.
Precondition: None.
Postcondition: myIncomingCalls has been updated.
-----------------------------------------------------------------------*/
private:
/***** Data Members *****/
//-- Inputs
int myLengthOfSimulation;
double myArrivalRate;
int myServicePercent[NUM_CATEGORIES];
//-- Outputs
int myCallsReceived;
double myTotalWaitingTime;
//-- Countdown Timer
Timer myTimer;
//-- Queue of calls waiting for service
Queue myIncomingCalls;
}; // end of class declaration
//--- Definition of Queue constructor
Queue::Queue()
: myFront(0), myBack(0)
{}
//--- Definition of Queue copy constructor
Queue::Queue(const Queue & original)
{
myFront = myBack = 0;
if (!original.empty())
{
// Copy first node
myFront = myBack = new Queue::Node(original.front());
// Set pointer to run through original's linked list
Queue::NodePointer origPtr = original.myFront->next;
while (origPtr != 0)
{
myBack->next = new Queue::Node(origPtr->data);
myBack = myBack->next;
origPtr = origPtr->next;
}
}
}
//--- Definition of Queue destructor
Queue::~Queue()
{
// Set pointer to run through the queue
Queue::NodePointer prev = myFront,
ptr;
while (prev != 0)
{
ptr = prev->next;
delete prev;
prev = ptr;
}
}
//--- Definition of assignment operator
const Queue & Queue::operator=(const Queue & rightHandSide)
{
if (this != &rightHandSide) // check that not q = q
{
this->~Queue(); // destroy current linked list
if (rightHandSide.empty()) // empty queue
myFront = myBack = 0;
else
{ // copy rightHandSide's list
// Copy first node
myFront = myBack = new Queue::Node(rightHandSide.front());
// Set pointer to run through rightHandSide's linked list
Queue::NodePointer rhsPtr = rightHandSide.myFront->next;
while (rhsPtr != 0)
{
myBack->next = new Queue::Node(rhsPtr->data);
myBack = myBack->next;
rhsPtr = rhsPtr->next;
}
}
}
return *this;
}
//--- Definition of empty()
bool Queue::empty() const
{
return (myFront == 0);
}
//--- Definition of enqueue()
void Queue::enqueue(Call)
{
Queue::NodePointer newptr = new Queue::Node(value);
//
ERROR IS: value not declared
if (empty())
myFront = myBack = newptr;
else
{
myBack->next = newptr;
myBack = newptr;
}
}
//--- Definition of display()
void Queue::display(ostream & out) const
{
Queue::NodePointer ptr;
for (ptr = myFront; ptr != 0; ptr = ptr->next)
out << ptr->data << " ";
out << endl;
}
//--- Definition of front()
QueueElement Queue::front() const
{
if (!empty())
return (myFront->data);
else
{
cerr << "*** Queue is empty "
" -- returning garbage ***\n";
QueueElement * temp = new(QueueElement);
QueueElement garbage = *temp; // "Garbage" value
delete temp;
return garbage;
}
}
//--- Definition of dequeue()
void Queue::dequeue()
{
if (!empty())
{
Queue::NodePointer ptr = myFront;
myFront = myFront->next;
delete ptr;
if (myFront == 0) // queue is now empty
myBack = 0;
}
else
cerr << "*** Queue is empty -- can't remove a value ***\n";
}
//--- Definition of constructor
Simulation::Simulation()
{
//-- Initialize output statistics
myCallsReceived = 0;
myTotalWaitingTime = 0;
//-- Get simulation parameters
cout << "Enter arrival rate (calls per hour): ";
int callsPerHour;
cin >> callsPerHour;
myArrivalRate = callsPerHour / 60.0; // convert to calls per minute
cout << "Enter percent of calls serviced in\n";
int percent,
sum = 0;
for (int i = 0; i < NUM_CATEGORIES - 1; i++)
{
cout << " <= " << i + 1 << " min. "; cin >> percent;
sum += percent;
myServicePercent[i] = sum;
}
myServicePercent[NUM_CATEGORIES - 1] = 100;
cout << "Enter # of minutes to run simulation: ";
cin >> myLengthOfSimulation;
// Set the countdown timer
myTimer.set(myLengthOfSimulation);
//-- Initialize random number generator
long seed = long(time(0)); // seed for random number generator
srand(seed);
}
//--- Definition of run()
void Simulation::run()
{
// Begin the simulation
int busyTimeLeft = 0;
while (myTimer.timeRemaining() > 0)
{
service(busyTimeLeft);
checkForNewCall();
myTimer.tick();
}
cout << "\nNot accepting more calls -- service those waiting\n";
// Service any remaining calls in incomingCalls queue
while (!myIncomingCalls.empty())
{
service(busyTimeLeft);
myTimer.tick();
}
// Output the results
display(cout);
}
//--- Definition of display()
void Simulation::display(ostream & out)
{
out << "\nNumber of calls processed: " << myCallsReceived
<< "\nAve. waiting time per call: "
<< myTotalWaitingTime / myCallsReceived
<< " minutes" << endl;
}
//--- Definition of service()
void Simulation::service(int & busyTimeRemaining)
{
if (busyTimeRemaining > 0) // servicing a call
busyTimeRemaining--; // service it for another minute
else
if (!myIncomingCalls.empty()) // calls are waiting -- get one
{
Call nextCall = myIncomingCalls.front();
//
ERROR IS: conversion from queuetype to no scaler type call
myIncomingCalls.dequeue();
busyTimeRemaining = nextCall.getServiceTime();
// Update total waiting time
myTotalWaitingTime +=
nextCall.getArrivalTime() - myTimer.timeRemaining();
}
}
//--- Definition of checkForNewCall()
void Simulation::checkForNewCall()
{
int x = rand() % 100;
if (x < 100 * myArrivalRate)
{
// A new call has arrived. Generate a random service time for it
int r = rand() % 100;
int serviceTime = 0;
while (r > myServicePercent[serviceTime])
serviceTime++;
// Construct a new call and add it to queue of incoming calls
Call newCall(myTimer, serviceTime + 1);
myIncomingCalls.enqueue(newCall);
myCallsReceived++;
}
}
//--- Definition of constructor
Timer::Timer(int initTime)
{
assert(initTime >= 0);
myMinutes = initTime;
}
//--- Definition of set()
void Timer::set(int minutes)
{
assert(minutes >= 0);
myMinutes = minutes;
}
//--- Definition of tick()
void Timer::tick()
{
myMinutes--;
}
//--- Definition of timeRemaining()
int Timer::timeRemaining() const
{
return myMinutes;
}
//--- Definition of Default Constructor
Call::Call()
{
myTimeOfArrival = myServiceTime = 0;
}
//--- Definition of getArrivalTime()
int Call::getArrivalTime() const
{
return myTimeOfArrival;
}
//--- Definition of getServiceTime()
int Call::getServiceTime() const
{
return myServiceTime;
}
//--- Definition of display()
void Call::display(ostream & out) const
{
out << "Arrival Time: " << myTimeOfArrival << endl
<< "Service Time: " << myServiceTime << endl;
}
//-- Definition of output operator
ostream & operator<<(ostream & out, const Call & aCall)
{
aCall.display(out);
return out;
}
int main()
{
Simulation sim;
sim.run();
return 0;
}
I put my errors where they appear in the source code. Like I said I know it's a lot of code to read but I would appreciate it so much if anyone took the time to help me with these last two errors. I have to turn this into my boss in two days so I need to finish it