Skip to content
Snippets Groups Projects
Commit 45454f09 authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

2021-01-17 Abschluss Prozedurales Programmieren

parent a4f5016c
Branches master
No related tags found
No related merge requests found
Showing with 240 additions and 7 deletions
......@@ -45,6 +45,9 @@ namespace _09_Contains_UebgMo
ContainsTest("aaabcdef", "def");
ContainsTest("def","aaabcdef");
ContainsTest("bababi", "babi");
ContainsTest("bababi", "");
}
}
}
......@@ -16,7 +16,7 @@ namespace _10_StreamWriterIntro
wr.WriteLine();
}
wr.Close();
// wr.Close(); kann bei Verwendung von using entfallen
}
}
}
......@@ -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;
......
......@@ -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");
}
}
}
}
}
}
......@@ -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);
}
}
}
......@@ -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)
{
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_14_QuersummeSchleife</RootNamespace>
</PropertyGroup>
</Project>
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);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_14_WerteVsReftypen</RootNamespace>
</PropertyGroup>
</Project>
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
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_14_WoerterZaehlen</RootNamespace>
</PropertyGroup>
</Project>
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 "));
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_14_Zifferntest</RootNamespace>
</PropertyGroup>
</Project>
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));
}
}
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment