From 1a9fd265263b5c150617e4995f0f8b3aaf6940bb Mon Sep 17 00:00:00 2001 From: Artem-Darius Weber Date: Thu, 17 Apr 2025 13:31:25 +0300 Subject: [PATCH] (lab 5) feat: add Circle and Cylinder calculations --- .../CircleAndCylinder.fsproj | 12 ++++++ lab 5/CircleAndCylinder/Program.fs | 42 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 lab 5/CircleAndCylinder/CircleAndCylinder.fsproj create mode 100755 lab 5/CircleAndCylinder/Program.fs diff --git a/lab 5/CircleAndCylinder/CircleAndCylinder.fsproj b/lab 5/CircleAndCylinder/CircleAndCylinder.fsproj new file mode 100755 index 0000000..299cf40 --- /dev/null +++ b/lab 5/CircleAndCylinder/CircleAndCylinder.fsproj @@ -0,0 +1,12 @@ + + + + Exe + net7.0 + + + + + + + diff --git a/lab 5/CircleAndCylinder/Program.fs b/lab 5/CircleAndCylinder/Program.fs new file mode 100755 index 0000000..e45b2ab --- /dev/null +++ b/lab 5/CircleAndCylinder/Program.fs @@ -0,0 +1,42 @@ +// For more information see https://aka.ms/fsharp-console-apps +printfn "Hello from F#" + +// Функция для вычисления площади круга +let circleArea radius = System.Math.PI * radius * radius + +// Функция для вычисления объема цилиндра через суперпозицию +let cylinderVolume radius height = + circleArea radius * height + +// Функция для вычисления объема цилиндра через каррирование +let cylinderVolumeCurried radius = + fun height -> circleArea radius * height + +// Функция для чтения числа с консоли +let readFloat() = + System.Console.ReadLine() + |> System.Double.Parse + |> float + +// Основная функция +[] +let main argv = + System.Console.WriteLine("Введите радиус круга:") + let radius = readFloat() + + System.Console.WriteLine("Введите высоту цилиндра:") + let height = readFloat() + + // Вычисление через суперпозицию + let volume1 = cylinderVolume radius height + System.Console.WriteLine($"Объем цилиндра (через суперпозицию): {volume1:F2}") + + // Вычисление через каррирование + let volume2 = (cylinderVolumeCurried radius) height + System.Console.WriteLine($"Объем цилиндра (через каррирование): {volume2:F2}") + + // Демонстрация частичного применения + let area = circleArea radius + System.Console.WriteLine($"Площадь круга: {area:F2}") + + 0