Hello, I am required to solve the simulation case by using DYNAMIC QUEUE (linked-list) but the solution by using static queue (array)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hello, I am required to solve the simulation case by using DYNAMIC QUEUE (linked-list) but the solution by using static queue (array) are given as follows: 

(Note that I use Dev-C++)

//Header file: queueADT.h

#ifndef H_queueADT

#define H_queueADT

template <class Type>

class queueADT

{

public:

    virtual bool isEmptyQueue() const = 0;

    virtual bool isFullQueue() const = 0;

    virtual void initializeQueue() = 0;

    virtual Type front() const = 0;

    virtual Type back() const = 0;

    virtual void addQueue(const Type& queueElement) = 0;

     virtual void deleteQueue() = 0;  

};

#endif

 

//Header file: QueueasArray.h

#ifndef H_QueueAsArray

#define H_QueueAsArray

#include <iostream>

#include <cassert>

#include "queueADT.h"

using namespace std;

 

template <class Type>

class queueType: public queueADT <Type>

{

              public:

                             const queueType <Type>& operator = (const queueType <Type>&);

                             //Overload the assignment operator

                            

                             bool isEmptyQueue() const;

                             bool isFullQueue() const;

                             void initializeQueue();

                             Type front() const;

                             Type back() const;

                             void addQueue(const Type& queueElement);

                             void deleteQueue();

                             queueType(int queueSize = 100);

                             //Constructor

                             queueType(const queueType<Type>& otherQueue);

                             //Copy constructor

                             ~queueType();

                             //Destructor

                            

                             private:

                                 int maxQueueSize;

                                 int count;

                                 int queueFront;

                                 int queueRear;

                                 Type *list;

};

 

template <class Type>

bool queueType<Type>::isEmptyQueue() const

{

              return (count == 0);

}//end isEmptyQueue

 

template <class Type>

bool queueType<Type>::isFullQueue() const

{

              return (count == maxQueueSize);

}//end isFullQueue

 

template <class Type>

void queueType<Type>::initializeQueue()

{

              queueFront = 0;

              queueRear = maxQueueSize - 1;

              count = 0;

}// end initializeQueue

 

template <class Type>

Type queueType<Type>::front() const

{

              assert (!isEmptyQueue());

              return list [queueFront];

}// end front

 

template <class Type>

Type queueType<Type>::back() const

{

              assert(!isEmptyQueue());

              return list[queueRear];

}// end back

 

 

template <class Type>

void queueType<Type>::addQueue(const Type& newElement)

{

    if (!isFullQueue())

    {  

        queueRear = (queueRear + 1) % maxQueueSize; //use mod

                            //operator to advance queueRear 

                            //because the array is circular

        count++;

        list[queueRear] = newElement;

    }

    else

        cout << "Cannot add to a full queue." << endl;

} //end addQueue

 

template <class Type>

void queueType<Type>::deleteQueue()

{

    if (!isEmptyQueue())

    {  

        count--;

        queueFront = (queueFront + 1) % maxQueueSize; //use the

                        //mod operator to advance queueFront

                        //because the array is circular

    }

    else

        cout << "Cannot remove from an empty queue." << endl;

} //end deleteQueue

 

    //Constructor

template <class Type>

queueType<Type>::queueType(int queueSize)  

{

    if (queueSize <= 0)

    {

        cout << "Size of the array to hold the queue must "

             << "be positive." << endl;

        cout << "Creating an array of size 100." << endl;

 

        maxQueueSize = 100;

    }

    else

        maxQueueSize = queueSize;   //set maxQueueSize to

                                    //queueSize

 

    queueFront = 0;                 //initialize queueFront

    queueRear = maxQueueSize - 1;   //initialize queueRear

    count = 0;

    list = new Type[maxQueueSize];  //create the array to

                                    //hold the queue elements

} //end constructor

 

    //Destructor

template <class Type>

queueType<Type>::~queueType()  

{

    delete [] list;

} //end destructor

 

template <class Type>

const queueType<Type>& queueType<Type>::operator=

                                 (const queueType<Type>& otherQueue)

{

    cout << "Write the definition of the function "

         << "to overload the assignment operator." << endl;

} //end assignment operator

 

template <class Type>

queueType<Type>::queueType(const queueType<Type>& otherQueue)

{

    cout << "Write the definition of the copy constructor."

         << endl;

} //end copy constructor

#endif

 

Example of Case Simulation
• In the theater problem, when the cashier is serving a customer, other
Customers must wait.
• Because customers are served on a first come, first served basis and
queues are an effective way to implement a First In First Out system,
queues are important data structures for use in computer simulations.
• The main goal of a computer simulation is to either generate results
showing the performance of an existing system or predict the
performance of a proposed system.
This section examines computer simulations in which queues are the
basic data structure.
• These simulations model the behavior of systems, called queuing
systems, in which queues of objects are waiting to be served by various
servers.
Transcribed Image Text:Example of Case Simulation • In the theater problem, when the cashier is serving a customer, other Customers must wait. • Because customers are served on a first come, first served basis and queues are an effective way to implement a First In First Out system, queues are important data structures for use in computer simulations. • The main goal of a computer simulation is to either generate results showing the performance of an existing system or predict the performance of a proposed system. This section examines computer simulations in which queues are the basic data structure. • These simulations model the behavior of systems, called queuing systems, in which queues of objects are waiting to be served by various servers.
Example of Case Simulation
• The manager of a local movie theater is hearing complaints from
customers about the time they have to wait in line to buy tickets.
• The theater currently has only one cashier. Another theater is
preparing to open in the neighborhood and the manager is afraid of
losing customers.
• The manager wants to hire enough cashiers so that a customer does
not have to wait too long to buy a ticket.
• The manager would like to know the average time a customer has to
wait for service
• In a computer simulation, the objects being studied are usually
represented as data.
• For the theater problem, some of the objects are the customers and
the cashier.
Transcribed Image Text:Example of Case Simulation • The manager of a local movie theater is hearing complaints from customers about the time they have to wait in line to buy tickets. • The theater currently has only one cashier. Another theater is preparing to open in the neighborhood and the manager is afraid of losing customers. • The manager wants to hire enough cashiers so that a customer does not have to wait too long to buy a ticket. • The manager would like to know the average time a customer has to wait for service • In a computer simulation, the objects being studied are usually represented as data. • For the theater problem, some of the objects are the customers and the cashier.
Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY