From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,eb6461ca23607ed4,start X-Google-Attributes: gid103376,public From: "Brian A Crawford" Subject: Stopwatch project Date: 1999/04/24 Message-ID: <924946678.23882.0.nnrp-04.c2de4c02@news.demon.co.uk>#1/1 X-Deja-AN: 470303474 X-NNTP-Posting-Host: billybob.demon.co.uk:194.222.76.2 X-Trace: news.demon.co.uk 924946678 nnrp-04:23882 NO-IDENT billybob.demon.co.uk:194.222.76.2 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Newsgroups: comp.lang.ada X-Complaints-To: abuse@demon.net Date: 1999-04-24T00:00:00+00:00 List-Id: 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; ---------------------------------------------------------------------------- ------------------------------------------------------------