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

2021-01-11

parent bd4d532a
No related branches found
No related tags found
No related merge requests found
......@@ -18,11 +18,14 @@ namespace _10_StreamsIntro
while (!sr.EndOfStream)
// Solange das Dateiende noch nicht erreicht ist
{
zeile = sr.ReadLine();
zeile = sr.ReadLine(); // zeile = "Brötchen 8 0,35"
// Aus der Datei eine Zeile lesen
// und dann geeignet damit arbeiten
//Console.WriteLine(zeile);
string[] daten = zeile.Split(' ');
// string[3] : daten[0] = "Brötchen"
// daten[1] = "8"
// daten[2] = "0,35"
int anz = Convert.ToInt32(daten[1]); // daten[1] ~ 8
double preis = Convert.ToDouble(daten[2]); // daten[2] ~ Einzelpreis
......
......@@ -20,5 +20,9 @@ namespace _12_Fibonacci
Console.WriteLine($"{i,2} | {Fib(i)}");
}
}
// Fib(4) --> Fib(3):3 + Fib(2):2 --> 5
// Fib(3) --> Fib(2):2 + Fib(1):1 --> 3
// Fib(2) --> Fib(1) + Fib(0) --> 2
// Fib(2) --> Fib(1) + Fib(0) --> 2 aus ... + Fib(2)
}
}
......@@ -19,7 +19,7 @@ namespace _12_Params
{
int[] werte = { 1, 2, 3, 4, 5, 6, 7 };
DoIt(1, 2);
DoIt("Hallo", 2, 3);
DoIt("Hallo", 2, 3, 4, 5);
DoIt("Hallo", new int[] { 2, 3 });
DoIt("Hallo", werte);
......
......@@ -26,8 +26,12 @@ namespace _13_DiesUndDas
f[y--] = 10; // f[3] = 10; y--; --> y=2;
// oder
f[--y] = 10; // y--; --> y=2; f[2] = 10;
// (1 + 2) + 3
Console.WriteLine(("44" + 10.ToString()) + 2.ToString()); // "44" + 10 --> "4410" --> "44102"
Console.WriteLine("44" + (10 + 2).ToString()); // "44" + 12 --> "4412"
bool x = (bool)1;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_13_Personalverwaltung_Klausur2015</RootNamespace>
</PropertyGroup>
</Project>
using System;
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
{
public string name;
public double gehalt;
public Eingruppierung eingruppierung;
public int id;
public Person(string Name, double Gehalt, Eingruppierung _eingruppierung, int Id)
{
name = Name;
gehalt = Gehalt;
eingruppierung = _eingruppierung;
id = Id;
}
}
class Program
{
static Person NeuePerson(string Name, double Gehalt, Eingruppierung _eingruppierung, int Id)
{
Person p;
p.name = Name;
p.gehalt = Gehalt;
p.eingruppierung = _eingruppierung;
p.id = Id;
return p;
}
static double Gehaltvolumen(Person[] personenFeld, Eingruppierung mitarbeitertyp)
{
double sum = 0;
foreach (Person person in personenFeld)
{
if (person.eingruppierung == mitarbeitertyp)
sum += person.gehalt;
// if (personenFeld[i].eingruppierung == mitarbeitertyp)
// sum += personenFeld[i].gehalt;
}
return sum;
}
static Person SuchePerson(Person[] personenFeld, string name)
{
foreach (Person person in personenFeld)
{
if (person.name == name)
return person;
}
return NeuePerson("", 0, 0, 0); // Person ist ein struct, d.h. ein Wertetyp,
// somit ist kein null Wert zulässig!!!
//return null; geht somit nicht!!!
}
// Alternativ: Einen Index zurückliefern, -1 für "nicht gefunden"
static void Main(string[] args)
{
Person[] persFeld = new Person[3];
persFeld[0] = NeuePerson("Huber", 3000, Eingruppierung.Angestellter, 1000);
persFeld[1] = new Person("Meier", 3200, Eingruppierung.Abteilungsleiter, 1001);
persFeld[2] = NeuePerson("Schuster", 2500, Eingruppierung.Angestellter, 1002);
Console.WriteLine($"Gehaltvolumen der Angestellten: {Gehaltvolumen(persFeld, Eingruppierung.Angestellter)}");
Person px = SuchePerson(persFeld, "xxx");
if (px.id == 0)
Console.WriteLine("Suche erfolglos");
}
}
}
......@@ -4,6 +4,9 @@ namespace _13_SchriftlichAddieren
{
class Program
{
// '0' - 48
// '1' - 49
// '9' - 57
static string Addiere(string z1, string z2)
{
// return (Convert.ToInt32(z1) + Convert.ToInt32(z2)).ToString();
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_13_throw</RootNamespace>
</PropertyGroup>
</Project>
using System;
namespace _13_throw
{
class Program
{
static int TueEtwas(int n) // n muss dreistellige Zahl sein
{
if (n < 100 || n > 999)
throw new Exception("n muss eine dreistellige Zahl sein");
//{
// Console.WriteLine("n muss eine dreistellige Zahl sein");
// return -1;
//}
int x = (int) Math.Sqrt(25);
return x;
}
static void Main(string[] args)
{
bool wiederholung;
do
{
try
{
wiederholung = false;
int x = Convert.ToInt32(Console.ReadLine());
int k = TueEtwas(x);
k = TueEtwas(x + 100);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
wiederholung = true;
}
} while (wiederholung == true);
//int k = TueEtwas(101);
//if (k < 0)
// Console.WriteLine("Fehlerfall");
//else
// Console.WriteLine("Gutfall");
//k = TueEtwas(25);
//if (k < 0)
// Console.WriteLine("Fehlerfall");
//else
// Console.WriteLine("Gutfall");
}
}
}
......@@ -131,11 +131,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 StructLehrveranstaltungs
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "12 Mediendaten (alte Klausur)", "12 Mediendaten (alte Klausur)\12 Mediendaten (alte Klausur).csproj", "{6009194F-17E8-4EAA-B29E-47FA15EC53C9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 DiesUndDas", "13 DiesUndDas\13 DiesUndDas.csproj", "{CB47C423-B137-4CFB-A535-AF9C74323C00}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13 DiesUndDas", "13 DiesUndDas\13 DiesUndDas.csproj", "{CB47C423-B137-4CFB-A535-AF9C74323C00}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 SchriftlichAddieren", "13 SchriftlichAddieren\13 SchriftlichAddieren.csproj", "{8E73624E-93CD-4670-B8E9-408F4385F686}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "13 SchriftlichAddieren", "13 SchriftlichAddieren\13 SchriftlichAddieren.csproj", "{8E73624E-93CD-4670-B8E9-408F4385F686}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 StructPersonalausweis", "13 StructPersonalausweis\13 StructPersonalausweis.csproj", "{3E44868E-6C68-4080-A071-94EDD05624AD}"
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}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13 throw", "13 throw\13 throw.csproj", "{EF692969-7849-446C-B9BD-EEBEF51C5C9C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -411,6 +415,14 @@ Global
{3E44868E-6C68-4080-A071-94EDD05624AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E44868E-6C68-4080-A071-94EDD05624AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E44868E-6C68-4080-A071-94EDD05624AD}.Release|Any CPU.Build.0 = Release|Any CPU
{C155A7D4-BCFE-4984-95DE-A9406F96929E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C155A7D4-BCFE-4984-95DE-A9406F96929E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C155A7D4-BCFE-4984-95DE-A9406F96929E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C155A7D4-BCFE-4984-95DE-A9406F96929E}.Release|Any CPU.Build.0 = Release|Any CPU
{EF692969-7849-446C-B9BD-EEBEF51C5C9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
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