From 854107447af5e53276c0d5036e046c37ccf76580 Mon Sep 17 00:00:00 2001 From: danielvici123 <94993276+danielvici@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:22:08 +0100 Subject: [PATCH] mitschrieb progp 25-1-8 --- progp/25-1-25 -- Vorbereitung KA2/ka2.php | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 progp/25-1-25 -- Vorbereitung KA2/ka2.php diff --git a/progp/25-1-25 -- Vorbereitung KA2/ka2.php b/progp/25-1-25 -- Vorbereitung KA2/ka2.php new file mode 100644 index 0000000..a4b8c07 --- /dev/null +++ b/progp/25-1-25 -- Vorbereitung KA2/ka2.php @@ -0,0 +1,75 @@ + + IN KA 1 AUFGABE +echo "

Portokosten

"; + +function holePortokosten(float $gewicht):int { + $porto = 0.0; + if ($gewicht > 0.0 && $gewicht < 1.0){ + $porto = 150; + } elseif ($gewicht >= 1.0 && $gewicht < 5.0){ + $porto = 540; + } elseif ($gewicht >= 5.0 && $gewicht <= 25.0){ + $porto = 1290; + } else { + $porto = -1; + } return $porto; +} + +// ######## +// # TEST # +// ######## + +$gewicht = 1000; +$gewicht_f = number_format($gewicht, 2, ",", "."); +$porto = holePortokosten($gewicht); + +if ($porto == -1){ + echo "

Das Gewicht $gewicht ist nicht zulässig. Es ist zu Schwer

"; +} else { + $porto_euro = $porto / 100; + $porto_euro_f = number_format($porto_euro, 2, ",", "."); + echo "

Ihr Paket mit $gewicht kg kostet $porto_euro_f

"; +} + + + +// SG 2 +echo "

Quersumme

"; +// 37652 => Quersumme = 3+7+6+5+2 = 23 +// UML. berechneQuersumme(zahl: int): int +$qr_zahl = 37652; + +echo "

Zahl: $qr_zahl

"; + +function berechneQuersumme(int $zahl):int { + $quersumme = 0; + while ($zahl > 0){ + $quersumme += $zahl % 10; + $zahl = intdiv($zahl, 10); + } + return $quersumme; +} + +echo "Berechnete Quersumme: " + berechneQuersumme($qr_zahl); +?> \ No newline at end of file