views:

56

answers:

3

hi, i am writing a simulation about vehicle manufacturing, i am wondering how i can create objects based on time..

i have a base class Vehicle, and children Motorbike, Car, and Truck. 1 Motorbike will be manufactured every 1 hour, 1 car will be manufactured every 3 hours, and 1 truck will be manufactured every 8 hours.

how can i create those objects according to the time indicated?

thanks

+1  A: 

One possibility is to have a thread dedicated to each task, that just sits in a loop of lather, rinse,create, sleep, repeat.

Jerry Coffin
+1  A: 

You can create timers and wait on those timer events. When the timer expires you can create corresponding object. You can monitor this in a thread.

When will you be destroying these objects?

ckv
the manufactured vehicle will go to some processes then they will be destroyed
chandra wib
A: 

If you want to have complete control over the timing (say, you can increment the time irrespective of the system timer), then you'll need to implement that as a class. Then provide a Singleton or static function to return the Current time. The time class should be copyable so that objects can remember the starting time. Also, provide a function for advancing time by a certain amount, and for doing time comparisons.

Inside each manufacturable object (or better, the factories that manufacture them), add two functions:

  1. StartManufacture. This function should remember the starting time.
  2. CheckManufactureComplete. This function fetches the current time, and checks if the required waiting time has elapsed since manufacturing started.
rwong