Skip to content

Commit

Permalink
🚧: var 24 done, needs testing
Browse files Browse the repository at this point in the history
  • Loading branch information
flovnes committed Apr 27, 2024
1 parent dd86a02 commit 01b7197
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@ namespace struct_lab_student {
public partial class Program {
static void Var9(List<Student> students) { }
static void Var10(List<Student> students) { }
static void Var24(List<Student> students) { }
}
static void Var24(List<Student> students) {
var summer_kids = FilterSummerKids(students);
foreach (var (dude, avg) in summer_kids.Zip(EvalAverages(summer_kids)))
Console.WriteLine($"{dude.surName} {dude.firstName} {avg:0.0}");
}

public static IEnumerable<Student> FilterSummerKids(List<Student> students) {
return students.Where(student => {
if (DateTime.TryParseExact(student.dateOfBirth, "dd.MM.yyyy", null, System.Globalization.DateTimeStyles.None,
out DateTime date)
){
return date.Month >= 6 && date.Month <= 8;
}
return false;
});
}

public static List<double> EvalAverages(IEnumerable<Student>? students) {
List<double> averages = [];
if (students != null) {
foreach (var dude in students) {
int sum = 0;
for (int i = 0; i < 3; i++) sum += (dude.Marks[i] == '-') ? 2 : dude.Marks[i] - '0';
averages.Add(sum / 3.0);
}
}
return averages;
}
}
}

0 comments on commit 01b7197

Please sign in to comment.