How to resolve the algorithm 99 bottles of beer step by step in the Ada programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm 99 bottles of beer step by step in the Ada programming language

Table of Contents

Problem Statement

Display the complete lyrics for the song:     99 Bottles of Beer on the Wall.

The lyrics follow this form: ... and so on, until reaching   0     (zero). Grammatical support for   1 bottle of beer   is optional. As with any puzzle, try to do it in as creative/concise/comical a way as possible (simple, obvious solutions allowed, too).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm 99 bottles of beer step by step in the Ada programming language

Source code in the ada programming language

with Ada.Text_Io; use Ada.Text_Io;
 
 procedure Bottles is
 begin
    for X in reverse 1..99 loop
       Put_Line(Integer'Image(X) & " bottles of beer on the wall");
       Put_Line(Integer'Image(X) & " bottles of beer");
       Put_Line("Take one down, pass it around");
       Put_Line(Integer'Image(X - 1) & " bottles of beer on the wall");
       New_Line;
    end loop;
 end Bottles;


with Ada.Text_Io; use Ada.Text_Io;

procedure Tasking_99_Bottles is
   subtype Num_Bottles is Natural range 1..99;
   task Print is
      entry Set (Num_Bottles);
   end Print;
   task body Print is
      Num : Natural;
   begin
      for I in reverse Num_Bottles'range loop
         select
         accept 
            Set(I) do -- Rendezvous with Counter task I
               Num := I;
            end Set;
            Put_Line(Integer'Image(Num) & " bottles of beer on the wall");
            Put_Line(Integer'Image(Num) & " bottles of beer");
            Put_Line("Take one down, pass it around");
            Put_Line(Integer'Image(Num - 1) & " bottles of beer on the wall");
            New_Line;
         or terminate; -- end when all Counter tasks have completed
         end select;
      end loop;
   end Print;
   task type Counter(I : Num_Bottles);
   task body Counter is
   begin
      Print.Set(I);
   end Counter;
   type Task_Access is access Counter;
   
   Task_List : array(Num_Bottles) of Task_Access;
 
begin
   for I in Task_List'range loop -- Create 99 Counter tasks
      Task_List(I) := new Counter(I);
   end loop;
end Tasking_99_Bottles;


  

You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the Red programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the PHP programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the Miranda programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Sidef programming language
You may also check:How to resolve the algorithm Pig the dice game step by step in the Chipmunk Basic programming language