comp.lang.ada
 help / color / mirror / Atom feed
* Stopwatch project
@ 1999-04-24  0:00 Brian A Crawford
  1999-04-25  0:00 ` Matthew Heaney
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Brian A Crawford @ 1999-04-24  0:00 UTC (permalink / raw)


I am a beginner attempting to teach myself from a number of Ada books and
lurking on this newsgroup.
I am trying to write a programme that will make the computer act as a
stopwatch with lap/split time capabilities.
I propose to start the programme running then use a get_immediate e.g. 'S'
for start then a number of
get_immediates e.g. 'L'  for each lap then get 'T' for stop and 'R' for
reset.
I find very little in the way of detailed examples in the books I have; in
fact very few mention get_immediate or real time programming; I have also
seen the amount of discussion on get_immediate in this newsgroup and realise
that neither topic is beginner level.
Are there any working examples of this concept on-line?

I have found on page 914-915 of 'Ada as a Second Language'  a package called
Stopwatch but find no example on how to use it (and the fact that it is on
page 914 is not lost on a beginner :-) ).

Any help would be extremely greatly appreciated.
Thanks
Brian
brianc@billybob.demon.co.uk

This is the programme taken from the book
----------------------------------------------------------------------------
---------------------------------------------------------
   PACKAGE stopwatch IS
      PROCEDURE reset;
      PROCEDURE start;
      PROCEDURE stop ;
      FUNCTION total_time RETURN duration;
      started_error : EXCEPTION;
   END stopwatch;

   WITH ada.Calender; USE ada.calendar;
   PACKAGE BODY stopwatch IS
      no_time: CONSTANT time := time_of (year => 1901, month => 1, day => 1,
seconds => 0.0 );
      time_started : time := no_time;
      total : duration := 0.0;

      PROCEDURE reset  IS

      BEGIN
         time_started := no_time;
         total := 0.0;

      END reset;

      PROCEDURE start IS

      BEGIN
         IF time_started = no_time THEN
            time_started :=  clock;
         ELSE RAISE started_error;
         END IF;
      END start;
      PROCEDURE stop IS

      BEGIN
         IF time_started =no_time THEN
            RAISE started_error;
         ELSE
            total := total + (clock - time_started);
            time_started := no_time;
         END IF;
      END stop;

      FUNCTION total_time RETURN duration IS
      BEGIN
         IF time_started = no_time THEN
            RETURN total;
         ELSE
            RAISE started_error;
         END IF ;
      END total_time;
   END stopwatch;

----------------------------------------------------------------------------
------------------------------------------------------------






^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-04-26  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-24  0:00 Stopwatch project Brian A Crawford
1999-04-25  0:00 ` Matthew Heaney
1999-04-25  0:00 ` Matthew Heaney
1999-04-26  0:00 ` Jeffrey D. Cherry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox