diff --git a/09 Contains_UebgMo/Program.cs b/09 Contains_UebgMo/Program.cs index 2900d3211e64dcea8bca65c3ec97356dde3d6592..aa09c9b49af5fce64a714e3325b4505b6cbe87e2 100644 --- a/09 Contains_UebgMo/Program.cs +++ b/09 Contains_UebgMo/Program.cs @@ -45,6 +45,9 @@ namespace _09_Contains_UebgMo ContainsTest("aaabcdef", "def"); ContainsTest("def","aaabcdef"); + ContainsTest("bababi", "babi"); + ContainsTest("bababi", ""); + } } } diff --git a/10 StreamWriterIntro/Program.cs b/10 StreamWriterIntro/Program.cs index ec066d100ea1ce56e430151d827cb2c0cfc8f00b..bd6175d174cc79e1042e1f9601fbac5822d874d7 100644 --- a/10 StreamWriterIntro/Program.cs +++ b/10 StreamWriterIntro/Program.cs @@ -16,7 +16,7 @@ namespace _10_StreamWriterIntro wr.WriteLine(); } - wr.Close(); + // wr.Close(); kann bei Verwendung von using entfallen } } } diff --git a/10 StreamsIntro/Program.cs b/10 StreamsIntro/Program.cs index 766ad4d7bdddab1bcba55059bcdfdcdf3f6e7321..30f448ef97179be5e907f5c8bbee3fdf4c5753d1 100644 --- a/10 StreamsIntro/Program.cs +++ b/10 StreamsIntro/Program.cs @@ -10,7 +10,7 @@ namespace _10_StreamsIntro //string s = Console.ReadLine(); //StreamReader sr = new StreamReader(@"C:\Users\wienkop\source\repos\Prog1_WS2021_22\10 StreamsIntro\Verkaeufe.txt"); - StreamReader sr = new StreamReader(@"..\..\..\Verkaeufe.txt"); + using StreamReader sr = new StreamReader(@"..\..\..\Verkaeufe.txt"); // Öffnet die Datei / den Stream string zeile; diff --git a/13 DiesUndDas/Program.cs b/13 DiesUndDas/Program.cs index c9ace4a69326560ec39f781b171e5e1330ed9836..4443521511ed563bb96cc5e22b3779afaf680d31 100644 --- a/13 DiesUndDas/Program.cs +++ b/13 DiesUndDas/Program.cs @@ -31,7 +31,35 @@ namespace _13_DiesUndDas Console.WriteLine("44" + (10 + 2).ToString()); // "44" + 12 --> "4412" - bool x = (bool)1; + int x1 = 'A'; // = 65 (aus der ASCII-Tabelle) + char c1 = (char) 65; + int x2 = (int) 3.14; + int x3 = (int)3.99999; Math.Round(3.5); + int x4 = Convert.ToInt32(3.54); + + foreach (int i in new int[] { 8, 21, 20, 9 }) + { + if (i % 2 == 0) + { + if (i >= 0 && i <= 10) + { + Console.Write("A"); + } + + } + else + { + if (i < 0 || i % 3 == 0) + { + Console.Write("B"); + } + else + { + Console.Write("C"); + } + } + } + } } } diff --git a/13 Personalverwaltung_Klausur2015/Program.cs b/13 Personalverwaltung_Klausur2015/Program.cs index 7b3dae5eb2b9242d0bd74cf018a3703650b1d21c..fce779fd5323c26ed6e796e4e0cfd2795e6ce6b1 100644 --- a/13 Personalverwaltung_Klausur2015/Program.cs +++ b/13 Personalverwaltung_Klausur2015/Program.cs @@ -5,7 +5,7 @@ namespace _13_Personalverwaltung_Klausur2015 enum Eingruppierung { Angestellter, Gruppenleiter, Abteilungsleiter } // Eingruppierung ~ neuer DATENTYP (analog zu int, bool, double, ...) // Konsequenz: Es müssen noch Variablen dieses Datentyps angelegt werden! - class Person + struct Person { public string name; public double gehalt; @@ -68,6 +68,8 @@ namespace _13_Personalverwaltung_Klausur2015 Person px = SuchePerson(persFeld, "xxx"); if (px.id == 0) Console.WriteLine("Suche erfolglos"); + string s = px.ToString(); + Console.WriteLine(px); } } } diff --git a/13 StructPersonalausweis/Program.cs b/13 StructPersonalausweis/Program.cs index d252143fb9f7671e99f4016065a38474f5870896..5e26e1393ca2e84cd7f7a9dc81be34809d7fb84b 100644 --- a/13 StructPersonalausweis/Program.cs +++ b/13 StructPersonalausweis/Program.cs @@ -5,7 +5,10 @@ namespace _13_StructPersonalausweis struct Personalausweis { public string name, vorname; - public int id; + public int id; // private ~ Nur Methoden der struct Personalausweis + // dürfen auf dieses Feld zugreifen + // public ~ Methoden aller Klassen und structs dürfen + // auf dieses Feld zugreifen public Personalausweis(string Name, string Vorname, int Id) { diff --git a/14 QuersummeSchleife/14 QuersummeSchleife.csproj b/14 QuersummeSchleife/14 QuersummeSchleife.csproj new file mode 100644 index 0000000000000000000000000000000000000000..cf9c011a9e86fb77a117d52b138004108e671f74 --- /dev/null +++ b/14 QuersummeSchleife/14 QuersummeSchleife.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_14_QuersummeSchleife</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/14 QuersummeSchleife/Program.cs b/14 QuersummeSchleife/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..b8042fec8730f6b9a4110b3d823c050549a33ac3 --- /dev/null +++ b/14 QuersummeSchleife/Program.cs @@ -0,0 +1,27 @@ +using System; + +namespace _14_QuersummeSchleife +{ + class Program + { + static void Main(string[] args) + { + do + { + int quersum = 0; + Console.WriteLine("Zahl eingeben: "); + int zahl = Convert.ToInt32(Console.ReadLine()); + + if (zahl == 0) + break; + + while (zahl > 0) + { + quersum += zahl % 10; + zahl /= 10; + } + Console.WriteLine($"Quersumme: {quersum}"); + } while (true); + } + } +} diff --git a/14 WerteVsReftypen/14 WerteVsReftypen.csproj b/14 WerteVsReftypen/14 WerteVsReftypen.csproj new file mode 100644 index 0000000000000000000000000000000000000000..26efffcdb60830a3eb6fba05e18e0226b9e8ea07 --- /dev/null +++ b/14 WerteVsReftypen/14 WerteVsReftypen.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_14_WerteVsReftypen</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/14 WerteVsReftypen/Program.cs b/14 WerteVsReftypen/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..d1d2e41e54d90a758bf099859047b7dca1578c9f --- /dev/null +++ b/14 WerteVsReftypen/Program.cs @@ -0,0 +1,37 @@ +using System; + +namespace _14_WerteVsReftypen +{ + struct CoordVal { public int x, y; } + class CoordRef { public int x, y; } + class Program + { + public static void TueVal(CoordVal cv) + { + cv.x++; + } + + static void TueVal(ref CoordVal cv) + { + cv.x++; + } + + static void TueRef(CoordRef cv) + { + cv = new CoordRef(); + cv.x++; + } + static void Main(string[] args) + { + CoordVal c1; + c1.x = 10; + c1.y = 15; + CoordRef c1r; + c1r = new CoordRef(); + + TueVal(c1); // Von Wertevar. wird eine KOPIE des Werts / aller Felder des structs übergeben + TueRef(c1r); // Von Referenzvar. wird eine KOPIE der Referenz übergeben + TueVal(ref c1); // Es wird eine Referenz auf c1 (Speicheradr. von c1) an TueVal übergeben + } + } +} diff --git a/14 WoerterZaehlen/14 WoerterZaehlen.csproj b/14 WoerterZaehlen/14 WoerterZaehlen.csproj new file mode 100644 index 0000000000000000000000000000000000000000..0bc40ffac3c472ee3c5e3daa70f424d394f573fb --- /dev/null +++ b/14 WoerterZaehlen/14 WoerterZaehlen.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_14_WoerterZaehlen</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/14 WoerterZaehlen/Program.cs b/14 WoerterZaehlen/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..4d5633847356f33f31ad4bf852017a797d9a00d6 --- /dev/null +++ b/14 WoerterZaehlen/Program.cs @@ -0,0 +1,45 @@ +using System; + +namespace _14_WoerterZaehlen +{ + class Program + { + static int ZaehleWoerter(string s) + { + // 1. Wortanfang finden (Sonderzeichen überspringen) + // 2. Wortzähler erhöhen + // 3. Wort durchlaufen + // Bsp.: " Hallo Welt und hello World " + int anz = 0; + int ind = 0; + while (ind < s.Length) + { + while (ind < s.Length && s[ind] == ' ') + ind++; + + if (ind < s.Length) + anz++; + + while (ind < s.Length && s[ind] != ' ') + ind++; + } + return anz; + } + + static string LeerzeichenEntfernen(string s) + { + string erg = "" + s[0]; + for (int i = 1; i < s.Length; i++) + { + if (!(s[i] == ' ' && s[i - 1] == ' ')) + erg += s[i]; + } + return erg; + } + static void Main(string[] args) + { + Console.WriteLine(LeerzeichenEntfernen(" Hallo Welt und hello World")); + Console.WriteLine(ZaehleWoerter(" Hallo Welt und hello World ")); + } + } +} diff --git a/14 Zifferntest/14 Zifferntest.csproj b/14 Zifferntest/14 Zifferntest.csproj new file mode 100644 index 0000000000000000000000000000000000000000..cfd977bdea28a891f62b9fab89cb1218eec9385c --- /dev/null +++ b/14 Zifferntest/14 Zifferntest.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_14_Zifferntest</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/14 Zifferntest/Program.cs b/14 Zifferntest/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..9cce58ca186870d14034918a6c788e9818671b58 --- /dev/null +++ b/14 Zifferntest/Program.cs @@ -0,0 +1,28 @@ +using System; + +namespace _14_Zifferntest +{ + class Program + { + static bool Zifferntest(int n) + { + if (n <= 0) + throw new ArgumentOutOfRangeException("Die Zahl n muss echt größer 0 sein!"); + + int zahl = n; + while (n>0) + { + int letzteZiffer = n % 10; // 123/10 -> 12, 123%10 -> 3 + if (letzteZiffer != 0 && zahl % letzteZiffer != 0) + return false; + n /= 10; + } + return true; + } + static void Main(string[] args) + { + Console.WriteLine(Zifferntest(101)); + Console.WriteLine(Zifferntest(125)); + } + } +} diff --git a/Prog1_WS2021_22.sln b/Prog1_WS2021_22.sln index 2edc69bedc2cf3cf776c03035d94855b8596c351..191795be39bd3c7fa15220df8bca04fb1c1e2a17 100644 --- a/Prog1_WS2021_22.sln +++ b/Prog1_WS2021_22.sln @@ -137,9 +137,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13 SchriftlichAddieren", "1 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13 StructPersonalausweis", "13 StructPersonalausweis\13 StructPersonalausweis.csproj", "{3E44868E-6C68-4080-A071-94EDD05624AD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 Personalverwaltung_Klausur2015", "13 Personalverwaltung_Klausur2015\13 Personalverwaltung_Klausur2015.csproj", "{C155A7D4-BCFE-4984-95DE-A9406F96929E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13 Personalverwaltung_Klausur2015", "13 Personalverwaltung_Klausur2015\13 Personalverwaltung_Klausur2015.csproj", "{C155A7D4-BCFE-4984-95DE-A9406F96929E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 throw", "13 throw\13 throw.csproj", "{EF692969-7849-446C-B9BD-EEBEF51C5C9C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13 throw", "13 throw\13 throw.csproj", "{EF692969-7849-446C-B9BD-EEBEF51C5C9C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "14 Zifferntest", "14 Zifferntest\14 Zifferntest.csproj", "{EEAFB9BD-8D54-47DD-B580-1E8AE707CCF3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "14 QuersummeSchleife", "14 QuersummeSchleife\14 QuersummeSchleife.csproj", "{0D3EE0BA-9BAC-41F1-8EBE-7D9CD88258A0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "14 WerteVsReftypen", "14 WerteVsReftypen\14 WerteVsReftypen.csproj", "{BFC88FD7-E039-4B89-8EA2-01941C7EC3FC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "14 WoerterZaehlen", "14 WoerterZaehlen\14 WoerterZaehlen.csproj", "{0B632D4E-DCF1-436A-B3D0-C8DF9BA0EDC0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -423,6 +431,22 @@ Global {EF692969-7849-446C-B9BD-EEBEF51C5C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU {EF692969-7849-446C-B9BD-EEBEF51C5C9C}.Release|Any CPU.ActiveCfg = Release|Any CPU {EF692969-7849-446C-B9BD-EEBEF51C5C9C}.Release|Any CPU.Build.0 = Release|Any CPU + {EEAFB9BD-8D54-47DD-B580-1E8AE707CCF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EEAFB9BD-8D54-47DD-B580-1E8AE707CCF3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EEAFB9BD-8D54-47DD-B580-1E8AE707CCF3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EEAFB9BD-8D54-47DD-B580-1E8AE707CCF3}.Release|Any CPU.Build.0 = Release|Any CPU + {0D3EE0BA-9BAC-41F1-8EBE-7D9CD88258A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D3EE0BA-9BAC-41F1-8EBE-7D9CD88258A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D3EE0BA-9BAC-41F1-8EBE-7D9CD88258A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D3EE0BA-9BAC-41F1-8EBE-7D9CD88258A0}.Release|Any CPU.Build.0 = Release|Any CPU + {BFC88FD7-E039-4B89-8EA2-01941C7EC3FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BFC88FD7-E039-4B89-8EA2-01941C7EC3FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BFC88FD7-E039-4B89-8EA2-01941C7EC3FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BFC88FD7-E039-4B89-8EA2-01941C7EC3FC}.Release|Any CPU.Build.0 = Release|Any CPU + {0B632D4E-DCF1-436A-B3D0-C8DF9BA0EDC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B632D4E-DCF1-436A-B3D0-C8DF9BA0EDC0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B632D4E-DCF1-436A-B3D0-C8DF9BA0EDC0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B632D4E-DCF1-436A-B3D0-C8DF9BA0EDC0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE