How to resolve the algorithm Enumerations step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Enumerations step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

Create an enumeration of constants with and without explicit values.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Enumerations step by step in the ALGOL 68 programming language

Source code in the algol programming language

BEGIN # example 1 #
  MODE FRUIT = INT;
  FRUIT apple = 1, banana = 2, cherry = 4;
  FRUIT x := cherry;
  CASE x IN
    print(("It is an apple #",x, new line)),
    print(("It is a banana #",x, new line)),
    SKIP, # 3 not defined #
    print(("It is a cherry #",x, new line))
  OUT
    SKIP # other values #
  ESAC
END;

BEGIN # example 2 #
  MODE ENUM = [0]CHAR; # something with minimal size #
  MODE APPLE = STRUCT(ENUM apple), BANANA = STRUCT(ENUM banana), CHERRY = STRUCT(ENUM cherry);
  MODE FRUIT = UNION(APPLE, BANANA, CHERRY);

  OP REPR = (FRUIT f)STRING:
    CASE f IN
      (APPLE):"Apple",
      (BANANA):"Banana",
      (CHERRY):"Cherry"
    OUT
      "?" # uninitalised #
    ESAC;

  FRUIT x := LOC CHERRY;

  CASE x IN
    (APPLE):print(("It is an ",REPR x, new line)),
    (BANANA):print(("It is a ",REPR x, new line)),
    (CHERRY):print(("It is a ",REPR x, new line))
  OUT
    SKIP # uninitialised FRUIT #
  ESAC
END

  

You may also check:How to resolve the algorithm Sleep step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Anagrams step by step in the BQN programming language
You may also check:How to resolve the algorithm Read a specific line from a file step by step in the Ruby programming language
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Flow-control structures step by step in the BASIC256 programming language