From 26fc0263c7883b44966d0d47085346dffc644101 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 23 Feb 2024 15:45:56 +0100 Subject: [PATCH] Add files for task 1 --- Tasks/DT1/DT1.csproj | 10 ++++ Tasks/DT1/DT1.pdf | 3 ++ Tasks/DT1/DT1_0.cs | 107 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 Tasks/DT1/DT1.csproj create mode 100644 Tasks/DT1/DT1.pdf create mode 100644 Tasks/DT1/DT1_0.cs diff --git a/Tasks/DT1/DT1.csproj b/Tasks/DT1/DT1.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/Tasks/DT1/DT1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/Tasks/DT1/DT1.pdf b/Tasks/DT1/DT1.pdf new file mode 100644 index 0000000..af1786b --- /dev/null +++ b/Tasks/DT1/DT1.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6d311cfb0de15c4dc449dc143997c72d09903e2c87c5f9586ef6da14bb739c7 +size 96944 diff --git a/Tasks/DT1/DT1_0.cs b/Tasks/DT1/DT1_0.cs new file mode 100644 index 0000000..6bff177 --- /dev/null +++ b/Tasks/DT1/DT1_0.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace DT1 { + public delegate double GradeCalc(List s); + public enum GradeLevel { FirstYear = 1, SecondYear, ThirdYear, FourthYear }; + + public class Student { + public string FirstName { get; set; } + public string LastName { get; set; } + public int ID { get; set; } + public GradeLevel Year; + public List ExamScores; + public double Grade { get; set; } + } + + public class StudentClass { + public Func studentSelector = /* TO BE DONE */ + public GradeCalc gradeCalculator = /* TO BE DONE */ + public Func passedSelector = /* TO BE DONE */ + + #region data + public List students = new List { + new Student {FirstName = "Terry", LastName = "Adams", ID = 120, + Year = GradeLevel.SecondYear, + ExamScores = new List{ 99, 82, 81, 79}}, + new Student {FirstName = "Fadi", LastName = "Fakhouri", ID = 116, + Year = GradeLevel.ThirdYear, + ExamScores = new List{ 99, 86, 90, 94}}, + new Student {FirstName = "Hanying", LastName = "Feng", ID = 117, + Year = GradeLevel.FirstYear, + ExamScores = new List{ 93, 92, 80, 87}}, + new Student {FirstName = "Cesar", LastName = "Garcia", ID = 114, + Year = GradeLevel.FourthYear, + ExamScores = new List{ 97, 89, 85, 82}}, + new Student {FirstName = "Debra", LastName = "Garcia", ID = 115, + Year = GradeLevel.ThirdYear, + ExamScores = new List{ 35, 72, 91, 70}}, + new Student {FirstName = "Hugo", LastName = "Garcia", ID = 118, + Year = GradeLevel.SecondYear, + ExamScores = new List{ 92, 90, 83, 78}}, + new Student {FirstName = "Sven", LastName = "Mortensen", ID = 113, + Year = GradeLevel.FirstYear, + ExamScores = new List{ 88, 94, 65, 91}}, + new Student {FirstName = "Claire", LastName = "O'Donnell", ID = 112, + Year = GradeLevel.FourthYear, + ExamScores = new List{ 75, 84, 91, 39}}, + new Student {FirstName = "Svetlana", LastName = "Omelchenko", ID = 111, + Year = GradeLevel.SecondYear, + ExamScores = new List{ 97, 92, 81, 60}}, + new Student {FirstName = "Lance", LastName = "Tucker", ID = 119, + Year = GradeLevel.ThirdYear, + ExamScores = new List{ 68, 79, 88, 92}}, + new Student {FirstName = "Michael", LastName = "Tucker", ID = 122, + Year = GradeLevel.FirstYear, + ExamScores = new List{ 94, 92, 91, 91}}, + new Student {FirstName = "Eugene", LastName = "Zabokritski", ID = 121, + Year = GradeLevel.FourthYear, + ExamScores = new List{ 96, 85, 91, 60}} + }; + #endregion + + public List AddGrades(GradeCalc calc) { + foreach (Student s in students) { + s.Grade = calc(s.ExamScores); + } + return students; + } + + public List SearchStudent(Func select, String lastName) { + List result = new List(); + foreach (Student s in students) { + if (select(s, lastName)) result.Add(s); + } + return result; + } + + public IEnumerable QueryPassed(Func passed) { + return /* TO BE DONE */ + } + + static void show(String titel, List students) { + Console.WriteLine(titel); + foreach (var item in students) { + Console.WriteLine(String.Format("{0} {1} {2}", item.FirstName, item.LastName, item.Grade)); + } + } + + public static void Main(string[] args) { + StudentClass sc = new StudentClass(); + show("Grades", sc.AddGrades(sc.gradeCalculator)); + show("\nStudent Carcia",sc.SearchStudent(sc.studentSelector, "Garcia")); + show("\nPassed 4th", sc.QueryPassed(sc.passedSelector).ToList()); + // Keep the console window open in debug mode. + Console.WriteLine("Press any key to exit"); + Console.ReadKey(); + } + + + } + public static class ListUtils { + public static IEnumerable ... /* TO BE DONE */ + } + +}