How to resolve the algorithm Compound data type step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Compound data type step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

Create a compound data type:

A compound data type is one that holds multiple independent values.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Compound data type step by step in the ALGOL 68 programming language

Source code in the algol programming language

MODE UNIONX = UNION(
   STRUCT(REAL r, INT i),
   INT,
   REAL,
   STRUCT(INT ii),
   STRUCT(REAL rr),
   STRUCT([]REAL r)
);

UNIONX data := 6.6;
CASE data IN
   (INT i): printf(($"r: "gl$,i)),
   (REAL r): printf(($"r: "gl$,r)),
   (STRUCT(REAL r, INT i) s): printf(($"r&i: "2(g)l$,s)),
   (STRUCT([]REAL r) s): printf(($"r: "n(UPB r OF s)(g)l$,s))
OUT
  printf($"Other cases"l$)
ESAC;

MODE POINT = STRUCT(
   INT x,
   INT y
);

MODE PERSON = STRUCT(
   STRING name,
   REAL age,
   REAL weight,
   UNION (
      STRUCT (REAL beard length),
      VOID
   ) gender details
);

  

You may also check:How to resolve the algorithm Numbers with equal rises and falls step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Integer overflow step by step in the Raku programming language
You may also check:How to resolve the algorithm Stair-climbing puzzle step by step in the Clojure programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the Java programming language
You may also check:How to resolve the algorithm Tree from nesting levels step by step in the Julia programming language