Help with time simulation assignment

This is a discussion on Help with time simulation assignment within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I have a question reagarding a simulation assignment I was given in my C++ class. The idea is ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    49

    Help with time simulation assignment

    Hey guys,

    I have a question reagarding a simulation assignment I was given in my C++ class. The idea is to simulate a array based queue of planes waiting to land on a runway. The inputs are...

    1 lenght of simulation (hour:minutes)
    2 average time between addition of planes to queue
    3 time it takes to land a plane (i.e. the speed at which planes can be removed from the queue)

    My problem is how to simulate time. The best I can come up with is to reduce the lenght of the simulation to total time in minutes and then run a for or do/while loop that cycles for that many minutes. That way I can consisly control what it happening at each minute. I was thinking something like this...

    Code:
    for( int c = 0; c < SimulationTimeInMinutes; c++){
    	
    	function to add plane(if conditions are correct)
    	function to remove plane(if conditions are correct)
    
    }


    Is there a better way to simulate time than using loops? Thanks

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    197
    Loops might be a good way to do it. I can't really think of an alternative. You might try something like this

    Code:
    Clock = 0; 
    
    while( Clock < AmountOfTimeToBeSimulated_InSeconds)
    {
    	
    	function to add plane(if conditions are correct);
    	function to remove plane(if conditions are correct);
    	
    	Clock += timeIncrement;
    
    }
    Last edited by thetinman; 10-31-2006 at 10:09 AM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    Looks pretty good to me

    You only need to start messing about with say clock() or other time measurements if you want a real-time simulation.

    If you just want a simulation to run "as fast as possible", then do what you've done already, and just use a loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    49
    Thanks guys, I guess I'm on the right track (especially since the God of the C agrees with me)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 08:51 PM
  2. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  3. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 11:42 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21