Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done block2 #6

Merged
merged 5 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/data_new.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
surname2 firstname3 patronymic3 Ж 06.12.1995 - 3 5 4756
surname4 firstname2 patronymic3 Ж 10.09.1995 2 - 1 3291
surname2 firstname4 patronymic4 Ж 07.05.2004 2 3 3 2103
surname1 firstname1 patronymic2 Ж 05.05.1998 1 - - 2766
surname3 firstname2 patronymic3 Ч 03.02.2001 - 3 1 2260
surname1 firstname1 patronymic2 Ж 12.04.2002 2 3 - 4495
surname4 firstname1 patronymic3 Ж 04.09.2005 3 2 4 4183
surname3 firstname1 patronymic2 Ж 08.07.2004 5 5 2 4345
surname2 firstname2 patronymic1 Ч 22.01.1999 2 1 5 3870
surname1 firstname1 patronymic1 Ч 04.05.2005 4 3 4 3302
surname2 firstname3 patronymic3 Ж 16.12.1995 1 3 5 2801
surname3 firstname2 patronymic3 Ж 24.08.1999 4 5 3 4139
surname4 firstname3 patronymic4 Ч 26.07.1998 2 3 4 2548
surname1 firstname3 patronymic1 Ч 23.06.1998 1 4 - 1092
surname1 firstname3 patronymic2 Ж 15.10.2000 5 3 3 1577
surname2 firstname2 patronymic2 Ч 08.12.2004 3 5 2 4394
surname4 firstname1 patronymic3 Ч 05.08.1998 2 - 2 1404
surname3 firstname4 patronymic3 Ж 15.12.1998 1 3 4 1133
surname3 firstname3 patronymic2 Ч 06.09.2000 2 3 3 1118
surname4 firstname2 patronymic3 Ж 22.12.2003 3 4 3 2677
5 changes: 2 additions & 3 deletions src/main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text;
using System.Text;
namespace struct_lab_student
{
public partial class Program
Expand Down Expand Up @@ -46,8 +46,7 @@ static void RunMenu(List<Student> students)
}
} while (match != 0);
}



static void Main()
{
Console.OutputEncoding = UTF8Encoding.UTF8;
Expand Down
110 changes: 69 additions & 41 deletions src/methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,95 @@ namespace struct_lab_student
{
public partial class Program
{
static void Var9(List<Student> students) { }
static void Var9(List<Student> students)
{
WriteData(ProcessData(students), "data_new.txt");
Console.WriteLine("Дані були успішно записані у файл data_new.txt");
}

static void Var10(List<Student> students)
{
static double CountAverageScore(Student student)
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 = [];

foreach (var student in students)
{
char[] marks = student.Marks;
double sum = 0;
foreach (var c in marks)
{
sum += (c == '-') ? 2 : double.Parse(c.ToString());
}
char sex = student.sex;

This comment was marked as outdated.

if (sex == 'M' || sex == 'м' || sex == 'Ч')
sex = 'Ч';
else if (sex == 'F' || sex == 'ж' || sex == 'Ж')
sex = 'Ж';

return Math.Round(sum / 3, 1);
Student processedStudent = new()
{
surName = student.surName,
firstName = student.firstName,
patronymic = student.patronymic,
sex = sex,
dateOfBirth = student.dateOfBirth,
Marks = student.Marks,
scholarship = student.scholarship
};

processedStudents.Add(processedStudent);
}

static IEnumerable<Student> FilterTalentedPhysicians(List<Student> students)
return processedStudents;
}

static void WriteData(List<Student> students, string filename)
{
try
{
return students.Where(student => student.Marks[1] == '5');
StreamWriter writer = new(filename);
{
foreach (var student in students)
{
writer.WriteLine($"{student.surName,-20} {student.firstName,-20} {student.patronymic,-20} " +
$"{student.sex,-5} {student.dateOfBirth,-12} {student.Marks[0],-5} {student.Marks[1],-5} {student.Marks[2],-5} " +
$"{student.scholarship}");
}
}
}

foreach (var student in FilterTalentedPhysicians(students))
catch (IOException e)
{
Console.WriteLine($"{student.surName} {student.firstName} {student.patronymic} {CountAverageScore(student):0.0} {student.scholarship}");
Console.WriteLine($"Помилка запису у файл: {e.Message}");
}
}

static void Var24(List<Student> students)
public static IEnumerable<Student> Filter(List<Student> students, Func<Student, bool> Condition)
{
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}");
return students.Where(Condition);
}

public static IEnumerable<Student> FilterSummerKids(List<Student> students)
private static bool IsSummer(Student student)
{
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;
});
int month = int.Parse(student.dateOfBirth[3..4]);
return month >= 6 && month <= 8;
}

public static List<double> EvalAverages(IEnumerable<Student>? students)
private static bool IsTalentedPhysician(Student student)
{
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;
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);
}
}
}