-
How to model a system?
Hello, everyone.
I have a question about how to use programming to model a system which contain time for mation or something like that.
To be more specific, the system is like Railway system、weather forecast system.
Basically, system change over time and may have some interaction function to customers.
I have very limited implementation skills.
I do know basic datastructures and knows how to build a library system which have simple functions like search, delete, add, and borrow ... etc.
Though I still have no idea if I want to add time information to modeling the library system. Like borrow the book depends on the time system have.
The question is what is the basic idea to model a system with "time" information?
Time infomation means the system change over time. <== It doesn't mean to equal to "real time" change, but the point is it changes..
Hopefully, with my poor English description. Someone might catch it..
-
Somewhere in your model, you have some abstract time, say
and a function to tick, say
Code:
void tick ( void ) {
now++;
}
In your library book object say, you may have
which you initialise with something like this when the book is borrowed;
Code:
book->returnBy = now + 7; // return within a week
So once a day, you call tick() to bump time along (if you're doing it in real-time), or at whatever rate you want if you just want to 'model' what would happen.
Also once a day, your 'overdue' function would do something like
Code:
if ( now > book->returnBy ) {
// OVERDUE!
}