E25 Ex 1 - 8

This commit is contained in:
sebi 2025-07-01 16:33:17 +02:00
parent 6acc6db249
commit 6cad6b98b2
8 changed files with 51 additions and 23 deletions

View File

@ -11,13 +11,13 @@ namespace Exercises_C_Sharp.E25_Tuple
public static void Start()
{
//Code START
Meth("Hans", 35);
Meth(("Hans", 35));
//Code ENDE
}
static void Meth(/*CODE START*/string name, int age/*CODE ENDE*/)
static void Meth(/*CODE START*/(string name, int age) va/*CODE ENDE*/)
{
Console.WriteLine("{0} ist {1} Jahre alt.", name, age);
Console.WriteLine("{0} ist {1} Jahre alt.", va.name, va.age);
}
}
}

View File

@ -6,14 +6,14 @@ namespace Exercises_C_Sharp.E25_Tuple
{
class Exercise_2
{
//Ändern Sie die Werte in dem Tuple 'tup', sodass die Werte "Breite2 und 12.9 darin stehen.
//Ändern Sie die Werte in dem Tuple 'tup', sodass die Werte "Breite" und 12.9 darin stehen.
public static void Start()
{
Tuple<string, double> tup = new Tuple<string, double>("Länge", 12.54);
//Code START
tup = new("Breite", 12.9);
//Code ENDE

View File

@ -11,7 +11,7 @@ namespace Exercises_C_Sharp.E25_Tuple
public static void Start()
{
//Code START
dynamic tup = -1;
(string, int, string) tup = ("Mount Everest",8849,"Nepal");
//Code ENDE

View File

@ -14,7 +14,7 @@ namespace Exercises_C_Sharp.E25_Tuple
Console.WriteLine("Das Wort {0} hat {1} den Buchstaben {2} enthalten.", element.Item1, element.Item2, element.Item3);
}
static /*Code START*/dynamic/*Code ENDE*/ Meth()
static /*Code START*/(string, int, char)/*Code ENDE*/ Meth()
{
string s = Console.ReadLine() ?? string.Empty;
int res = 0;
@ -23,7 +23,7 @@ namespace Exercises_C_Sharp.E25_Tuple
res++;
//Code START
return s + res;
return (s, res, 'A');
//Code ENDE
}

View File

@ -9,7 +9,7 @@ namespace Exercises_C_Sharp.E25_Tuple
//Erstellen Sie eine Liste von Tupeln. Sorgen Sie dafür, dass die Liste mit der unteren Methode gefüllt wird. Geben Sie zum Schluss die Elemente aus.
//Code START
static dynamic tupleList = -1;
static List<(string, int)> tupleList = [];
//Code ENDE
public static void Start()
{
@ -24,19 +24,29 @@ namespace Exercises_C_Sharp.E25_Tuple
Console.Clear();
foreach(var element in tupleList)
foreach (var element in tupleList)
{
//Code START
Console.WriteLine("----------------------");
Console.WriteLine("String: " + element.Item1);
Console.WriteLine("Integer: " + element.Item2);
Console.WriteLine("----------------------");
//Code ENDE
}
}
//Diese Methode soll den Nutzer nach einen String und einen int fragen und diese kombination dann in einem Tuple zurück geben. Sorgen Sie dafür, dass der Nutzer valide Werte eingibt.
static /*Code START*/ dynamic /*Code ENDE*/ GetStringAndIntFromUser()
static /*Code START*/ (string, int) /*Code ENDE*/ GetStringAndIntFromUser()
{
//Code START
return -1;
Console.WriteLine("Bitte String eingeben:");
string userinputstring = Console.ReadLine() ?? string.Empty;
Console.WriteLine("Bitte Integer eingeben:");
int userinputint = 0;
while (!int.TryParse(Console.ReadLine(), out userinputint)) ;
return (userinputstring, userinputint);
//Code ENDE
}

View File

@ -9,7 +9,7 @@ namespace Exercises_C_Sharp.E25_Tuple
//Sorgen Sie dafür, dass 7 und 345 ausgegeben wird:
//Code START
static dynamic tupList = -1;
static List<(int, int, int)> tupList = [(345,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0)];
//Code ENDE
public static void Start()
{

View File

@ -11,7 +11,7 @@ namespace Exercises_C_Sharp.E25_Tuple
public static void Start()
{
//Code START
dynamic element = -1;
(string, int) element = ("Elementarelement", 0);
//Code ENDE
Meth(element);

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Collections.Generic;
using Exercises_C_Sharp.E28_Classes;
namespace Exercises_C_Sharp.E25_Tuple
{
@ -10,10 +11,16 @@ namespace Exercises_C_Sharp.E25_Tuple
public static void Start()
{
//Code START
dynamic element = -1;
//Code ENDE
foreach(var item in Meth(element))
List<string> element = [];
while (true)
{
string s = Console.ReadLine() ?? "";
if (s == string.Empty) break;
element.Add(s);
}
//Code ENDE
foreach (var item in Meth(element))
{
//Geben Sie hier die einzelnen Werte in dieser Form aus:
//Haus -> 2 Selbstlaute
//Bauer -> 3 Selbstlaute
@ -21,16 +28,27 @@ namespace Exercises_C_Sharp.E25_Tuple
//Achten Sie auf die deutsche Grammatik!
//Code START
//Code ENDE
}
Console.WriteLine("{0} -> {1} Selbstlaut{2}", item.Item1, item.Item2, item.Item2 != 1 ? "e" : "");
//Code ENDE
}
}
//Sorgen Sie dafür, dass die Methode eine Liste der Strings mit deren Anzahl an Selbstlauten zurück gibt:
static List<Tuple<string,int>> Meth(List<string> stringList)
static List<(string,int)> Meth(List<string> stringList)
{
//Code START
dynamic returnList = -1;
var list = new List<char>() { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
List<(string, int)> returnList = [];
foreach (var element in stringList)
{
int selbstlaute = 0;
foreach (var item in element)
if (list.Contains(item)) selbstlaute++;
returnList.Add((element, selbstlaute));
}
//Code ENDE
return returnList;