Skip to content

Commit

Permalink
Update methods.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mffn-rscl authored Apr 29, 2024
1 parent 0cb22b6 commit 4dafc61
Showing 1 changed file with 48 additions and 12 deletions.
60 changes: 48 additions & 12 deletions src/methods.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
namespace struct_lab_student {
public partial class Program {
namespace struct_lab_student
{
public partial class Program
{
static void Var9(List<Student> students)
{
var processedStudents = ProcessData(students);
WriteData(processedStudents, "data_new.txt");
Console.WriteLine("Дані були успішно переписані у файл data_new.txt");
WriteData(ProcessData(students), "data_new.txt");
Console.WriteLine("Дані були успішно записані у файл data_new.txt");
}

static void Var10(List<Student> students)
{
foreach (var student in Filter(students, IsTalentedPhysician))
Console.WriteLine($"{student.surName} {student.firstName} {student.patronymic} {EvalAverage(student):0.0} {student.scholarship}");
}

static void Var24(List<Student> students)
{
var summer_kids = Filter(students, IsSummer);
foreach (var dude in summer_kids)
Console.WriteLine($"{dude.surName} {dude.firstName} {EvalAverage(dude)}");
}

static List<Student> ProcessData(List<Student> students)
{
List<Student> processedStudents = new List<Student>();
List<Student> processedStudents = [];

foreach (var student in students)
{
Expand All @@ -19,7 +33,8 @@ static List<Student> ProcessData(List<Student> students)
else if (sex == 'F' || sex == 'ж' || sex == 'Ж')
sex = 'Ж';

Student processedStudent = new Student {
Student processedStudent = new()
{
surName = student.surName,
firstName = student.firstName,
patronymic = student.patronymic,
Expand All @@ -39,7 +54,7 @@ static void WriteData(List<Student> students, string filename)
{
try
{
using (StreamWriter writer = new StreamWriter(filename))
StreamWriter writer = new(filename);
{
foreach (var student in students)
{
Expand All @@ -54,7 +69,28 @@ static void WriteData(List<Student> students, string filename)
Console.WriteLine($"Помилка запису у файл: {e.Message}");
}
}
static void Var10(List<Student> students) { }
static void Var24(List<Student> students) { }
}
}

public static IEnumerable<Student> Filter(List<Student> students, Func<Student, bool> Condition)
{
return students.Where(Condition);
}

private static bool IsSummer(Student student)
{
int month = int.Parse(student.dateOfBirth[3..4]);
return month >= 6 && month <= 8;
}

private static bool IsTalentedPhysician(Student student)
{
return student.Marks[1] == '5';
}

public static double EvalAverage(Student student)
{
double sum = 0;
foreach (var c in student.Marks) sum += (c == '-') ? 2 : double.Parse(c.ToString());
return Math.Round(sum / 3, 1);
}
}
}

0 comments on commit 4dafc61

Please sign in to comment.