From 005dfed9e47ebc3fb982815e18a44642b90a5f79 Mon Sep 17 00:00:00 2001 From: Uwe Wienkop <uwe.wienkop@th-nuernberg.de> Date: Mon, 20 Dec 2021 11:19:43 +0100 Subject: [PATCH] 2021-12-20 Wiederholung&Vertiefung --- 11 UebgKoordinaten_Di/Program.cs | 48 ++++++++++++++++++- .../12 PW_Check (SoSe2019).csproj | 9 ++++ 12 PW_Check (SoSe2019)/Program.cs | 45 +++++++++++++++++ 12 Params/12 Params.csproj | 9 ++++ 12 Params/Program.cs | 31 ++++++++++++ 12 StringConcat/12 StringConcat.csproj | 9 ++++ 12 StringConcat/Program.cs | 21 ++++++++ 12 StructBruch/12 StructBruch.csproj | 9 ++++ 12 StructBruch/Program.cs | 33 +++++++++++++ 12 StructToString/12 StructToString.csproj | 9 ++++ 12 StructToString/Program.cs | 23 +++++++++ Prog1_WS2021_22.sln | 36 ++++++++++++-- 12 files changed, 277 insertions(+), 5 deletions(-) create mode 100644 12 PW_Check (SoSe2019)/12 PW_Check (SoSe2019).csproj create mode 100644 12 PW_Check (SoSe2019)/Program.cs create mode 100644 12 Params/12 Params.csproj create mode 100644 12 Params/Program.cs create mode 100644 12 StringConcat/12 StringConcat.csproj create mode 100644 12 StringConcat/Program.cs create mode 100644 12 StructBruch/12 StructBruch.csproj create mode 100644 12 StructBruch/Program.cs create mode 100644 12 StructToString/12 StructToString.csproj create mode 100644 12 StructToString/Program.cs diff --git a/11 UebgKoordinaten_Di/Program.cs b/11 UebgKoordinaten_Di/Program.cs index 04ecf95..70bd028 100644 --- a/11 UebgKoordinaten_Di/Program.cs +++ b/11 UebgKoordinaten_Di/Program.cs @@ -2,7 +2,7 @@ namespace _11_UebgKoordinaten_Di { - + // Erstellen Sie eine Struct Koordinate Coord(double x, double y) mit // ToString() und Konstruktor(en) // Erstellen Sie in Program eine Methode CoordDist(), welche den Abstand zwischen zwei Koordinaten bestimmt @@ -10,13 +10,57 @@ namespace _11_UebgKoordinaten_Di struct Coord { + public double x, y; + public Coord(double X, double Y) + { + x = X; + y = Y; + } + public override string ToString() => $"Koordinate: ({x}|{y})"; } class Program { + static double CoordDist(Coord p1, Coord p2) + { + double dx = p1.x - p2.x; + double dy = p1.y - p2.y; + return Math.Sqrt(dx * dx + dy * dy); + } + static void CoordMove(ref Coord p, double deltaX, double deltaY) + { + p.x += deltaX; + p.y += deltaY; + } + static Coord CoordMove(Coord p, double deltaX, double deltaY) + { + p.x += deltaX; + p.y += deltaY; + return p; + } static void Main(string[] args) { - Console.WriteLine(); + Coord c1 = new Coord(1, 2); + Coord c2 = new Coord(3, 3); + Console.WriteLine(c1); + Console.WriteLine(c2); + Console.WriteLine(CoordDist(c1, c2)); + + CoordMove(ref c1, 4, 3); // Referenzübergabe der Koord. c1 + Console.WriteLine(c1); + + Coord c3 = CoordMove(c1, 6, 5); // Werteübergabe von c1, aber return liefert Ergebnis zurück + Console.WriteLine(c3); + + Console.WriteLine(c3.ToString()); + + Coord[] coords = new Coord[5]; + coords[0] = new Coord(1, 2); + coords[1] = new Coord(3, 3); + + coords[3] = coords[0]; // Structs sind Wertetypen! + coords[0].x = -999; // d.h. bei der Zuweisung wird eine KOPIE von coords[0] gespeichert + coords[0].y = -999; // bei Referenztypen (class) wird hingegen eine weitere Referenz gespeichert } } } diff --git a/12 PW_Check (SoSe2019)/12 PW_Check (SoSe2019).csproj b/12 PW_Check (SoSe2019)/12 PW_Check (SoSe2019).csproj new file mode 100644 index 0000000..3c54404 --- /dev/null +++ b/12 PW_Check (SoSe2019)/12 PW_Check (SoSe2019).csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_12_PW_Check__SoSe2019_</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/12 PW_Check (SoSe2019)/Program.cs b/12 PW_Check (SoSe2019)/Program.cs new file mode 100644 index 0000000..adfeb9d --- /dev/null +++ b/12 PW_Check (SoSe2019)/Program.cs @@ -0,0 +1,45 @@ +using System; + +namespace _12_PW_Check__SoSe2019_ +{ +// Erstellen Sie eine Funktion „PWCheck“, die für ein als String übergebenes Passwort überprüft, ob es +// gewissen Anforderungen genügt.Ein Passwort muss +// mindestens 12 Zeichen lang sein UND +// mindestens einen Großbuchstaben enthalten UND +// mindestens eine Ziffer enthalten. +// Die Funktion liefert true, wenn der übergebene String alle Anforderungen erfüllt, sonst false. + class Program + { + static bool PWCheck(string passwort) + { + if (passwort.Length < 12) // .Length ~ Anzahl der Zeichen des strings + // "AB" --> .Length = 2; Diese sind an Pos [0] und [1] gespeichert + return false; + //for (int i = 0; i < passwort.Length && (grossbuchstabe==false || ziffer==false); i++) + //{ + // char zeichen = passwort[i]; + //} + bool grossbuchstabe = false, ziffer = false; + foreach (char zeichen in passwort) // D2ies_ist_2mein_Passwort + { + if (zeichen >= 'A' && zeichen <= 'Z') + grossbuchstabe = true; + else if (zeichen >= '0' && zeichen <= '9') + ziffer = true; + if (grossbuchstabe && ziffer) + return true; + } + return false; // grossbuchstabe==true && ziffer==true; + + //if (grossbuchstabe == true && ziffer == true) + // return true; + //else + // return false; + + } + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/12 Params/12 Params.csproj b/12 Params/12 Params.csproj new file mode 100644 index 0000000..eac40ee --- /dev/null +++ b/12 Params/12 Params.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_12_Params</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/12 Params/Program.cs b/12 Params/Program.cs new file mode 100644 index 0000000..c94b1ac --- /dev/null +++ b/12 Params/Program.cs @@ -0,0 +1,31 @@ +using System; + +namespace _12_Params +{ + class Program + { + static void DoIt(int x1, int x2) { } + static void DoIt(string s, params int[] xf) // params ~ ermöglicht eine var. Anzahl an Parametern + // alle Param. müssen vom angegebenen Typ sein + { + Console.WriteLine($"---------\nLänge: {xf.Length}"); + foreach (int item in xf) + { + Console.WriteLine(item); + } + } + + static void Main(string[] args) + { + int[] werte = { 1, 2, 3, 4, 5, 6, 7 }; + DoIt(1, 2); + DoIt("Hallo", 2, 3); + DoIt("Hallo", new int[] { 2, 3 }); + DoIt("Hallo", werte); + + string s = "Dies ist ein Zeile, die es in sich hat!"; + char[] separatorZeichen = { ' ', ',', '!' }; + string[] sf = s.Split(separatorZeichen); // Variable Anzahl an Parametern sinnvoll + } + } +} diff --git a/12 StringConcat/12 StringConcat.csproj b/12 StringConcat/12 StringConcat.csproj new file mode 100644 index 0000000..cd6ced8 --- /dev/null +++ b/12 StringConcat/12 StringConcat.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_12_StringConcat</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/12 StringConcat/Program.cs b/12 StringConcat/Program.cs new file mode 100644 index 0000000..470a1c9 --- /dev/null +++ b/12 StringConcat/Program.cs @@ -0,0 +1,21 @@ +using System; + +namespace _12_StringConcat +{ + class Program + { + // public static Bruch operator *(Bruch b1, Bruch b2) + // public static string operator+ (string s1, string s2) + + static void Main(string[] args) + { + Console.WriteLine("44" + 10 + 2); + Console.WriteLine("44" + (10 + 2)); + + int x = 1 + 2 + 3; // (1 + 2) + 3 + Console.WriteLine(("44" + 10) + 2); + // "44" + 10.ToString() --> "44" + "10" --> "4410" + // "4410" + 2.ToString() --> "4410" + "2" --> "44102" + } + } +} diff --git a/12 StructBruch/12 StructBruch.csproj b/12 StructBruch/12 StructBruch.csproj new file mode 100644 index 0000000..3200cc4 --- /dev/null +++ b/12 StructBruch/12 StructBruch.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_12_StructBruch</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/12 StructBruch/Program.cs b/12 StructBruch/Program.cs new file mode 100644 index 0000000..b11a3e4 --- /dev/null +++ b/12 StructBruch/Program.cs @@ -0,0 +1,33 @@ +using System; + +namespace _12_StructBruch +{ + struct Bruch + { + public int zaehler, nenner; + public Bruch(int Zaehler, int Nenner) { zaehler = Zaehler;nenner = Nenner; } + public override string ToString() { return $"{zaehler}/{nenner}"; } + public static Bruch operator *(Bruch b1, Bruch b2) + => new Bruch(b1.zaehler * b2.zaehler, b1.nenner * b2.nenner); + } + class Program + { + static void Main(string[] args) + { + Bruch b1 = new Bruch(1, 2); + Bruch b2 = new Bruch(2, 3); + + Console.WriteLine($"{b1.zaehler}/{b1.nenner}"); + // : + Console.WriteLine($"{b2.zaehler}|{b2.nenner}"); + + Console.WriteLine(b1); + Console.WriteLine(b2); + string text = b1.ToString(); + Console.WriteLine($"Als Text: {text}"); + + Bruch b3 = b1 * b2; + Console.WriteLine(b3); + } + } +} diff --git a/12 StructToString/12 StructToString.csproj b/12 StructToString/12 StructToString.csproj new file mode 100644 index 0000000..eb9e61a --- /dev/null +++ b/12 StructToString/12 StructToString.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_12_StructToString</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/12 StructToString/Program.cs b/12 StructToString/Program.cs new file mode 100644 index 0000000..fcbd7f9 --- /dev/null +++ b/12 StructToString/Program.cs @@ -0,0 +1,23 @@ +using System; + +namespace _12_StructToString +{ + struct Person + { + public string name, vorname; + public static string PersonToString(Person p) { return $"Name: {p.name}, Vorname: {p.vorname}"; } + //public static string ToString(Person p) { return $"Name: {p.name}, Vorname: {p.vorname}"; } + public override string ToString() { return $"Name: {name}, Vorname: {vorname}"; } + } + class Program + { + static void Main(string[] args) + { + Person p1 = new Person(); + p1.name = "Müller"; + p1.vorname = "Anton"; + + Console.WriteLine(p1); + } + } +} diff --git a/Prog1_WS2021_22.sln b/Prog1_WS2021_22.sln index 5cfbffa..1ff467a 100644 --- a/Prog1_WS2021_22.sln +++ b/Prog1_WS2021_22.sln @@ -107,11 +107,21 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11 UebgKoordinatenMo", "11 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11 Time", "11 Time\11 Time.csproj", "{A5C6305D-65D0-4B95-9884-F75E61BDD8E9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11 UebgKoordinaten_Di", "11 UebgKoordinaten_Di\11 UebgKoordinaten_Di.csproj", "{B1C38CF7-98C6-4696-990E-E590C24BCA46}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11 UebgKoordinaten_Di", "11 UebgKoordinaten_Di\11 UebgKoordinaten_Di.csproj", "{B1C38CF7-98C6-4696-990E-E590C24BCA46}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11 StructsPublicPrivate", "11 StructsPublicPrivate\11 StructsPublicPrivate.csproj", "{2A85F1F9-5C05-4905-BC7D-D9C836D10477}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11 StructsPublicPrivate", "11 StructsPublicPrivate\11 StructsPublicPrivate.csproj", "{2A85F1F9-5C05-4905-BC7D-D9C836D10477}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11 ThrowIntro", "11 ThrowIntro\11 ThrowIntro.csproj", "{055DDC53-EB6E-43B8-BED5-EC6BEDC87507}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "11 ThrowIntro", "11 ThrowIntro\11 ThrowIntro.csproj", "{055DDC53-EB6E-43B8-BED5-EC6BEDC87507}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 PW_Check (SoSe2019)", "12 PW_Check (SoSe2019)\12 PW_Check (SoSe2019).csproj", "{0EC7D975-1D95-40B7-BBDF-73A475231A1F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12 Params", "12 Params\12 Params.csproj", "{4EBDD0DB-69AC-4D1D-8D52-20C01CA0EF1F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12 StructToString", "12 StructToString\12 StructToString.csproj", "{D7CB06EE-32B9-499C-9AE7-4391D4AC6438}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12 StructBruch", "12 StructBruch\12 StructBruch.csproj", "{D087E2B4-9E89-4456-ABB6-CCF348CB7E79}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12 StringConcat", "12 StringConcat\12 StringConcat.csproj", "{B4191FF6-95B7-4577-AE98-9B42BC338F5A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -339,6 +349,26 @@ Global {055DDC53-EB6E-43B8-BED5-EC6BEDC87507}.Debug|Any CPU.Build.0 = Debug|Any CPU {055DDC53-EB6E-43B8-BED5-EC6BEDC87507}.Release|Any CPU.ActiveCfg = Release|Any CPU {055DDC53-EB6E-43B8-BED5-EC6BEDC87507}.Release|Any CPU.Build.0 = Release|Any CPU + {0EC7D975-1D95-40B7-BBDF-73A475231A1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0EC7D975-1D95-40B7-BBDF-73A475231A1F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0EC7D975-1D95-40B7-BBDF-73A475231A1F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0EC7D975-1D95-40B7-BBDF-73A475231A1F}.Release|Any CPU.Build.0 = Release|Any CPU + {4EBDD0DB-69AC-4D1D-8D52-20C01CA0EF1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4EBDD0DB-69AC-4D1D-8D52-20C01CA0EF1F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4EBDD0DB-69AC-4D1D-8D52-20C01CA0EF1F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4EBDD0DB-69AC-4D1D-8D52-20C01CA0EF1F}.Release|Any CPU.Build.0 = Release|Any CPU + {D7CB06EE-32B9-499C-9AE7-4391D4AC6438}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7CB06EE-32B9-499C-9AE7-4391D4AC6438}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7CB06EE-32B9-499C-9AE7-4391D4AC6438}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D7CB06EE-32B9-499C-9AE7-4391D4AC6438}.Release|Any CPU.Build.0 = Release|Any CPU + {D087E2B4-9E89-4456-ABB6-CCF348CB7E79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D087E2B4-9E89-4456-ABB6-CCF348CB7E79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D087E2B4-9E89-4456-ABB6-CCF348CB7E79}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D087E2B4-9E89-4456-ABB6-CCF348CB7E79}.Release|Any CPU.Build.0 = Release|Any CPU + {B4191FF6-95B7-4577-AE98-9B42BC338F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4191FF6-95B7-4577-AE98-9B42BC338F5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4191FF6-95B7-4577-AE98-9B42BC338F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4191FF6-95B7-4577-AE98-9B42BC338F5A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- GitLab