Solve task 1

This commit is contained in:
Manuel Thalmann 2024-03-01 13:05:10 +01:00
parent 26fc0263c7
commit a26546e8a4
2 changed files with 23 additions and 8 deletions

View file

@ -17,9 +17,20 @@ namespace DT1 {
} }
public class StudentClass { public class StudentClass {
public Func<Student, string, bool> studentSelector = /* TO BE DONE */ public Func<Student, string, bool> studentSelector = (student, surname) =>
public GradeCalc gradeCalculator = /* TO BE DONE */ {
public Func<Student, bool> passedSelector = /* TO BE DONE */ return string.Compare(student.LastName, surname, true) == 0;
};
public GradeCalc gradeCalculator = (grades) =>
{
return Math.Round(((grades.Average() / 100 * 5) + 1) * 2, MidpointRounding.AwayFromZero) / 2;
};
public Func<Student, bool> passedSelector = (student) =>
{
return student.Year == GradeLevel.FourthYear && student.Grade >= 4;
};
#region data #region data
public List<Student> students = new List<Student> { public List<Student> students = new List<Student> {
@ -70,15 +81,16 @@ namespace DT1 {
} }
public List<Student> SearchStudent(Func<Student, string, bool> select, String lastName) { public List<Student> SearchStudent(Func<Student, string, bool> select, String lastName) {
List<Student> result = new List<Student>(); List<Student> result = new() { };
foreach (Student s in students) { foreach (Student s in students) {
if (select(s, lastName)) result.Add(s); if (select(s, lastName)) result.Add(s);
} }
return result; return result;
} }
public IEnumerable<Student> QueryPassed(Func<Student,bool> passed) { public IEnumerable<Student> QueryPassed(Func<Student,bool> passed)
return /* TO BE DONE */ {
return students.Where(passed);
} }
static void show(String titel, List<Student> students) { static void show(String titel, List<Student> students) {
@ -101,7 +113,10 @@ namespace DT1 {
} }
public static class ListUtils { public static class ListUtils {
public static IEnumerable<T> ... /* TO BE DONE */ public static IEnumerable<T> What<T>(this IList<T> list, Func<T, bool> selector)
{
return list.Where(selector);
}
} }
} }

View file

@ -4,7 +4,7 @@
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>disable</Nullable>
</PropertyGroup> </PropertyGroup>
</Project> </Project>