| | |
Real-time simulation problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi everybody! I recently wrote a little simulation program, that simulates a real-time elevator system with 3 elevators. Since the code is around 530 lines I presume it is not a good idea to paste it here. There is some number of minor flaws of logical type and I would be very thankful on any ideas or corrections.
Since I don't posses any web space and I believe that corrections will be (probably) move obvious on a personal machine I can send the code to the email of anybody who's interested. I guarantee that no harmful programs will come with the email, in case somebody may think so.
If somebody is interested please answer to this post or send me a personal message with your email. If you have a better proposition than the email option that I can think of at the moment - please, of course, share it with me
Thanks to all in advance!
Since I don't posses any web space and I believe that corrections will be (probably) move obvious on a personal machine I can send the code to the email of anybody who's interested. I guarantee that no harmful programs will come with the email, in case somebody may think so.
If somebody is interested please answer to this post or send me a personal message with your email. If you have a better proposition than the email option that I can think of at the moment - please, of course, share it with me
Thanks to all in advance!
liblifts.h is the dirty worker in this case so this is the place. I presume that the Elevator class is the primary and probably almost only source of errors. The open_doors() function and the move() function are probably most critical. If I must be sincere - I don't have an exact idea what's wrong .. if I did have one I would try to correct the code myself.
I bet you know what I'm gonna say don't you.
Let me guess, you wrote the whole program in one go, and then hit compile and execute and expected it to work?
My advice would be to test each function or in your case, each method, separately and make sure it's doing what it is supposed to. Once you've gone through each method systematically you should be able to find out what's going wrong and where.
It's the only way.
Another thing, I noticed, it appears you're not freeing up your memory.
Where's your use of delete[].
And you really need to work on your indentation. It's horrendous. I also hate the use of try catch statements in c++, but that's just me.
Let me guess, you wrote the whole program in one go, and then hit compile and execute and expected it to work?
My advice would be to test each function or in your case, each method, separately and make sure it's doing what it is supposed to. Once you've gone through each method systematically you should be able to find out what's going wrong and where.
It's the only way.
Another thing, I noticed, it appears you're not freeing up your memory.
Where's your use of delete[].
And you really need to work on your indentation. It's horrendous. I also hate the use of try catch statements in c++, but that's just me.
*Voted best profile in the world*
Generally you're right about the testing. I can't think of a way, though, to check every function, especially when one function often uses the other from the same class and executable code is produced only when all the used functions are written down. Once the whole picture is clear I can start tracking down the problems.
As for delete[] - this belongs to the last actions I have to do. My primary concern at the moment is that the code starts running as it is supposed to do :-) Optimization belongs to the last stage before giving up the ready code and will be done, I can assure you.
As for delete[] - this belongs to the last actions I have to do. My primary concern at the moment is that the code starts running as it is supposed to do :-) Optimization belongs to the last stage before giving up the ready code and will be done, I can assure you.
freemind: You know that you're not supposed to put function bodies or variable definitions in a header, right? (Well, now you do.)
I may actually help more later on, but there are many things that make this code difficult to look at and understand. So I'm taking my time.
I may actually help more later on, but there are many things that make this code difficult to look at and understand. So I'm taking my time.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Other Threads in the C++ Forum
- Previous Thread: Dynamic Array and Pointer
- Next Thread: I/O question. using vc++ read char by char
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






