Solve task 1
This commit is contained in:
parent
26fc0263c7
commit
a26546e8a4
2 changed files with 23 additions and 8 deletions
|
@ -17,9 +17,20 @@ namespace DT1 {
|
|||
}
|
||||
|
||||
public class StudentClass {
|
||||
public Func<Student, string, bool> studentSelector = /* TO BE DONE */
|
||||
public GradeCalc gradeCalculator = /* TO BE DONE */
|
||||
public Func<Student, bool> passedSelector = /* TO BE DONE */
|
||||
public Func<Student, string, bool> studentSelector = (student, surname) =>
|
||||
{
|
||||
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
|
||||
public List<Student> students = new List<Student> {
|
||||
|
@ -70,15 +81,16 @@ namespace DT1 {
|
|||
}
|
||||
|
||||
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) {
|
||||
if (select(s, lastName)) result.Add(s);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<Student> QueryPassed(Func<Student,bool> passed) {
|
||||
return /* TO BE DONE */
|
||||
public IEnumerable<Student> QueryPassed(Func<Student,bool> passed)
|
||||
{
|
||||
return students.Where(passed);
|
||||
}
|
||||
|
||||
static void show(String titel, List<Student> students) {
|
||||
|
@ -101,7 +113,10 @@ namespace DT1 {
|
|||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Reference in a new issue