Sunday, July 12, 2009

Programming C++?

Programming C++?


programming: Who can write a program in C++ which shows how a timer works!and designs the graphic of it!(with class and functions)

Programming C++?
check out http://www.pscode.com for great sample codes.
Reply:Exact answer of your question would be - anybody who knows programming in C++ can write a program which shows how a timer ....!





Well being one of that set, I can explain you how to do that, if that is the intention of your question here.





(1) Create a class Timer


(2) Create private data members to hold Hour, Minute, Seconds and Milliseconds


(3) Create a 'default' constructor and intialize all variable to zero (hour = min = sec = ms = 0)


(4) Create a method - displayTime() - and write code to display - time in 'hh : mm : ss : ms' format (Hint: concatenate and display using graphics function - use outtextxy() method - to always clear and output at same location)


(5) Creat a method - Start() - this will contain logic of running a timer. If you are using just for demonstration purpose, as you have mentioned -how timer works, you can use a simple loop to increment milliseconds in each loop execution. Increation second every 10 millisecond (and reset ms=0), increment minute every 60 sec (and reset sec=0) and similarly hour. Within this loop, call displayTime() method to show the timer (running) and in the same loop also put a way to stop like checking for a keyinput or something like that.


(6) in Main.. create an instance of this timer class and call Start() method to run the timer.





This is a simple timer. You may want to create another Constructor that accepts values for hour,min,sec,ms and starts from there. An advanced version may have more features like - countdown (reverse timer - take a value and keep on decreasing instead of incrementing); you can also create a timer mapped to System Time (using getTime() in loop). A well created Timer will be a Multithreaded application and may also allow you to suspend/resume timer anytime.





I hope this is what you are looking for. If you need more specific solution, please be specific in your question.





If you are looking for a ready to use code, I won't give you that, but you can refer to http://www.sourcecodesworld.com/source/s... for some more clue.
Reply:I can, In fact I was paid to write something like that - but I am not doing your homework

periwinkle

No comments:

Post a Comment