using this c++ code, can u change it a little bit into printing simulating. instead num_minutes 20, it should be change to only 10 person to serve.  #include #include #include #include #define NUM_MINUTES 20 #define MIN_MINUTES_PER_ARRIVAL 1 #define MAX_MINUTES_PER_ARRIVAL 4 #define MIN_MINUTES_PER_SERVICE 1 #define MAX_MINUTES_PER_SERVICE 4 static int customerArrivalTimes[NUM_MINUTES]; int main() {

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

using this c++ code, can u change it a little bit into printing simulating. instead num_minutes 20, it should be change to only 10 person to serve. 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#define NUM_MINUTES 20
#define MIN_MINUTES_PER_ARRIVAL 1
#define MAX_MINUTES_PER_ARRIVAL 4
#define MIN_MINUTES_PER_SERVICE 1
#define MAX_MINUTES_PER_SERVICE 4
static int customerArrivalTimes[NUM_MINUTES];

int main()
{
    // This will seed the random number generator.
    unsigned int seed = (unsigned)time( NULL );
    printf( "seeding with %u\n", seed );
    srand( seed );

    int nextArrival;

    // The value of -1 is reserved to indicate that no customer is currently being serviced.
    int nextService = -1;
    int longestWait = 0;
    int longestQueue = 0;
    int queueLength = 0;
    int queueStart = 0;
    int queueEnd = 0;

    // This will use the random number generator to set the arrival time of the first customer.
    nextArrival = rand() % (MAX_MINUTES_PER_ARRIVAL + 1 - MIN_MINUTES_PER_ARRIVAL) + MIN_MINUTES_PER_ARRIVAL;

    // This simulation will start at minute 0 and end at minute NUM_MINUTES - 1
    for ( int i = 0; i < NUM_MINUTES; i++ )
    {
        //check if the next customer is scheduled to arrive in this minute
        if ( nextArrival == i )
        {
            //update queueLength and test if record has been broken
            queueLength++;
            if ( queueLength > longestQueue ) longestQueue = queueLength;

            //print information message
            printf( "%03d:New customer arriving, queue length now: %d.\n", i, queueLength );

            //remember the arrival time of the current customer
            customerArrivalTimes[queueEnd++] = i;

            //set random arrival time for next customer
            nextArrival = rand() % (MAX_MINUTES_PER_ARRIVAL + 1 - MIN_MINUTES_PER_ARRIVAL) + MIN_MINUTES_PER_ARRIVAL + i;

            //if queue was empty, start servicing the new customer
            if ( queueLength == 1 )
            {
                // The following line will abort the program with an error
                // message if nextService is a valid time value (not -1).
                // This should not happen if the queue was empty. Therefore,
                // this would indicate a bug in the program.
                assert( nextService == -1 );

                //schedule completion time of next customer service
                nextService = rand() % (MAX_MINUTES_PER_SERVICE + 1 - MIN_MINUTES_PER_SERVICE) + MIN_MINUTES_PER_SERVICE + i;
            }
        }

        //check if customer service is scheduled to finish in this minute
        if ( nextService == i )
        {
            //print information message
            printf(
                "%03d:Customer service completed, total time: %d.\n",
                i, i - customerArrivalTimes[queueStart]
            );

            // This code block will update the variable longestWait if the
            // record was broken
            if ( longestWait < i - customerArrivalTimes[queueStart] )
            {
                longestWait = i - customerArrivalTimes[queueStart];
            }

            //update the starting point and length of the queue
            queueStart++;
            queueLength--;

            // The following line will abort the program with an error message
            // if queueLength ever becomes negative (which should never happen
            // and would indicate a bug in the program).
            assert( queueLength >= 0 );

            //if queue is not empty, start servicing the next customer
            if ( queueLength != 0 )
            {
                //schedule completion time of next customer service
                nextService = rand() % (MAX_MINUTES_PER_SERVICE + 1 - MIN_MINUTES_PER_SERVICE) + MIN_MINUTES_PER_SERVICE + i;
            }
            //otherwise indicate that no customer is currently being serviced
            else
            {
                nextService = -1;
            }
        }
    }
    printf( "Longest wait: %d\n", longestWait );
    printf( "Longest queue: %d\n", longestQueue );

    return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps

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