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

2021-12-20 Wiederholung&Vertiefung

parent 8d94aad8
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_12_PW_Check__SoSe2019_</RootNamespace>
</PropertyGroup>
</Project>
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!");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_12_Params</RootNamespace>
</PropertyGroup>
</Project>
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
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_12_StringConcat</RootNamespace>
</PropertyGroup>
</Project>
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"
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_12_StructBruch</RootNamespace>
</PropertyGroup>
</Project>
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);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_12_StructToString</RootNamespace>
</PropertyGroup>
</Project>
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);
}
}
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment