Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using c++ i need the implemntation of each function please // QueueLinked.h #include #include using namespace std; #include Queue.h template class QueueLinked : public Queue

using c++ i need the implemntation of each function please

// QueueLinked.h

#include #include

using namespace std;

#include "Queue.h"

template class QueueLinked : public Queue { public: QueueLinked(int maxNumber = Queue::MAX_QUEUE_SIZE); QueueLinked(const QueueLinked& other); QueueLinked& operator=(const QueueLinked& other); ~QueueLinked();

void enqueue(const DataType& newDataItem) throw (logic_error); DataType dequeue() throw (logic_error);

void clear();

bool isEmpty() const; bool isFull() const;

// Programming Exercise 2 void putFront(const DataType& newDataItem) throw (logic_error); DataType getRear() throw (logic_error); // Programming Exercise 3 int getLength() const;

void showStructure() const;

private: class QueueNode { public: QueueNode(const DataType& nodeData, QueueNode* nextPtr);

DataType dataItem; QueueNode* next; };

QueueNode* front; QueueNode* back; };

//-------------------------------------------------------------------- // // Laboratory 7, Programming Exercise 1 storesim.cs // // Program implementation shell. // //--------------------------------------------------------------------

// Simulates the flow of customers through a line in a store.

#include #include #include #include

// Use which ever implementation is currently configured. #if LAB7_TEST1 # include "QueueLinked.cpp" #else # include "QueueArray.cpp" #endif

using namespace std;

int main () { #if LAB7_TEST1 QueueLinked custQ; // Line (queue) of customers containing the #else QueueArray custQ; // Line (queue) of customers containing the #endif // time that each customer arrived and // joined the line int simLength, // Length of simulation (minutes) minute, // Current minute timeArrived, // Time dequeued customer arrived waitTime, // How long dequeued customer waited totalServed = 0, // Total customers served totalWait = 0, // Total waiting time maxWait = 0, // Longest wait numArrivals = 0; // Number of new arrivals

// Seed the random number generator. Equally instructive to run the // simulation with the generator seeded and not seeded. srand( time(NULL) );

cout << endl << "Enter the length of time to run the simulator : "; cin >> simLength;

// Put your code here to run this simulation. Use "rand()" to get // a pseudorandom number that you can use to calculate probabilities.

// Print out simulation results cout << endl; cout << "Customers served : " << totalServed << endl; cout << "Average wait : " << setprecision(2) << double(totalWait)/totalServed << endl; cout << "Longest wait : " << maxWait << endl;

return 0; } //-------------------------------------------------------------------- // // Laboratory 7 Queue.h // // Class declaration of the abstract class interface to be used as // the basis for implementations of the Queue ADT. // //--------------------------------------------------------------------

#ifndef QUEUE_H #define QUEUE_H

#include #include

using namespace std;

//--------------------------------------------------------------------

template class Queue { public: static const int MAX_QUEUE_SIZE = 8;

virtual ~Queue();

virtual void enqueue(const DataType& newDataItem) throw (logic_error) = 0; virtual DataType dequeue() throw (logic_error) = 0;

virtual void clear() = 0;

virtual bool isEmpty() const = 0; virtual bool isFull() const = 0;

// The conditional compilation tests below are very important. // Because the functions declared are pure virtual functions, if they // are declared in the base class, then they MUST be implemented in any // derived classes. But they are supposed to be optional implementations. // Consequently, they must only be declared here if they are being // implemented in the derived classes. #if LAB7_TEST2 virtual void putFront(const DataType& newDataItem) throw (logic_error) = 0; virtual DataType getRear() throw (logic_error) = 0; #endif #if LAB7_TEST3 virtual int getLength() const = 0; #endif

virtual void showStructure() const = 0; };

template Queue::~Queue() // Not worth having a separate class implementation file for the destuctor {}

#endif // #ifndef QUEUE_H

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions