How to resolve the algorithm Nautical bell step by step in the Seed7 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Nautical bell step by step in the Seed7 programming language

Table of Contents

Problem Statement

Write a small program that emulates a nautical bell producing a ringing bell pattern at certain times throughout the day. The bell timing should be in accordance with Greenwich Mean Time, unless locale dictates otherwise. It is permissible for the program to daemonize, or to slave off a scheduler, and it is permissible to use alternative notification methods (such as producing a written notice "Two Bells Gone"), if these are more usual for the system type.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Nautical bell step by step in the Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";
  include "time.s7i";
  include "duration.s7i";
  include "keybd.s7i";

const array string: watch is [] ("Middle", "Morning", "Forenoon", "Afternoon", "Dog", "First");
const array string: bells is [] ("One Bell", "Two Bells", "Three Bells", "Four Bells", "Five Bells", "Six Bells", "Seven Bells", "Eight Bells");

const func time: truncToHalfHour (in time: aTime) is func
  result
    var time: truncatedTime is time.value;
  begin
    truncatedTime := aTime;
    truncatedTime.minute := aTime.minute div 30 * 30;
    truncatedTime.second := 0;
    truncatedTime.micro_second := 0;
  end func;

const proc: main is func
  local
    var time: nextTime is time.value;
    var time: midnight is time.value;
    var integer: minutes is 0;
  begin
    writeln;
    nextTime := truncToHalfHour(time(NOW));
    midnight := truncToDay(nextTime);
    while TRUE do
      nextTime +:= 30 . MINUTES;
      await(nextTime);
      minutes := toMinutes(nextTime - midnight);
      writeln(str_hh_mm(nextTime, ":") <& " - " <&
              watch[succ((minutes - 30) mdiv 240 mod 6)] <& " watch - " <&
              bells[succ((minutes - 30) mdiv 30 mod 8)] <& " Gone.");
      flush(OUT);
    end while;
  end func;

  

You may also check:How to resolve the algorithm Check that file exists step by step in the Gambas programming language
You may also check:How to resolve the algorithm String length step by step in the Dyalect programming language
You may also check:How to resolve the algorithm Function definition step by step in the C# programming language
You may also check:How to resolve the algorithm Tree from nesting levels step by step in the Java programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Haskell programming language