From a5067335b73b3091a888bbf80632340abf46dc09 Mon Sep 17 00:00:00 2001 From: rascal Date: Tue, 30 Apr 2024 00:05:11 +0300 Subject: [PATCH 1/4] gaben gimme arcana --- src/data_new.txt | 20 ++++++++++++ src/main.cs | 1 + src/methods.cs | 55 +++++++++++++++++++++++++++++++- t.cs | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 src/data_new.txt create mode 100644 t.cs diff --git a/src/data_new.txt b/src/data_new.txt new file mode 100644 index 0000000..a09fcb9 --- /dev/null +++ b/src/data_new.txt @@ -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 diff --git a/src/main.cs b/src/main.cs index 37296a4..9beb89f 100644 --- a/src/main.cs +++ b/src/main.cs @@ -1,4 +1,5 @@ using System.Text; + namespace struct_lab_student { public partial class Program { static List ReadData(string fileName) { diff --git a/src/methods.cs b/src/methods.cs index b2f8ab8..8793159 100644 --- a/src/methods.cs +++ b/src/methods.cs @@ -1,6 +1,59 @@ namespace struct_lab_student { public partial class Program { - static void Var9(List students) { } + static void Var9(List students) + { + var processedStudents = ProcessData(students); + WriteData(processedStudents, "data_new.txt"); + Console.WriteLine("Дані були успішно переписані у файл data_new.txt"); + } + + static List ProcessData(List students) + { + List processedStudents = new List(); + + foreach (var student in students) + { + char sex = student.sex; + if (sex == 'M' || sex == 'м' || sex == 'Ч') + sex = 'Ч'; + else if (sex == 'F' || sex == 'ж' || sex == 'Ж') + sex = 'Ж'; + + Student processedStudent = new Student { + surName = student.surName, + firstName = student.firstName, + patronymic = student.patronymic, + sex = sex, + dateOfBirth = student.dateOfBirth, + Marks = student.Marks, + scholarship = student.scholarship + }; + + processedStudents.Add(processedStudent); + } + + return processedStudents; + } + + static void WriteData(List students, string filename) + { + try + { + using (StreamWriter writer = new StreamWriter(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}"); + } + } + } + catch (IOException e) + { + Console.WriteLine($"Помилка запису у файл: {e.Message}"); + } + } static void Var10(List students) { } static void Var24(List students) { } } diff --git a/t.cs b/t.cs new file mode 100644 index 0000000..9a2cb86 --- /dev/null +++ b/t.cs @@ -0,0 +1,81 @@ +using System; +using System.IO; + +namespace struct_lab_student +{ + public struct Student + { + public string surName; + public string firstName; + public string patronymic; + public char sex; + public string dateOfBirth; + public char[] Marks; + public int schoolarship; + + public override string ToString() + { + return surName + " " + firstName + " " + patronymic + " " + dateOfBirth; + } + + public Student(string line) + { + string[] fields = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); + surName = fields[0]; + firstName = fields[1]; + patronymic = fields[2]; + sex = char.Parse(fields[3]); + dateOfBirth = fields[4]; + Marks = new char[] { char.Parse(fields[5]), char.Parse(fields[6]), char.Parse(fields[7]) }; + schoolarship = int.Parse(fields[8]); + } + } + + class Program + { + static void Main(string[] args) + { + Student[] students = ReadData("input.txt"); + ProcessData(students); + WriteData(students, "data_new.txt"); + Console.WriteLine("Дані були успішно переписані у файл data_new.txt"); + } + + static Student[] ReadData(string filename) + { + string[] lines = File.ReadAllLines(filename); + Student[] students = new Student[lines.Length]; + + for (int i = 0; i < lines.Length; i++) + { + students[i] = new Student(lines[i]); + } + + return students; + } + + static void ProcessData(Student[] students) + { + for (int i = 0; i < students.Length; i++) + { + if (students[i].sex == 'M' || students[i].sex == 'м' || students[i].sex == 'Ч') + students[i].sex = 'Ч'; + else if (students[i].sex == 'F' || students[i].sex == 'ж' || students[i].sex == 'Ж') + students[i].sex = 'Ж'; + } +} + + static void WriteData(Student[] students, string filename) + { + using (StreamWriter writer = new StreamWriter(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.schoolarship}"); + } + } + } + } +} From 0cb22b6db758c863c96650fa0ab68295affae37d Mon Sep 17 00:00:00 2001 From: rscl <129153593+mffn-rscl@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:54:28 +0300 Subject: [PATCH 2/4] Delete t.cs --- t.cs | 81 ------------------------------------------------------------ 1 file changed, 81 deletions(-) delete mode 100644 t.cs diff --git a/t.cs b/t.cs deleted file mode 100644 index 9a2cb86..0000000 --- a/t.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.IO; - -namespace struct_lab_student -{ - public struct Student - { - public string surName; - public string firstName; - public string patronymic; - public char sex; - public string dateOfBirth; - public char[] Marks; - public int schoolarship; - - public override string ToString() - { - return surName + " " + firstName + " " + patronymic + " " + dateOfBirth; - } - - public Student(string line) - { - string[] fields = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); - surName = fields[0]; - firstName = fields[1]; - patronymic = fields[2]; - sex = char.Parse(fields[3]); - dateOfBirth = fields[4]; - Marks = new char[] { char.Parse(fields[5]), char.Parse(fields[6]), char.Parse(fields[7]) }; - schoolarship = int.Parse(fields[8]); - } - } - - class Program - { - static void Main(string[] args) - { - Student[] students = ReadData("input.txt"); - ProcessData(students); - WriteData(students, "data_new.txt"); - Console.WriteLine("Дані були успішно переписані у файл data_new.txt"); - } - - static Student[] ReadData(string filename) - { - string[] lines = File.ReadAllLines(filename); - Student[] students = new Student[lines.Length]; - - for (int i = 0; i < lines.Length; i++) - { - students[i] = new Student(lines[i]); - } - - return students; - } - - static void ProcessData(Student[] students) - { - for (int i = 0; i < students.Length; i++) - { - if (students[i].sex == 'M' || students[i].sex == 'м' || students[i].sex == 'Ч') - students[i].sex = 'Ч'; - else if (students[i].sex == 'F' || students[i].sex == 'ж' || students[i].sex == 'Ж') - students[i].sex = 'Ж'; - } -} - - static void WriteData(Student[] students, string filename) - { - using (StreamWriter writer = new StreamWriter(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.schoolarship}"); - } - } - } - } -} From 4dafc614b62900e9c05168276ea7a71ffc451e88 Mon Sep 17 00:00:00 2001 From: rscl <129153593+mffn-rscl@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:57:47 +0300 Subject: [PATCH 3/4] Update methods.cs --- src/methods.cs | 60 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/methods.cs b/src/methods.cs index 8793159..4fde281 100644 --- a/src/methods.cs +++ b/src/methods.cs @@ -1,15 +1,29 @@ -namespace struct_lab_student { - public partial class Program { +namespace struct_lab_student +{ + public partial class Program + { static void Var9(List 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 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 students) + { + var summer_kids = Filter(students, IsSummer); + foreach (var dude in summer_kids) + Console.WriteLine($"{dude.surName} {dude.firstName} {EvalAverage(dude)}"); } static List ProcessData(List students) { - List processedStudents = new List(); + List processedStudents = []; foreach (var student in students) { @@ -19,7 +33,8 @@ static List ProcessData(List students) else if (sex == 'F' || sex == 'ж' || sex == 'Ж') sex = 'Ж'; - Student processedStudent = new Student { + Student processedStudent = new() + { surName = student.surName, firstName = student.firstName, patronymic = student.patronymic, @@ -39,7 +54,7 @@ static void WriteData(List students, string filename) { try { - using (StreamWriter writer = new StreamWriter(filename)) + StreamWriter writer = new(filename); { foreach (var student in students) { @@ -54,7 +69,28 @@ static void WriteData(List students, string filename) Console.WriteLine($"Помилка запису у файл: {e.Message}"); } } - static void Var10(List students) { } - static void Var24(List students) { } - } -} \ No newline at end of file + + public static IEnumerable Filter(List students, Func 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); + } + } +} From 73a436013ef7939aeb62b239da0f7ab2eaa75fbc Mon Sep 17 00:00:00 2001 From: flovnes <106932515+flovnes@users.noreply.github.com> Date: Tue, 30 Apr 2024 01:49:39 +0300 Subject: [PATCH 4/4] Update main.cs --- src/main.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cs b/src/main.cs index 2409786..802bb6d 100644 --- a/src/main.cs +++ b/src/main.cs @@ -1,3 +1,4 @@ +using System.Text; namespace struct_lab_student { public partial class Program