diff --git a/OOP2024_AMP.sln b/OOP2024_AMP.sln index 9008f551ca0ffe8c66b2bad3884a8cff21e1c0b5..47296da3d417bce8177b4b09f83bbccc4445a10a 100644 --- a/OOP2024_AMP.sln +++ b/OOP2024_AMP.sln @@ -33,9 +33,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P11Mi Vererbung", "P11Mi Ve EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P14 GenericList", "P14 GenericList\P14 GenericList.csproj", "{4C9F3622-88C7-4A7D-8D21-16BBFC70D8FC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P15 GenericSort", "P15 GenericSort\P15 GenericSort.csproj", "{35FAC883-FC17-4B7B-BA86-93B91B3C9803}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P15 GenericSort", "P15 GenericSort\P15 GenericSort.csproj", "{35FAC883-FC17-4B7B-BA86-93B91B3C9803}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P16 GenericKeyValueList", "P16 GenericKeyValueList\P16 GenericKeyValueList.csproj", "{43F7D344-EBBF-4672-9452-AE59A1C977BF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "P16 GenericKeyValueList", "P16 GenericKeyValueList\P16 GenericKeyValueList.csproj", "{43F7D344-EBBF-4672-9452-AE59A1C977BF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P17 Intro Delegates", "P17 Intro Delegates\P17 Intro Delegates.csproj", "{8E449A0E-B181-4E03-9BF5-732A32CF7A02}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -111,6 +113,10 @@ Global {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Debug|Any CPU.Build.0 = Debug|Any CPU {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Release|Any CPU.ActiveCfg = Release|Any CPU {43F7D344-EBBF-4672-9452-AE59A1C977BF}.Release|Any CPU.Build.0 = Release|Any CPU + {8E449A0E-B181-4E03-9BF5-732A32CF7A02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E449A0E-B181-4E03-9BF5-732A32CF7A02}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E449A0E-B181-4E03-9BF5-732A32CF7A02}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E449A0E-B181-4E03-9BF5-732A32CF7A02}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/P14 GenericList/DblList.cs b/P14 GenericList/DblList.cs index 9a4a56ae125a72c3648b3fbb9a533acc7ac21561..b87403415422476e210428a06ba1bd04ef0aeb52 100644 --- a/P14 GenericList/DblList.cs +++ b/P14 GenericList/DblList.cs @@ -99,6 +99,12 @@ namespace P14_GenericList for (LItem? item = first; item != null; item = item.next) yield return item.data; } + //public IEnumerable<T?> Filter(testfunktion) + //{ + // for (LItem? item = first; item != null; item = item.next) + // if (item.data[0] == "S") testfunktion(data)-->bool + // yield return item.data; + //} public void ReversePrintList() { for (LItem? item = last; item != null; item = item.prev) diff --git a/P16 GenericKeyValueList/KeyValueList.cs b/P16 GenericKeyValueList/KeyValueList.cs index a4636993a598110820f4a010b53186bca1e955bc..e741ac4cf4e1ae9e282ece70d1bfd23051cad862 100644 --- a/P16 GenericKeyValueList/KeyValueList.cs +++ b/P16 GenericKeyValueList/KeyValueList.cs @@ -61,5 +61,10 @@ namespace P16_GenericKeyValueList for (LItem item = first; item != null; item = item.next) yield return (item.Key, item.Value); } + public void Print() + { + for(LItem item = first;item != null; item = item.next) + Console.WriteLine($"{item.Key}: {item.Value}"); + } } } diff --git a/P16 GenericKeyValueList/Program.cs b/P16 GenericKeyValueList/Program.cs index f51068a9f221c4bb027ff927e6d0514a7758f465..220c91858dbbde904fe1098de5a21ef5af121920 100644 --- a/P16 GenericKeyValueList/Program.cs +++ b/P16 GenericKeyValueList/Program.cs @@ -1,6 +1,27 @@ namespace P16_GenericKeyValueList { - internal class Program + class Termin + { + public string was; + public string wer; + public Termin(string was, string wer) { this.was = was; this.wer = wer; } + public override string ToString() => $"Termin: {was} mit {wer}"; + } + + class ComplexKey : IComparable<ComplexKey> + { + public int Wert1 { get; set; } + public string Wert2 { get; set; } + public ComplexKey(int Wert1, string Wert2) { this.Wert1 = Wert1; this.Wert2 = Wert2; } + public int CompareTo(ComplexKey other) + { + int diff = Wert1.CompareTo(other.Wert1); + if (diff != 0) + return diff; + return Wert2.CompareTo(other.Wert2); + } + } + class Program { static void Main(string[] args) { @@ -13,6 +34,69 @@ foreach (var item in tel) { Console.WriteLine( $"{item.Item1}: {item.Item2}"); } - } + + KeyValueList<string, int> kvListe = new KeyValueList<string, int>(); + kvListe["Wienkop"] = 1614; + kvListe["Otsa"] = 1855; + + Console.WriteLine($"Telefonnummer von Wienkop: {kvListe["Wienkop"]}"); + Console.WriteLine("-----------"); + + kvListe.Print(); + Console.WriteLine("-----------"); + kvListe["Otsa"] = 9999; + kvListe.Print(); + Console.WriteLine("-----------"); + + KeyValueList<string, Termin> termine = new KeyValueList<string, Termin>(); + termine["Wienkop"] = new Termin("IT-Proj", "Digitale Visitenkarte"); + termine.Print(); + //foreach (var item in termine) + //{ + // Console.WriteLine(item.val); + //} + + List<Termin> termineMi = new List<Termin>(); + termineMi.Add(new Termin("08:00 Prog2-Vorlesung", "Gruppe-Wienkop")); + termineMi.Add(new Termin("09:45 Dig Bildbearbeitung", "MA-MIN")); + + List<Termin> termineDi = new List<Termin>(); + termineDi.Add(new Termin("08:00 Prog2-Übung", "Gruppe-Wienkop")); + termineDi.Add(new Termin("09:45 Prog2-Vorlesung", "Gruppe-Wienkop")); + termineDi.Add(new Termin("11:30 Mitarbeiterbesprechung", "Jobbörse")); + + KeyValueList<string, List<Termin>> terminverwaltung = new KeyValueList<string, List<Termin>>(); + terminverwaltung["02.06.2020"] = termineDi; + terminverwaltung["03.06.2020"] = termineMi; + terminverwaltung["02.06.2020"]?.Add(new Termin("11:30 Teams", "BayernMINT")); + + + // Pfannkuchen, Zutaten(Mehl, Milch, Eier), Zubereitung (Schritt1, Schritt2, ...) + KeyValueList<string, (List<string>, List<string>)> rezepte = new KeyValueList<string, (List<string>, List<string>)>(); + List<string> zutaten = new List<string>(); + zutaten.Add("Mehl"); + zutaten.Add("Milch"); + zutaten.Add("Eier"); + List<string> zubereitung = new List<string>(); + zubereitung.Add("Eier in Schüssel schlagen"); + zubereitung.Add("mit Mehl und Milch verrühren"); + + rezepte["Pfannkuchen"] = (zutaten, zubereitung); + + + List<string> zutaten2; + List<string> zubereitung2; + (zutaten2, zubereitung2) = rezepte["Pfannkuchen"]; + Console.WriteLine("Zutaten: "); + foreach (var item in zutaten2) + { + Console.WriteLine(item); + } + Console.WriteLine("Zubereitung:"); + foreach (var item in zubereitung2) + { + Console.WriteLine(item); + } + } } } diff --git a/P17 Intro Delegates/P17 Intro Delegates.csproj b/P17 Intro Delegates/P17 Intro Delegates.csproj new file mode 100644 index 0000000000000000000000000000000000000000..58397634564af744fd8a1f891f8b625c5983f688 --- /dev/null +++ b/P17 Intro Delegates/P17 Intro Delegates.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <RootNamespace>P17_Intro_Delegates</RootNamespace> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/P17 Intro Delegates/Program.cs b/P17 Intro Delegates/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..15680f86e54cac83eb93cc41386358869d3ec640 --- /dev/null +++ b/P17 Intro Delegates/Program.cs @@ -0,0 +1,31 @@ +namespace P17_Intro_Delegates +{ + internal class Program + { + static double Square(double x) => x * x; + static double Mal2(double x) => 2 * x; + + delegate double ZulaessigeFunktionen(double x); + static void Wertetabelle(double von, double bis, + double schrittweite, ZulaessigeFunktionen fkt) + { + for (double x = von; x <= bis ; x+= schrittweite) + Console.WriteLine( $"{x:f8} | {fkt(x):f8}"); + Console.WriteLine( "------------"); + } + static void Main(string[] args) + { + Wertetabelle(0, 5, 1, Square); + Wertetabelle(0, 5, 1, Mal2); + Wertetabelle(0, 5, 1, Math.Sin); + Wertetabelle(0, 5, 1, delegate (double xxx) { return xxx + 1; }); + Wertetabelle(0, 5, 1, y => y + 2); + + ZulaessigeFunktionen meineFunktRef; + meineFunktRef = Square; + Console.WriteLine(meineFunktRef(10)); + meineFunktRef = z => z + 10; + Console.WriteLine(meineFunktRef(10)); + } + } +}