From 0d747477010efd21c82baa8945cf82aabaaeeaff Mon Sep 17 00:00:00 2001
From: Jens Albrecht <jens.albrecht@th-nuernberg.de>
Date: Tue, 21 Jan 2025 14:24:07 +0100
Subject: [PATCH] .

---
 ColorArray/ColorArray.cs             | 39 ++++++++++++++
 ColorArray/ColorArray.csproj         | 10 ++++
 DateiHelgoland/DateiHelgoland.csproj | 10 ++++
 DateiHelgoland/Helgoland.cs          | 56 ++++++++++++++++++++
 Erasthostenes/Erasthostenes.cs       | 15 ++++++
 Erasthostenes/Erasthostenes.csproj   | 10 ++++
 ProduktVerkauf/ProduktVerkauf.cs     | 78 ++++++++++++++++++++++++++++
 ProduktVerkauf/ProduktVerkauf.csproj | 10 ++++
 Replace/Replace.cs                   | 23 ++++++++
 Replace/Replace.csproj               | 10 ++++
 Teilmenge/Teilmenge.cs               | 29 +++++++++++
 Teilmenge/Teilmenge.csproj           | 10 ++++
 Uebung13.sln                         | 55 ++++++++++++++++++++
 13 files changed, 355 insertions(+)
 create mode 100644 ColorArray/ColorArray.cs
 create mode 100644 ColorArray/ColorArray.csproj
 create mode 100644 DateiHelgoland/DateiHelgoland.csproj
 create mode 100644 DateiHelgoland/Helgoland.cs
 create mode 100644 Erasthostenes/Erasthostenes.cs
 create mode 100644 Erasthostenes/Erasthostenes.csproj
 create mode 100644 ProduktVerkauf/ProduktVerkauf.cs
 create mode 100644 ProduktVerkauf/ProduktVerkauf.csproj
 create mode 100644 Replace/Replace.cs
 create mode 100644 Replace/Replace.csproj
 create mode 100644 Teilmenge/Teilmenge.cs
 create mode 100644 Teilmenge/Teilmenge.csproj
 create mode 100644 Uebung13.sln

diff --git a/ColorArray/ColorArray.cs b/ColorArray/ColorArray.cs
new file mode 100644
index 0000000..fec9464
--- /dev/null
+++ b/ColorArray/ColorArray.cs
@@ -0,0 +1,39 @@
+// Erstellen Sie einen Aufzähltyp Color mit den Werten Red, Blue, Green.
+enum Color { Red, Blue, Green }
+
+class Program
+{
+    // Schreiben Sie eine Funktion ColorCount, die ein Color-Array sowie eine einzelne Farbe als Parameter bekommt
+    // und die Anzahl der Elemente mit der entsprechenden Farbe in dem Array zurückgibt.
+    static int ColorCount(Color[] colors, Color searchColor)
+    {
+        int num = 0;
+
+        foreach (Color c in colors)
+        {
+            if (c == searchColor)
+                num++;
+        }
+
+        return num;
+    }
+
+    static void Main()
+    {
+        // Erzeugen Sie ein Array vom Typ Color der Länge 10
+        Color[] colors = new Color[10];
+
+        // und initialisieren Sie es mit zufälligen Farb-Werten
+        Random rnd = new Random();
+
+        for (int i = 0; i < colors.Length; i++)
+        {
+            colors[i] = (Color)rnd.Next(3);
+            Console.WriteLine($"{i,3}: {colors[i]}");
+        }
+
+        // Testen Sie die Funktion mit dem erzeugten Array
+        Color color = Color.Blue;
+        Console.WriteLine($"{ColorCount(colors, Color.Blue)}x {color} gefunden");
+    }
+}
diff --git a/ColorArray/ColorArray.csproj b/ColorArray/ColorArray.csproj
new file mode 100644
index 0000000..206b89a
--- /dev/null
+++ b/ColorArray/ColorArray.csproj
@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>
diff --git a/DateiHelgoland/DateiHelgoland.csproj b/DateiHelgoland/DateiHelgoland.csproj
new file mode 100644
index 0000000..206b89a
--- /dev/null
+++ b/DateiHelgoland/DateiHelgoland.csproj
@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>
diff --git a/DateiHelgoland/Helgoland.cs b/DateiHelgoland/Helgoland.cs
new file mode 100644
index 0000000..062dd24
--- /dev/null
+++ b/DateiHelgoland/Helgoland.cs
@@ -0,0 +1,56 @@
+namespace Helgoland;
+
+using System.Globalization; // für CultureInfo
+
+// Das Programm ist so gestaltet, dass es auf deutschen/englischen Systemen
+// sowie auf Windows und Unix/MacOS läuft.
+
+class Program
+{
+    static void Niedrigwasser(string datum, out double hoehe, out string zeit)
+    {
+        // Stellt sicher, dass bei Convert.ToDouble ein Komma als Dezimalzeichen
+        // interpretiert wird (kein Klausurwissen)
+        CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("de-de");
+
+        hoehe = 0;
+        zeit = "";
+
+        // Path.Combine trennt Verzeichnisebenen unter Windows durch \
+        // und unter Unix durch / (kein Klausurwissen)
+        StreamReader sr = new StreamReader(Path.Combine("..","..","..","Helgoland.txt"));
+
+        while (!sr.EndOfStream)
+        {
+            string[] felder = sr.ReadLine()!.Split('\t');
+
+            // gesuchten Tag finden
+            if (felder[0] == datum)
+            {
+                // Min. Höhe und Zeit dazu bestimmen
+                hoehe = Convert.ToDouble(felder[2]);
+                for (int i = 2; i < felder.Length; i += 2)
+                {
+                    double aktHoehe = Convert.ToDouble(felder[i]);
+                    if (aktHoehe < hoehe)
+                    {
+                        hoehe = aktHoehe;
+                        zeit = felder[i - 1];
+                    }
+                }
+
+                return;
+            }
+        }
+    }
+
+    static void Main(string[] args)
+    {
+        double h;
+        string t;
+        string datum = "0707";
+
+        Niedrigwasser(datum, out h, out t);
+        Console.WriteLine($"Niedrigwasserhöhe an {datum} ist {h} um Zeit {t}");
+    }
+}
diff --git a/Erasthostenes/Erasthostenes.cs b/Erasthostenes/Erasthostenes.cs
new file mode 100644
index 0000000..d06fd29
--- /dev/null
+++ b/Erasthostenes/Erasthostenes.cs
@@ -0,0 +1,15 @@
+bool[] isPrime = new bool[1000];
+
+for (int i = 2; i < isPrime.Length; i++)
+    isPrime[i] = true;
+
+for (int i = 2; i < isPrime.Length; i++)
+{
+    if (isPrime[i])
+    {
+        Console.WriteLine($"{i} ist prim.");
+
+        for (int j = i+i; j < isPrime.Length; j+=i)
+            isPrime[j] = false;
+    }
+}
diff --git a/Erasthostenes/Erasthostenes.csproj b/Erasthostenes/Erasthostenes.csproj
new file mode 100644
index 0000000..206b89a
--- /dev/null
+++ b/Erasthostenes/Erasthostenes.csproj
@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>
diff --git a/ProduktVerkauf/ProduktVerkauf.cs b/ProduktVerkauf/ProduktVerkauf.cs
new file mode 100644
index 0000000..cf174c7
--- /dev/null
+++ b/ProduktVerkauf/ProduktVerkauf.cs
@@ -0,0 +1,78 @@
+class Produktverkauf
+{
+    static void VerkaufProArtikelAusgeben(int[,] v)
+    {
+        Console.WriteLine("Durchschnittlicher Verkauf für:");
+        for (int i = 0; i < v.GetLength(0); i++)
+        {
+            double summe = 0;
+            for (int j = 0; j < v.GetLength(1); j++)
+                summe += v[i, j];
+            Console.WriteLine($"- Artikel {i}: {summe / v.GetLength(1):f2}");
+        }
+    }
+
+    static void VerkaufProMonatAusgeben(int[,] v, int monat)
+    {
+        if (monat > v.GetLength(1) || monat <= 0)
+        {
+            Console.WriteLine("Ungültiger Monat!");
+            return;
+        }
+
+        double summe = 0;
+        for (int i = 0; i < v.GetLength(0); i++)
+            summe += v[i, monat - 1];
+        Console.Write($"Durchschnittlicher Verkauf für Monat {monat}: {summe / v.GetLength(0):f2}");
+    }
+
+    static void GesamtVerkaufAusgeben(int[,] v)
+    {
+        double summe = 0;
+        for (int i = 0; i < v.GetLength(0); i++)
+            for (int j = 0; j < v.GetLength(1); j++)
+                summe += v[i, j];
+        Console.WriteLine($"Insgesamt wurden {summe} Artikel verkauft.");
+    }
+
+    static void Main(string[] args)
+    {
+        int[,] verkauf = { { 3, 5, 6 },
+                           { 7, 8, 2 },
+                           { 4, 5, 3 },
+                           { 9, 7, 8 } };
+
+        string auswahl;
+        do
+        {
+            Console.WriteLine("\n\nHauptmenü\n");
+            Console.WriteLine("1) Durchschnittliche Verkaufszahl pro Artikel ausgeben");
+            Console.WriteLine("2) Durchschnittliche Verkaufszahl für einen Monat ausgeben");
+            Console.WriteLine("3) Summe aller verkauften Artikel ausgeben");
+            Console.WriteLine("4) Beenden");
+            Console.Write("Ihre Auswahl: ");
+
+            auswahl = Console.ReadLine()!;
+
+            switch (auswahl)
+            {
+                case "1":
+                    VerkaufProArtikelAusgeben(verkauf);
+                    break;
+                case "2":
+                    Console.Write("Welcher Monat? ");
+                    int monat = Convert.ToInt32(Console.ReadLine());
+                    VerkaufProMonatAusgeben(verkauf, monat);
+                    break;
+                case "3":
+                    GesamtVerkaufAusgeben(verkauf);
+                    break;
+                case "4":
+                    break;
+                default:
+                    Console.WriteLine("Ungültige Eingabe!");
+                    break;
+            }
+        } while (auswahl != "4");
+    }
+}
diff --git a/ProduktVerkauf/ProduktVerkauf.csproj b/ProduktVerkauf/ProduktVerkauf.csproj
new file mode 100644
index 0000000..206b89a
--- /dev/null
+++ b/ProduktVerkauf/ProduktVerkauf.csproj
@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>
diff --git a/Replace/Replace.cs b/Replace/Replace.cs
new file mode 100644
index 0000000..9abd44e
--- /dev/null
+++ b/Replace/Replace.cs
@@ -0,0 +1,23 @@
+class Program
+{
+    static void Replace(ref string s, char suchZeichen, char ersatzZeichen)
+    {
+        // Einfachste Variante
+        char[] ergebnis = new char[s.Length];
+        for (int i = 0; i < s.Length; i++)
+            if (s[i] == suchZeichen)
+                ergebnis[i] = ersatzZeichen;
+            else
+                ergebnis[i] = s[i];
+        s = new String(ergebnis);
+    }
+
+    static void Main(string[] args)
+    {
+        string text = "Anne";
+        Console.WriteLine("Text vorher: " + text);
+        Replace(ref text, 'n', 'm');
+        Console.WriteLine("Text nachher: " + text);
+    }
+}
+
diff --git a/Replace/Replace.csproj b/Replace/Replace.csproj
new file mode 100644
index 0000000..206b89a
--- /dev/null
+++ b/Replace/Replace.csproj
@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>
diff --git a/Teilmenge/Teilmenge.cs b/Teilmenge/Teilmenge.cs
new file mode 100644
index 0000000..ccb7f68
--- /dev/null
+++ b/Teilmenge/Teilmenge.cs
@@ -0,0 +1,29 @@
+class Program
+{
+    static bool Teilmenge(int[] a, int[] b)
+    {
+        // prüfe für jedes Element in b, ob es auch in a vorkommt
+        for (int j = 0; j < b.Length; j++)
+        {
+            bool gefunden = false;
+            for (int i = 0; i < a.Length && !gefunden; i++)
+            {
+                if (b[j] == a[i])
+                    gefunden = true;
+            }
+            if (!gefunden)
+                return false;
+        }
+
+        return true;
+    }
+
+    static void Main(string[] args)
+    {
+        int[] a = { 8, 6, 1, 7, 4, 9 };
+        int[] b = { 1, 6, 9 };
+
+        if (Teilmenge(a, b))
+            Console.WriteLine("b ist Teilmenge von a");
+    }
+}
diff --git a/Teilmenge/Teilmenge.csproj b/Teilmenge/Teilmenge.csproj
new file mode 100644
index 0000000..206b89a
--- /dev/null
+++ b/Teilmenge/Teilmenge.csproj
@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net8.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+</Project>
diff --git a/Uebung13.sln b/Uebung13.sln
new file mode 100644
index 0000000..618d174
--- /dev/null
+++ b/Uebung13.sln
@@ -0,0 +1,55 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 25.0.1706.14
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorArray", "ColorArray\ColorArray.csproj", "{C118DF43-943D-4E0D-A0FA-CE8EE2D16A48}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DateiHelgoland", "DateiHelgoland\DateiHelgoland.csproj", "{A4CD45D4-59F2-4F44-8AF6-F8A5444B06F3}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProduktVerkauf", "ProduktVerkauf\ProduktVerkauf.csproj", "{12AA6AA5-CFD9-478A-A38B-7B5B1A674627}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Teilmenge", "Teilmenge\Teilmenge.csproj", "{8C4796B7-B07A-4445-AC7F-FEE914849115}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace", "Replace\Replace.csproj", "{D452875E-3BED-45CF-A71A-15178F110CCE}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Erasthostenes", "Erasthostenes\Erasthostenes.csproj", "{00F85AB7-95E8-4C41-A6FA-D6C1F8A3F487}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{C118DF43-943D-4E0D-A0FA-CE8EE2D16A48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{C118DF43-943D-4E0D-A0FA-CE8EE2D16A48}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{C118DF43-943D-4E0D-A0FA-CE8EE2D16A48}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{C118DF43-943D-4E0D-A0FA-CE8EE2D16A48}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A4CD45D4-59F2-4F44-8AF6-F8A5444B06F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A4CD45D4-59F2-4F44-8AF6-F8A5444B06F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A4CD45D4-59F2-4F44-8AF6-F8A5444B06F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A4CD45D4-59F2-4F44-8AF6-F8A5444B06F3}.Release|Any CPU.Build.0 = Release|Any CPU
+		{12AA6AA5-CFD9-478A-A38B-7B5B1A674627}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{12AA6AA5-CFD9-478A-A38B-7B5B1A674627}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{12AA6AA5-CFD9-478A-A38B-7B5B1A674627}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{12AA6AA5-CFD9-478A-A38B-7B5B1A674627}.Release|Any CPU.Build.0 = Release|Any CPU
+		{8C4796B7-B07A-4445-AC7F-FEE914849115}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{8C4796B7-B07A-4445-AC7F-FEE914849115}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{8C4796B7-B07A-4445-AC7F-FEE914849115}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{8C4796B7-B07A-4445-AC7F-FEE914849115}.Release|Any CPU.Build.0 = Release|Any CPU
+		{D452875E-3BED-45CF-A71A-15178F110CCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D452875E-3BED-45CF-A71A-15178F110CCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D452875E-3BED-45CF-A71A-15178F110CCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D452875E-3BED-45CF-A71A-15178F110CCE}.Release|Any CPU.Build.0 = Release|Any CPU
+		{00F85AB7-95E8-4C41-A6FA-D6C1F8A3F487}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{00F85AB7-95E8-4C41-A6FA-D6C1F8A3F487}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{00F85AB7-95E8-4C41-A6FA-D6C1F8A3F487}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{00F85AB7-95E8-4C41-A6FA-D6C1F8A3F487}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {956BF058-FD07-431E-AEFA-2915F58510ED}
+	EndGlobalSection
+EndGlobal
-- 
GitLab