From 3f0b8d6369c4ae5b43c0bf9b88b36d09adfbdaec Mon Sep 17 00:00:00 2001 From: Uwe Wienkop <uwe.wienkop@th-nuernberg.de> Date: Sun, 12 Jun 2022 16:42:16 +0200 Subject: [PATCH] 2022-06-12 --- 02-1 OpUeberladungBrueche/Bruch.cs | 18 +- 02-1 OpUeberladungBrueche/Program.cs | 2 + 03-UbgKlasseTime-Mo/Program.cs | 2 +- 11-6 ListPersVerwaltung/.editorconfig | 32 +++ .../11-6 ListPersVerwaltung.csproj | 9 + 11-6 ListPersVerwaltung/ClassDiagram1.cd | 48 +++++ 11-6 ListPersVerwaltung/GenericList.cs | 195 ++++++++++++++++++ 11-6 ListPersVerwaltung/Personal.cs | 50 +++++ 11-6 ListPersVerwaltung/Program.cs | 72 +++++++ Prog2WienkopSS2021.sln | 8 +- 10 files changed, 433 insertions(+), 3 deletions(-) create mode 100644 11-6 ListPersVerwaltung/.editorconfig create mode 100644 11-6 ListPersVerwaltung/11-6 ListPersVerwaltung.csproj create mode 100644 11-6 ListPersVerwaltung/ClassDiagram1.cd create mode 100644 11-6 ListPersVerwaltung/GenericList.cs create mode 100644 11-6 ListPersVerwaltung/Personal.cs create mode 100644 11-6 ListPersVerwaltung/Program.cs diff --git a/02-1 OpUeberladungBrueche/Bruch.cs b/02-1 OpUeberladungBrueche/Bruch.cs index ec52580..0e7a727 100644 --- a/02-1 OpUeberladungBrueche/Bruch.cs +++ b/02-1 OpUeberladungBrueche/Bruch.cs @@ -34,7 +34,8 @@ namespace _02_1_OpUeberladungBrueche => new Bruch(this.z * b.z, this.n * b.n); public Bruch Mult_V4(int k) => new Bruch(z * k, n); - + // Voraussetzung bei allen zuvor aufgeführten nicht-statischen Methoden: + // Es braucht links jeweils ein Bruch-Objekt! public static Bruch Mult_V5(Bruch b1, Bruch b2) => new Bruch(b1.z * b2.z, b1.n * b2.n); @@ -74,8 +75,23 @@ namespace _02_1_OpUeberladungBrueche #region Vergleichsoperatoren public static bool operator ==(Bruch b1, Bruch b2) => b1.z == b2.z && b1.n == b2.n; public static bool operator !=(Bruch b1, Bruch b2) => !(b1 == b2); + public static bool operator true(Bruch b) => b.n != 1; + // Nenner == 1 heißt ganze Zahl, kein echter Bruch public static bool operator false(Bruch b) => b.n == 1; + public override bool Equals(object obj) + { + if (obj == null) + return false; + if (this.GetType() != obj.GetType()) + return false; + + return this == (Bruch)obj; + } + public override int GetHashCode() + { + return z.GetHashCode() ^ n.GetHashCode(); + } #endregion public override string ToString() => $"{z}/{n}"; } diff --git a/02-1 OpUeberladungBrueche/Program.cs b/02-1 OpUeberladungBrueche/Program.cs index f622754..ed05529 100644 --- a/02-1 OpUeberladungBrueche/Program.cs +++ b/02-1 OpUeberladungBrueche/Program.cs @@ -50,6 +50,8 @@ namespace _02_1_OpUeberladungBrueche Console.WriteLine("Brüche sind gleich"); else Console.WriteLine("Brüche sind NICHT gleich!"); + + if (b4) Console.WriteLine("b4 ist ein echter Bruch"); else diff --git a/03-UbgKlasseTime-Mo/Program.cs b/03-UbgKlasseTime-Mo/Program.cs index cd0a0cf..f2c597e 100644 --- a/03-UbgKlasseTime-Mo/Program.cs +++ b/03-UbgKlasseTime-Mo/Program.cs @@ -9,7 +9,7 @@ namespace _03_UbgKlasseTime_Mo { Time t1 = new Time(9, 45); Time t3 = "11:30"; - Time t2 = t1 + "1:30" + 15; + Time t2 = t1 + "10:30" + 15; Console.WriteLine(t2); TimeSpan ts1 = t3 - t1; Console.WriteLine(t2); diff --git a/11-6 ListPersVerwaltung/.editorconfig b/11-6 ListPersVerwaltung/.editorconfig new file mode 100644 index 0000000..2edebbf --- /dev/null +++ b/11-6 ListPersVerwaltung/.editorconfig @@ -0,0 +1,32 @@ +# Rules in this file were initially inferred by Visual Studio IntelliCode from the C:\Users\wienkop\source\repos\prog2-ss2021-wienkop\11-5 BinTreePersVerwaltung\ codebase based on best match to current usage at 08.06.2021 +# You can modify the rules from these initially generated values to suit your own policies +# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference +[*.cs] + + +#Core editorconfig formatting - indentation + +#use soft tabs (spaces) for indentation +indent_style = space + +#Formatting - spacing options + +#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call +csharp_space_between_method_call_parameter_list_parentheses = false +#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list. +csharp_space_between_method_declaration_parameter_list_parentheses = false + +#Style - expression bodied member options + +#prefer block bodies for methods +csharp_style_expression_bodied_methods = false:suggestion + +#Style - language keyword and framework type options + +#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion + +#Style - modifier options + +#do not prefer accessibility modifiers to be specified +dotnet_style_require_accessibility_modifiers = never:suggestion diff --git a/11-6 ListPersVerwaltung/11-6 ListPersVerwaltung.csproj b/11-6 ListPersVerwaltung/11-6 ListPersVerwaltung.csproj new file mode 100644 index 0000000..cf12192 --- /dev/null +++ b/11-6 ListPersVerwaltung/11-6 ListPersVerwaltung.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_11_5_BinTreePersVerwaltung</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/11-6 ListPersVerwaltung/ClassDiagram1.cd b/11-6 ListPersVerwaltung/ClassDiagram1.cd new file mode 100644 index 0000000..a514e10 --- /dev/null +++ b/11-6 ListPersVerwaltung/ClassDiagram1.cd @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<ClassDiagram MajorVersion="1" MinorVersion="1"> + <Class Name="_11_6_ListPersVerwaltung.MyList<T>" Collapsed="true"> + <Position X="14.25" Y="5.75" Width="1.5" /> + <TypeIdentifier> + <HashCode>AAAAAAAAAAAAABQEAAEAAIQQQFgAAAIAAAACAAEEAgA=</HashCode> + <FileName>GenericList.cs</FileName> + </TypeIdentifier> + <Lollipop Position="0.2" /> + </Class> + <Class Name="_11_6_ListPersVerwaltung.Personal" Collapsed="true"> + <Position X="9.5" Y="5.75" Width="1.5" /> + <TypeIdentifier> + <HashCode>AAAAAAAAAAAAAAQAAAAAAAQAAAAgAAAAAAAAAAAAAAA=</HashCode> + <FileName>Personal.cs</FileName> + </TypeIdentifier> + <Lollipop Position="0.2" /> + </Class> + <Class Name="_11_6_ListPersVerwaltung.Mitarbeiter" Collapsed="true"> + <Position X="11.75" Y="7" Width="1.5" /> + <TypeIdentifier> + <HashCode>AAAAAAAAAAAAAAAEAAAAAAAAAAAgAAAAAgAAAAAAAAA=</HashCode> + <FileName>Personal.cs</FileName> + </TypeIdentifier> + </Class> + <Class Name="_11_6_ListPersVerwaltung.Führungskraft" Collapsed="true"> + <Position X="7.25" Y="7" Width="1.5" /> + <TypeIdentifier> + <HashCode>AAAAAAAAAAAAAAAEAAAAAAAAAAEgAAAAAgAAAAAAAAA=</HashCode> + <FileName>Personal.cs</FileName> + </TypeIdentifier> + </Class> + <Class Name="_11_6_ListPersVerwaltung.Werkvertragler" Collapsed="true"> + <Position X="9.5" Y="7" Width="1.5" /> + <TypeIdentifier> + <HashCode>AAAAAAAAAAAAAAAEAAAAAAAAAABgAAAAAAAAAAAAAAA=</HashCode> + <FileName>Personal.cs</FileName> + </TypeIdentifier> + </Class> + <Class Name="_11_6_ListPersVerwaltung.Program" Collapsed="true"> + <Position X="16.5" Y="5.75" Width="1.5" /> + <TypeIdentifier> + <HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAA=</HashCode> + <FileName>Program.cs</FileName> + </TypeIdentifier> + </Class> + <Font Name="Segoe UI" Size="9" /> +</ClassDiagram> \ No newline at end of file diff --git a/11-6 ListPersVerwaltung/GenericList.cs b/11-6 ListPersVerwaltung/GenericList.cs new file mode 100644 index 0000000..a1274fd --- /dev/null +++ b/11-6 ListPersVerwaltung/GenericList.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Text; + +namespace _11_6_ListPersVerwaltung +{ + //delegate bool MeinFilter<T>(T var); + + + class MyList<T> : IEnumerable, IComparable<MyList<T>> where T : IComparable<T> + { + class LItem + { + public T data; + public LItem next = null, prev = null; + public LItem(T Data) { data = Data; } + + public override string ToString() + => $"Name: {data}, prev: {(prev == null ? "null" : prev.data.ToString())}, next: {(next == null ? "null" : next.data.ToString())}"; + } + + LItem first = null, last = null; + public int Count { get; private set; } + public MyList() { Count = 0; } + public int CompareTo(MyList<T> other) => Count - other.Count; + + public void AddEnd(T Data) + { + LItem newItem = new LItem(Data); + Count++; + if (first == null) + first = last = newItem; + else // Es gibt schon Listenelemente + { + last.next = newItem; + newItem.prev = last; + last = newItem; + } + } + public void AddFront(T Data) + { + LItem newItem = new LItem(Data); + Count++; + if (first == null) + first = last = newItem; + else + { + newItem.next = first; + first.prev = newItem; + first = newItem; + } + } + public void AddSorted(T InsData) + { + // 1. Fall: Leere Liste oder Anfügen am Listenende + if (first == null || last.data.CompareTo(InsData) <= 0) + AddEnd(InsData); + else if (InsData.CompareTo(first.data) <= 0) + // 2. Fall: Anfügen am Listenende + AddFront(InsData); + else + { + // Wir wissen: Das neue Element ist NICHT das erste und nicht das letzte Element + LItem newItem = new LItem(InsData); + Count++; + + LItem item = first; + while (item.next.data.CompareTo(InsData) < 0) + item = item.next; + // bis hierher identisch zur einfach-verketteten Liste + newItem.next = item.next; // Vorwärtsverkettung vom neuen Element zur Restliste + newItem.prev = item; // Rückwärtsverkettung vom neuen Elenent zum Listenanfangsstück + item.next.prev = newItem; // Rückwärtsverkettung vom nachfolgenden Listenelement + item.next = newItem; // Vorwärtsverkettung zum neuen Element + } + } + public void DeleteFirst() + { + // Fall 1: Liste ist leer + // Fall 2: Liste besteht nur aus EINEM Element + // Fall 3: Liste hat mehr als ein Element + + if (first == null) // Fall 1 + return; + Count--; + if (first == last) // Fall 2 + first = last = null; + else + { + first = first.next; + first.prev = null; + } + } + public void DeleteLast() + { + // Fall 1: Liste ist leer + // Fall 2: Liste besteht nur aus EINEM Element + // Fall 3: Liste hat mehr als ein Element + + if (first == null) // Fall 1 + return; + Count--; + if (first == last) // Fall 2 + first = last = null; + else + { + last = last.prev; + last.next = null; + } + } + public void DeleteByName(T DelData) + { + // Fall 1: Liste ist leer + // Fall 2: Das gesuchte Element befindet sich am Anfang + // Fall 3: Das gesuchte Element befindet sich am Ende + // Fall 4: Das gesuchte Element befindet sich mittendrin + + if (first == null) // Fall 1 + return; + if (first.data.CompareTo(DelData) == 0) // Fall 2 + DeleteFirst(); + else if (last.data.CompareTo(DelData) == 0) // Fall 3 + DeleteLast(); + else + { + // Fall 4: Wir wissen: + // Das zu löschende Element befindet sich weder am Anfang noch am Ende + // --> Es gibt ein Vorgänger- UND ein Nachfolger-Element + Count--; + LItem item = first.next; + while (item.next != null && item.data.CompareTo(DelData) != 0) + item = item.next; + if (item.next != null) + { + // d.h. Element wurde gefunden und item zeigt auf dieses Element + // 20 - 21 - 22 + item.prev.next = item.next; // 20 -> 22 Nachfolger + item.next.prev = item.prev; // 22 -> 20 Vorgänger + } + } + } + public void Print() + { + for (LItem item = first; item != null; item = item.next) + { + Console.WriteLine(item.data); + } + } + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + for (LItem item = first; item != null; item = item.next) + { + sb.Append(item.data.ToString()); + sb.Append(" "); + } + return sb.ToString(); + } + public void PrintReverse() + { + for (LItem item = last; item != null; item = item.prev) + { + Console.WriteLine(item.data); + } + Console.WriteLine("-------------------"); + } + public bool Exist(T findData) + { + for (LItem item = first; item != null; item = item.next) + { + if (item.data.CompareTo(findData) == 0) + return true; + } + return false; + } + public IEnumerable<T> Reverse() + { + for (LItem item = last; item != null; item = item.prev) + yield return item.data; + } + public IEnumerator GetEnumerator() + { + for (LItem item = first; item != null; item = item.next) + yield return item.data; + } + + public IEnumerable<T> Filter(Predicate<T> filterFunktion) + { + for (LItem item = first; item != null; item = item.next) + if (filterFunktion(item.data)) // Filterfunktion + yield return item.data; + } + } +} diff --git a/11-6 ListPersVerwaltung/Personal.cs b/11-6 ListPersVerwaltung/Personal.cs new file mode 100644 index 0000000..6c92483 --- /dev/null +++ b/11-6 ListPersVerwaltung/Personal.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace _11_6_ListPersVerwaltung +{ + abstract class Personal : IComparable<Personal> + { + public virtual string Name { get; set; } + + //private string Name2x; + //public string Name2 + //{ + // get { return Name2x; } + // set { Name2x = value; } + //} + public Personal(string Name) { this.Name = Name; } + abstract public double Kosten { get; } + public int CompareTo(Personal other) => Name.CompareTo(other.Name); + } + class Mitarbeiter : Personal + { + protected double gehalt; + public Mitarbeiter(string Name, double Gehalt) : base(Name) { gehalt = Gehalt; } + public override double Kosten { get => 12.65 * gehalt; } + public override string ToString() => $"{Name,-15} {Kosten,6}"; + } + class Führungskraft : Personal + { + protected double gehalt; + protected double erfolgsbeteiligung; + public Führungskraft(string Name, double Gehalt, double Erfolgsbeteiligung) : base(Name) + { + gehalt = Gehalt; + erfolgsbeteiligung = Erfolgsbeteiligung; + } + public override double Kosten { get => 12.65 * gehalt + erfolgsbeteiligung; } + public override string ToString() => $"{Name,-15} {Kosten,6}"; + } + class Werkvertragler : Personal + { + protected double betrag; + public Werkvertragler(string Name, double Betrag) : base(Name) + { + betrag = Betrag; + } + public override double Kosten { get => betrag; } + public override string ToString() => $"{Name,-15} {Kosten,6}"; + } +} diff --git a/11-6 ListPersVerwaltung/Program.cs b/11-6 ListPersVerwaltung/Program.cs new file mode 100644 index 0000000..260dca4 --- /dev/null +++ b/11-6 ListPersVerwaltung/Program.cs @@ -0,0 +1,72 @@ +using System; +using System.Linq; + +namespace _11_6_ListPersVerwaltung +{ + class Program + { + static void InputData(MyList<Personal> pt) + { + pt.AddSorted(new Mitarbeiter("Dieter", 2000)); + pt.AddSorted(new Führungskraft("Anton", 5000, 10000)); + pt.AddSorted(new Werkvertragler("Gustav", 12000)); + pt.AddSorted(new Mitarbeiter("Heiner", 2000)); + pt.AddSorted(new Werkvertragler("Berta", 10000)); + pt.AddSorted(new Werkvertragler("Ludwig", 12000)); + pt.AddSorted(new Mitarbeiter("Klaus", 2000)); + pt.AddSorted(new Mitarbeiter("Ida", 2000)); + pt.AddSorted(new Führungskraft("Charles", 5000, 10000)); + pt.AddSorted(new Werkvertragler("Johanna", 10000)); + pt.AddSorted(new Mitarbeiter("Emma", 2000)); + pt.AddSorted(new Mitarbeiter("Franz", 10000)); + pt.AddSorted(new Werkvertragler("Norbert", 10000)); + pt.AddSorted(new Werkvertragler("Willi", 10000)); + pt.AddSorted(new Mitarbeiter("Quasimodo", 2500)); + pt.AddSorted(new Führungskraft("Manni", 5200, 15000)); + pt.AddSorted(new Mitarbeiter("Otto", 10000)); + pt.AddSorted(new Werkvertragler("Uwe", 10000)); + pt.AddSorted(new Werkvertragler("Stefan", 10000)); + pt.AddSorted(new Mitarbeiter("Thorsten", 10000)); + pt.AddSorted(new Werkvertragler("Rainer", 10000)); + pt.AddSorted(new Werkvertragler("Zacharias", 10000)); + pt.AddSorted(new Mitarbeiter("Yvonne", 3000)); + pt.AddSorted(new Führungskraft("Volker", 5100, 10000)); + pt.AddSorted(new Mitarbeiter("Xaver", 2500)); + pt.AddSorted(new Werkvertragler("Paul", 15000)); + } + static void Main(string[] args) + { + + MyList<Personal> persListe = new MyList<Personal>(); + InputData(persListe); + persListe.Print(); + Console.WriteLine("-------------------"); + + + var res = from Personal p in persListe + where p is Führungskraft + orderby p.Kosten + select new { Name = p.Name.ToUpper(), Kosten = p.Kosten }; + foreach (var item in res) + { + Console.WriteLine(item); + } + Console.WriteLine("-------------------"); + + double GesKosten = res.Sum(w => w.Kosten); + Console.WriteLine("Kosten für die Führungskräfte: " + GesKosten); + + int anz = res.Count(); + Console.WriteLine(anz + " Führungskräfte"); + Console.WriteLine("-------------------"); + + + var res2 = from Personal p in persListe + where p.Kosten < 30000 + orderby p.Kosten descending, p.Name ascending // Sortierung nach Kosten, dann Name + select new { Name = p.Name, K = p.Kosten }; + foreach (var item in res2) + Console.WriteLine(item.Name + ": " + item.K); + } + } +} diff --git a/Prog2WienkopSS2021.sln b/Prog2WienkopSS2021.sln index 06994d5..ad8e977 100644 --- a/Prog2WienkopSS2021.sln +++ b/Prog2WienkopSS2021.sln @@ -113,7 +113,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13-1 ApplyAll", "13-Ubg App EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13-UbgCycleList-Mo", "13-UbgCycleList-Mo\13-UbgCycleList-Mo.csproj", "{C1594C99-2A3F-4948-AC3E-ED7D16379C48}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13-2 VererbungWdhlg", "13-2 VererbungWdhlg\13-2 VererbungWdhlg.csproj", "{D0B0CCA1-1E7B-4C35-BAD2-AABD1993E9A8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13-2 VererbungWdhlg", "13-2 VererbungWdhlg\13-2 VererbungWdhlg.csproj", "{D0B0CCA1-1E7B-4C35-BAD2-AABD1993E9A8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11-6 ListPersVerwaltung", "11-6 ListPersVerwaltung\11-6 ListPersVerwaltung.csproj", "{52BF103D-C2C4-431F-81CB-0EF713275BCA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -345,6 +347,10 @@ Global {D0B0CCA1-1E7B-4C35-BAD2-AABD1993E9A8}.Debug|Any CPU.Build.0 = Debug|Any CPU {D0B0CCA1-1E7B-4C35-BAD2-AABD1993E9A8}.Release|Any CPU.ActiveCfg = Release|Any CPU {D0B0CCA1-1E7B-4C35-BAD2-AABD1993E9A8}.Release|Any CPU.Build.0 = Release|Any CPU + {52BF103D-C2C4-431F-81CB-0EF713275BCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52BF103D-C2C4-431F-81CB-0EF713275BCA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52BF103D-C2C4-431F-81CB-0EF713275BCA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52BF103D-C2C4-431F-81CB-0EF713275BCA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- GitLab