From b558787bf67e44677ca767b476e744e3a4464d11 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Mon, 16 Sep 2019 08:59:50 -0700 Subject: [PATCH] Add two examples from ch2. --- prada2012/ch02/print_roots.adb | 26 ++++++++++++++++++++++++++ prada2012/ch02/print_roots2.adb | 23 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 prada2012/ch02/print_roots.adb create mode 100644 prada2012/ch02/print_roots2.adb diff --git a/prada2012/ch02/print_roots.adb b/prada2012/ch02/print_roots.adb new file mode 100644 index 0000000..d3d1b14 --- /dev/null +++ b/prada2012/ch02/print_roots.adb @@ -0,0 +1,26 @@ +with Ada.Text_IO; +with Ada.Float_Text_IO; +with Ada.Numerics.Generic_Elementary_Functions; + +procedure Print_Roots is + use Ada.Text_IO; + use Ada.Float_Text_IO; + package Numerics is new Ada.Numerics.Generic_Elementary_Functions(Float); + use Numerics; + X: Float; +begin + Put_Line("Roots of various numbers"); + New_Line(1); + + loop + Get(X); + exit when X = 0.0; + Put("Root of "); Put(X); Put(" is "); + if X < 0.0 then + Put("not calculable."); + else + Put(Sqrt(X)); + end if; + New_Line; + end loop; +end Print_Roots; diff --git a/prada2012/ch02/print_roots2.adb b/prada2012/ch02/print_roots2.adb new file mode 100644 index 0000000..e47ed1c --- /dev/null +++ b/prada2012/ch02/print_roots2.adb @@ -0,0 +1,23 @@ +-- print_roots2 demonstrates runtime exceptions. +with Ada.Text_IO; +with Ada.Float_Text_IO; +with Ada.Numerics.Generic_Elementary_Functions; + +procedure Print_Roots is + use Ada.Text_IO; + use Ada.Float_Text_IO; + package Numerics is new Ada.Numerics.Generic_Elementary_Functions(Float); + use Numerics; + X: Float; +begin + Put_Line("Roots of various numbers"); + New_Line(1); + + loop + Get(X); + exit when X = 0.0; + Put("Root of "); Put(X); Put(" is "); + Put(Sqrt(X)); + New_Line; + end loop; +end Print_Roots;