comp.lang.ada
 help / color / mirror / Atom feed
From: "Brian A Crawford" <brianc@billybob.demon.co.uk>
Subject: Stopwatch project
Date: 1999/04/24
Date: 1999-04-24T00:00:00+00:00	[thread overview]
Message-ID: <924946678.23882.0.nnrp-04.c2de4c02@news.demon.co.uk> (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;

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






             reply	other threads:[~1999-04-24  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-24  0:00 Brian A Crawford [this message]
1999-04-25  0:00 ` Stopwatch project Matthew Heaney
1999-04-25  0:00 ` Matthew Heaney
1999-04-26  0:00 ` Jeffrey D. Cherry
replies disabled

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