{
  "format": "tokbit",
  "version": 1,
  "name": "Geometry with a cuboid",
  "main": [
    {
      "id": "u15",
      "kind": "declare",
      "name": "option",
      "type": "str",
      "init": "\"\""
    },
    {
      "id": "u16",
      "kind": "declare",
      "name": "a",
      "type": "float"
    },
    {
      "id": "u17",
      "kind": "declare",
      "name": "b",
      "type": "float"
    },
    {
      "id": "u18",
      "kind": "declare",
      "name": "c",
      "type": "float"
    },
    {
      "id": "u19",
      "kind": "while",
      "condition": "option != \"6\"",
      "body": [
        {
          "id": "u20",
          "kind": "output",
          "values": "\"\""
        },
        {
          "id": "u21",
          "kind": "output",
          "values": "\"1 Rectangle\""
        },
        {
          "id": "u22",
          "kind": "output",
          "values": "\"2 Square\""
        },
        {
          "id": "u23",
          "kind": "output",
          "values": "\"3 Circle\""
        },
        {
          "id": "u24",
          "kind": "output",
          "values": "\"4 Right triangle\""
        },
        {
          "id": "u25",
          "kind": "output",
          "values": "\"5 Cuboid\""
        },
        {
          "id": "u26",
          "kind": "output",
          "values": "\"6 Quit\""
        },
        {
          "id": "u27",
          "kind": "input",
          "target": "option",
          "prompt": "Choice:"
        },
        {
          "id": "u28",
          "kind": "if",
          "condition": "option == \"1\"",
          "then": [
            {
              "id": "u29",
              "kind": "assign",
              "target": "a",
              "value": "read_size(\"Side a\")"
            },
            {
              "id": "u30",
              "kind": "assign",
              "target": "b",
              "value": "read_size(\"Side b\")"
            },
            {
              "id": "u31",
              "kind": "output",
              "values": "\"Perimeter:\", round(rect_perimeter(a, b), 2)"
            },
            {
              "id": "u32",
              "kind": "output",
              "values": "\"Area:\", round(rect_area(a, b), 2)"
            }
          ],
          "else": [
            {
              "id": "u33",
              "kind": "if",
              "condition": "option == \"2\"",
              "then": [
                {
                  "id": "u34",
                  "kind": "assign",
                  "target": "a",
                  "value": "read_size(\"Side\")",
                  "comment": "A square is a rectangle with equal sides: P = 4a, A = a²."
                },
                {
                  "id": "u35",
                  "kind": "output",
                  "values": "\"Perimeter:\", round(rect_perimeter(a, a), 2)"
                },
                {
                  "id": "u36",
                  "kind": "output",
                  "values": "\"Area:\", round(rect_area(a, a), 2)"
                }
              ],
              "else": [
                {
                  "id": "u37",
                  "kind": "if",
                  "condition": "option == \"3\"",
                  "then": [
                    {
                      "id": "u38",
                      "kind": "assign",
                      "target": "a",
                      "value": "read_size(\"Radius r\")"
                    },
                    {
                      "id": "u39",
                      "kind": "output",
                      "values": "\"Perimeter:\", round(circle_perimeter(a), 2)"
                    },
                    {
                      "id": "u40",
                      "kind": "output",
                      "values": "\"Area:\", round(circle_area(a), 2)"
                    }
                  ],
                  "else": [
                    {
                      "id": "u41",
                      "kind": "if",
                      "condition": "option == \"4\"",
                      "then": [
                        {
                          "id": "u42",
                          "kind": "assign",
                          "target": "a",
                          "value": "read_size(\"Leg a\")"
                        },
                        {
                          "id": "u43",
                          "kind": "assign",
                          "target": "b",
                          "value": "read_size(\"Leg b\")"
                        },
                        {
                          "id": "u44",
                          "kind": "assign",
                          "target": "c",
                          "value": "hypotenuse(a, b)",
                          "comment": "Triangle: P = a + b + c, A = a · b / 2."
                        },
                        {
                          "id": "u45",
                          "kind": "output",
                          "values": "\"Hypotenuse:\", round(c, 2)"
                        },
                        {
                          "id": "u46",
                          "kind": "output",
                          "values": "\"Perimeter:\", round(a + b + c, 2)"
                        },
                        {
                          "id": "u47",
                          "kind": "output",
                          "values": "\"Area:\", round(a * b / 2, 2)"
                        }
                      ],
                      "else": [
                        {
                          "id": "u48",
                          "kind": "if",
                          "condition": "option == \"5\"",
                          "then": [
                            {
                              "id": "u49",
                              "kind": "assign",
                              "target": "a",
                              "value": "read_size(\"Edge a\")"
                            },
                            {
                              "id": "u50",
                              "kind": "assign",
                              "target": "b",
                              "value": "read_size(\"Edge b\")"
                            },
                            {
                              "id": "u51",
                              "kind": "assign",
                              "target": "c",
                              "value": "read_size(\"Edge c\")"
                            },
                            {
                              "id": "u52",
                              "kind": "output",
                              "values": "\"Volume:\", round(cuboid_volume(a, b, c), 2)"
                            },
                            {
                              "id": "u53",
                              "kind": "output",
                              "values": "\"Surface:\", round(cuboid_surface(a, b, c), 2)"
                            }
                          ],
                          "else": [
                            {
                              "id": "u54",
                              "kind": "if",
                              "condition": "option != \"6\"",
                              "then": [
                                {
                                  "id": "u55",
                                  "kind": "output",
                                  "values": "\"Unknown choice.\""
                                }
                              ],
                              "else": []
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "comment": "The menu repeats until you choose 5."
    }
  ],
  "functions": [
    {
      "name": "read_size",
      "params": [
        {
          "name": "label",
          "type": "str"
        }
      ],
      "returnType": "float",
      "blocks": [
        {
          "id": "u1",
          "kind": "declare",
          "name": "x",
          "type": "float"
        },
        {
          "id": "u2",
          "kind": "doWhile",
          "body": [
            {
              "id": "u3",
              "kind": "output",
              "values": "label + \":\"",
              "newline": false
            },
            {
              "id": "u4",
              "kind": "input",
              "target": "x",
              "prompt": ""
            },
            {
              "id": "u5",
              "kind": "if",
              "condition": "x <= 0",
              "then": [
                {
                  "id": "u6",
                  "kind": "output",
                  "values": "\"The size must be greater than 0.\""
                }
              ],
              "else": []
            }
          ],
          "condition": "x <= 0"
        },
        {
          "id": "u7",
          "kind": "return",
          "value": "x"
        }
      ],
      "comment": "Prints the name of the size and reads until it is positive; returns it."
    },
    {
      "name": "rect_perimeter",
      "params": [
        {
          "name": "a",
          "type": "float"
        },
        {
          "name": "b",
          "type": "float"
        }
      ],
      "returnType": "float",
      "blocks": [
        {
          "id": "u8",
          "kind": "return",
          "value": "2 * (a + b)"
        }
      ],
      "comment": "P = 2 · (a + b)"
    },
    {
      "name": "rect_area",
      "params": [
        {
          "name": "a",
          "type": "float"
        },
        {
          "name": "b",
          "type": "float"
        }
      ],
      "returnType": "float",
      "blocks": [
        {
          "id": "u9",
          "kind": "return",
          "value": "a * b"
        }
      ],
      "comment": "A = a · b"
    },
    {
      "name": "circle_perimeter",
      "params": [
        {
          "name": "r",
          "type": "float"
        }
      ],
      "returnType": "float",
      "blocks": [
        {
          "id": "u10",
          "kind": "return",
          "value": "2 * pi * r"
        }
      ],
      "comment": "C = 2 · π · r"
    },
    {
      "name": "circle_area",
      "params": [
        {
          "name": "r",
          "type": "float"
        }
      ],
      "returnType": "float",
      "blocks": [
        {
          "id": "u11",
          "kind": "return",
          "value": "pi * r ** 2"
        }
      ],
      "comment": "A = π · r²"
    },
    {
      "name": "hypotenuse",
      "params": [
        {
          "name": "a",
          "type": "float"
        },
        {
          "name": "b",
          "type": "float"
        }
      ],
      "returnType": "float",
      "blocks": [
        {
          "id": "u12",
          "kind": "return",
          "value": "sqrt(a ** 2 + b ** 2)"
        }
      ],
      "comment": "c = √(a² + b²)"
    },
    {
      "name": "cuboid_volume",
      "params": [
        {
          "name": "a",
          "type": "float"
        },
        {
          "name": "b",
          "type": "float"
        },
        {
          "name": "c",
          "type": "float"
        }
      ],
      "returnType": "float",
      "blocks": [
        {
          "id": "u13",
          "kind": "return",
          "value": "a * b * c"
        }
      ],
      "comment": "V = a · b · c"
    },
    {
      "name": "cuboid_surface",
      "params": [
        {
          "name": "a",
          "type": "float"
        },
        {
          "name": "b",
          "type": "float"
        },
        {
          "name": "c",
          "type": "float"
        }
      ],
      "returnType": "float",
      "blocks": [
        {
          "id": "u14",
          "kind": "return",
          "value": "2 * (a * b + b * c + a * c)"
        }
      ],
      "comment": "S = 2 · (ab + bc + ac)"
    }
  ],
  "comment": "Solution to the task “Cuboid”: Add a Cuboid: from three edges compute the volume V = a · b · c and the surface S = 2 · (ab + bc + ac). Write two functions with a return value for it.",
  "screen": "fit"
}
