Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using c++ and data structure Dubai port is having trouble keeping up with the in

ID: 3823661 • Letter: U

Question

using c++ and data structure

Dubai port is having trouble keeping up with the incoming cargo ship traffic.

They have come up with a priority system where ships would be allowed in the

port according to which one has the maximum priority as calculated by the

following formula:

priority=#containers * (1+days waiting)

The port is able to unload five ships per day.

Your task is to create a simulator of the port operation. Your program should

generate a given number of ships (as specified in the command line) each with

a random number of containers in the range of [100, 1000]. Your program

should then print out the order that these ships will come into the port, and the

min, max and average waiting time.

An example of how the program should be called:

$ portSim 10 // should simulate 10 ships

Order : 0 2 5 6 7 8 9 1 4 3

Min : 0

Max : 1

Average : 0.5

Explanation / Answer

#include <iostream.h>
#include <vector>
#include <cstdlib>
#include <time.h>
#include <string>

class portSim{
      private:
      std::vector<int> priority;
        int max;
      public:
        void fillpriority(int count){
             int i;
             time_t seconds;
             time(&seconds);
       srand((unsigned int) seconds);
             for (i = 0; i<counr; i++){
                 priority.push_back(rand() % 901 + 100)); /* Initially the days waiting is 0 for all ships */
             }
        }
        int getmax(){
            max = count / 5;
            if (count % 5 != 0){
               max = max + 1;
            }
            return max;
        }
        float getaverage(){
            return max/2;
        }
        void printOrder(int count){
             int i;
             int j;
             int min;
             int index;
             cout << "Order:";
             for (i = 0; i<count; i++;){
                 min = 0;
                 for(j=0; j<count; j++){
                    if (priority[j] > min){
                       index = j;
                       min = priority[j];
                    }
                 
                 }
                 priority[index] = -1;
                 cout << index << " ";
             }
             cout << endl;
        }      
};

void main(int argc, char* argv[]) {
     int count;
     count = stoi(argv[1]);
     portSim sim;
     sim.fillpriority(count);
     sim.printOrder(count);
     cout << "Min :" << "0" << endl;
     cout << "Max :" << sim.getmax(); << endl;
     cout << "Average:" << sim.getaverage(); << endl;

           
}