this is my assignment question.
You must implement a simulation program to model air traffic among a collection of airports, as discussed in class. There are two important extensions that will be made to the model. First, in addition to arriving aircraft using the runway, departing aircraft must also use the same runway. If both arriving and departing aircraft are waiting to use the runway, it should be allocated to the aircraft that has been waiting the longest amount of time. Assume the amount of time a departing aircraft uses the runway follows the same distribution as an arriving aircraft. You should develop the appropriate queueing model abstraction for this system, and implement in with a simulation program.
Second, you will implement a network of airports rather than a single airport. Specifics of this system are described below.
1 Aircraft Behavior
The simulation contains N aircraft that are initially uniformly distributed among the airports. The number of aircraft does not change throughout the simulation. When the simulation starts each aircraft should schedule an initial departure event for itself with time selected from an exponential distribution with mean of 1 hour. Whenever a plane takes off it flies to a randomly selected airport from the possible destinations for the airport it is leaving, specified in the traffic network topology, as discussed below. An aircraft is equally likely to select any of the possible destinations. Run the simulation for 24 hours.
The amount of time to fly to a destination airport is uniformly distributed between 1.0 and 2.0 hours. Upon arrival, the plane must wait until the runway at the destination airport is free. Assume that once the plane has been cleared to land, it requires exclusive use of the runway for 2 minutes. Assume the amount of time spent on the ground is uniformly distributed between 0.75 and 1.5 hours.
Your simulator should compute the following statistics for each airport: (1) number of aircraft that landed during the simulation, (2) number of aircraft that departed during the simulation, and (3) average amount of time an aircraft had to wait for that airport’s runway when it arrived.
2 Air Traffic Network
The traffic network is specified as a graph, with nodes representing airports, and links representing possible flights. If aircraft can fly from airport i to airport j, then there is a link from node i to node j in the graph. A file input by your program specifies the network topology. The format for this file is a list of lines, one per nodes. Nodes are numbered 0, 1, … Each line lists (1) an airport number, and (2) a list of possible destination nodes for aircraft departing from that airport. For example, the file:
0 1 2
1 0
2 0

indicates aircraft departing from airport 0 may be destined for airport 1 or airport 2, and all aircraft departing from airport 1 and airport 2 always fly to airport 0. You may assume there are up to MAX_NODES airports in the simulation, and MAX_DESTINATIONS possible destinations (outgoing links) of any airport. MAX_NODES and MAX_DESTINATIONS should be defined as constants in your program.
3 Implementation
You will need to implement two parts:
• A simulation engine. This should include the pending event set implementation and a random number generator. The pending event set must be implemented using dynamic memory allocation (malloc and free). You are free to choose the random number generator and priority queue you wish to use, but you must implement these from scratch (as opposed to using a canned library). You will need to define and document and application programmer’s interface (API) that is used to develop the simulation model.
• A simulation model and graph generator. The graph generator is a program, completely independent of the simulator, that creates files of the specified format according to certain parameters that you specify (e.g., number of nodes, average node degree). The simulation model program must then read this file, create a network of the specified topology, and simulate the aircraft.
Assume simulation time is implemented as a double precision floating point number.

This is what I've done.But I was wondering am I on the right track.
I'm quites lost now.
And can we use random exponent?
I got problem in displayrunwaystatus,in fact the part where the exponent function is suppose to be random exponent.

#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;
int *airplanes = NULL;
int size;
int flight_no[12];
string dest[20];
float dtime[10]; //departure time
float atime[10]; // arrival time
float ltime[10]; //landing time
int a;

float air;
float ground;
void menu(void)
{
     cout <<"Airport Menu Options " <<endl;
     cout <<endl;
     cout <<"1 = Enter Flight Information" <<endl;
     cout <<"2 = Display Flight Information" <<endl;
     cout <<"3 = Display Runway Status" <<endl;
     cout <<endl;
     cout <<"0 = quit" <<endl;
     cout <<endl;
}

void flightinformation(void)
{
    
    cout <<"How many Flight Information you would like to key in : "<<endl;
    cin >> size;
    airplanes = new int[size];
    for(a = 0; a < size; a++)
     {
       cout <<"Enter Flight information for " << airplanes[a] <<endl;
       cout <<endl;
       cout <<"Flight Number ";
       cin  >>flight_no[a];
       cout <<"Destination ";
       cin  >>dest[a];
       cout <<"Departure Time (in 24 Hours Mode) ";
       cin  >>dtime[a];
       if(dtime[a]<0000 || dtime[a] >2400)
       {
       cout << "Error!"<<endl;
       }
       cout <<"Arrival Time(in 24 Hours Mode) ";
       cin  >>atime[a];
       if(atime[a]<0000 || atime[a] >2400)
       {
            cout << "Error!"<<endl;
       }
       cout <<endl;
       }
     delete []airplanes;      
}
void displayflightinfo(void)
{
     cout <<"         " <<left;
     cout << setw(15) <<"Flight Number | "<<setw(13) <<"Destination | " <<setw(16)
     <<"Departure Time | " <<"Arrival Time" <<endl;
     cout <<endl;
     for(int b = 0; b < size; b++)
     {
             cout <<left;
             cout <<airplanes[b] <<"  " <<setw(15) <<flight_no[b] <<" " <<setw(13) <<dest[b]
             <<" " <<setw(16) <<dtime[b] <<" " <<atime[b];
             cout <<endl;
     }
                         
system("pause");
}

void displayrunwaystatus(void)
{
     cout <<"Enter a Plane number to check its status" <<endl;
     int j;
     cout <<"Plane ";
     cin  >>j;
     for(int i=1;i >= atime[j];i++)
     {
             air = air + 1;
             ltime[j] = atime[j] + (exp(1.5));
             cout << "Landing Time : " << ltime[j] <<endl;
             if(i==ltime[j])
             {
                   cout << "Runway is occupied" << endl;
                
             }
          
     if(i>=ltime[j])
     {
                    air = air - 1;
                    ground = ground + 1;
                    if(air > 0)
                    {
                           ltime[j] = i + exp(1.5);
                    }
                    else
                    cout << "Runway is free" <<endl;
                    ltime[j] = atime[j] + exp(1.5);  
     } 
     }
system("pause");
}

int main()
{
                           
    int a;  
    do
    {
        cout <<endl;
        menu();
        cin >> a;
        cout <<endl;
     
     
                         
                     switch(a)
                     {
                                      case 1: flightinformation();
                                      break;
                                      case 2: displayflightinfo();
                                      break;
                                      case 3: displayrunwaystatus();
                                      break;
                                      
                     
                                     
                     }
    }while (a!= 0);       
return 0;
}

1) departure time, arrival time and landing time should be integers, not floats since they should be entered in YYYMMDDHHMM format. Just entering HHMM is not much value because they could span two or more days, especially if the airplain crosses the international date line.

2) you need to create a structure to hold the information for one person, then have an array of those structures because its easier to keep all the info for one person together. Using separate arrays for each of the times is not a good way to do that because it can become cumbersome and difficult to keep the arrays in sync.

Don't waste the time for writing random pieces of codes. You have rather serious task, start from the Project Plan.

You must study some theoretical issues before to start your program design. Search INET for random number generation theory and basics of statistical simulation. Wikipedia is a good start point for your studies.

It's absolutely uninteresting thing to ask your system about any runway or airplane status. The main goal of any statistical simulation program is to produce then save for future analysis all required statistics (see your project specifications). So don't rack your brains over simulation menu switches and displablabla family functions. You need two different programs (airline network file generator and simulation engine) with minimal interactiveness.

It seems you have too restrictive requirement:

You are free to choose the random number generator and priority queue you wish to use, but you must implement these from scratch (as opposed to using a canned library).

Really good random number generator implementation "from the scratch" is more compicated task than all the rest of your project. In practice all serious people in simulation world use professional-made generators (such as famous MersennTwister implementation). I think, you may extract some codes from the public domain implementations (search INET again). Good uniform distributed pseudorandom numbers generator is the key point of any sucsessful statistical simulation package. It's so easy to get exponentially (or what else) distributed random numbers from uniform random stream. No ready to use functions in C (and C++) standard library.

Fortunately, it's possible to split your project on relatively independent parts and move them forward little by little and continuosly. Please, don't implement this project as a monoblock warhead, don't write any codes until you understand what do you want to do.

Don't invent wheels, start from minimal theory basics of the problem area...

Good luck!

commented: very nice comments :) +34

Apropos: is it a C++ or C project? Why malloc and free in specifications?

Wow! After reading Ark's comments you can scrap the comments I made because they are next to useless in your program.

Oh, it's a very interesting educational (it looks like a trial;)) project.
Let's remeber: many years ago Bjarne The Great invented C++ for comfort simulator design and implementation...

Apropos: is it a C++ or C project? Why malloc and free in specifications?

we can choose either C or C++.
omg...
I'm confused now.
I can understand the algorithm for the project.
But I don't really know how to implement them in the program.

Algorithms + Data Structures = Programs, said N.Wirth many years ago (read the book of the same name when an opportunity offers).

Implement the project as usually: start then do it step by step.

Download and study this article (An Introduction to Object-Oriented Simulation in C++, PDF, 146Kb):
http://www.informs-cs.org/wsc97papers/0078.PDF
It may be useful if you select C++ as your project implementation language.

Don't waste the time for writing random pieces of codes. You have rather serious task, start from the Project Plan.

You must study some theoretical issues before to start your program design. Search INET for random number generation theory and basics of statistical simulation. Wikipedia is a good start point for your studies.

It's absolutely uninteresting thing to ask your system about any runway or airplane status. The main goal of any statistical simulation program is to produce then save for future analysis all required statistics (see your project specifications). So don't rack your brains over simulation menu switches and displablabla family functions. You need two different programs (airline network file generator and simulation engine) with minimal interactiveness.

It seems you have too restrictive requirement:

You are free to choose the random number generator and priority queue you wish to use, but you must implement these from scratch (as opposed to using a canned library).

Really good random number generator implementation "from the scratch" is more compicated task than all the rest of your project. In practice all serious people in simulation world use professional-made generators (such as famous MersennTwister implementation). I think, you may extract some codes from the public domain implementations (search INET again). Good uniform distributed pseudorandom numbers generator is the key point of any sucsessful statistical simulation package. It's so easy to get exponentially (or what else) distributed random numbers from uniform random stream. No ready to use functions in C (and C++) standard library.

Fortunately, it's possible to split your project on relatively independent parts and move them forward little by little and continuosly. Please, don't implement this project as a monoblock warhead, don't write any codes until you understand what do you want to do.

Don't invent wheels, start from minimal theory basics of the problem area...

Good luck!

I concur with ArkM. I personally think that the overall planning and structure of your program may need much changes. As a note, basically rand() is enough to generate random numbers; we don't have to understand to underlying implementation of rand() to use it. (Ito had clarified that it is fine enough to use rand().)

You are welcome!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.