Skip to content

Commit

Permalink
Merge pull request #5 from flovnes/dima
Browse files Browse the repository at this point in the history
done my block dubl 2
  • Loading branch information
flovnes authored Apr 29, 2024
2 parents 65e9c95 + e790fb4 commit 9442ff6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 30 deletions.
31 changes: 20 additions & 11 deletions src/main.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System.Text;
namespace struct_lab_student {
public partial class Program {
static List<Student> ReadData(string fileName) {
namespace struct_lab_student
{
public partial class Program
{
static List<Student> ReadData(string fileName)
{
List<Student> students = [];
try {
try
{
StreamReader reader = new(fileName);
string? line;
while ((line = reader.ReadLine()) != null)
Expand All @@ -13,13 +17,17 @@ static List<Student> ReadData(string fileName) {
return students;
}

static void RunMenu(List<Student> students) {
static void RunMenu(List<Student> students)
{
int match;
do {
do
{
Console.Write("\n<- Вихід [0]\nВиконати варіант 9 студента Попов Антон [1]\nВиконати варіант 10 студента Дмитро Киба [2]\nВиконати варіант 24 студента Волощук Влад [3]\nНомер > ");
string? s = Console.ReadLine();
if (int.TryParse(s, out match)) {
switch (match) {
if (int.TryParse(s, out match))
{
switch (match)
{
case 1:
Var9(students);
break;
Expand All @@ -40,10 +48,11 @@ static void RunMenu(List<Student> students) {
}


static void Main() {
Console.OutputEncoding = UTF8Encoding.UTF8;
static void Main()
{
Console.OutputEncoding = UTF8Encoding.UTF8;
List<Student> students = ReadData("../input.txt");
RunMenu(students);
}
}
}
}
58 changes: 46 additions & 12 deletions src/methods.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
namespace struct_lab_student {
public partial class Program {
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 Var10(List<Student> students)
{
static double CountAverageScore(Student student)
{
char[] marks = student.Marks;
double sum = 0;
foreach (var c in marks)
{
sum += (c == '-') ? 2 : double.Parse(c.ToString());
}

return Math.Round(sum / 3, 1);
}

static IEnumerable<Student> FilterTalentedPhysicians(List<Student> students)
{
return students.Where(student => student.Marks[1] == '5');
}

foreach (var student in FilterTalentedPhysicians(students))
{
Console.WriteLine($"{student.surName} {student.firstName} {student.patronymic} {CountAverageScore(student):0.0} {student.scholarship}");
}
}

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 => {
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) {
public static List<double> EvalAverages(IEnumerable<Student>? students)
{
List<double> averages = [];
if (students != null) {
foreach (var dude in students) {
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;
}
}
}
}
21 changes: 14 additions & 7 deletions src/student.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace struct_lab_student {
public struct Student {
namespace struct_lab_student
{
public struct Student
{
public string surName;
public string firstName;
public string patronymic;
Expand All @@ -9,20 +11,25 @@ public struct Student {
public int scholarship;

// debug
public override readonly string ToString() {
public override readonly string ToString()
{
return surName + " " + firstName + " " + patronymic + " " + dateOfBirth;
}
public Student(string line) {
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 = [
char.Parse(fields[5]),
char.Parse(fields[6]),
char.Parse(fields[7])
//math
char.Parse(fields[5]),
//physics
char.Parse(fields[6]),
// computer science
char.Parse(fields[7])
];
scholarship = int.Parse(fields[8]);
}
Expand Down

0 comments on commit 9442ff6

Please sign in to comment.