5.15 END OF CHAPTER PROGRAMS

5.15.1 Timer application

We have studied keyword static earlier in this chapter. The class Timer gives us a nice opportunity to study static as well as non-static methods of a given class. In many programs, we would like to measure the time taken by the critical code. Well someone will suggest a stopwatch. Can we implement the stopwatch in our program? By all means! What is a stopwatch anyway? It measures elapsed time between two events start and stop. C++ provides us with a method time() in header file “time.h”. This method returns the time from a predefined reference to current time as a long integer. It can be effectively used to measure the elapsed time.

Problem: Write a program to illustrate static methods start, ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.