From 96e36600b43cdc68256c2925d9a7fd843e53a9d2 Mon Sep 17 00:00:00 2001 From: ipvg Date: Thu, 18 Jul 2024 21:50:25 -0400 Subject: [PATCH] end challenge project 012 --- 012_foreach_array_2/012_csharp.md | 4 + .../ChallengeProject/Own/Own.csproj | 10 +++ .../ChallengeProject/Own/Program.cs | 85 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 012_foreach_array_2/ChallengeProject/Own/Own.csproj create mode 100644 012_foreach_array_2/ChallengeProject/Own/Program.cs diff --git a/012_foreach_array_2/012_csharp.md b/012_foreach_array_2/012_csharp.md index 6487c79..b9513b2 100644 --- a/012_foreach_array_2/012_csharp.md +++ b/012_foreach_array_2/012_csharp.md @@ -278,3 +278,7 @@ Logan 91.2 93.12 A 96 (1.92 pts) ``` Congratulations if you succeeded in this challenge! + +- [Sugested Inital Solution](./ChallengeProject/Starter/Program.cs) +- [Sugested Final Solution](./ChallengeProject/Final/Program.cs) +- [Own Solution](./ChallengeProject/Own/Program.cs) diff --git a/012_foreach_array_2/ChallengeProject/Own/Own.csproj b/012_foreach_array_2/ChallengeProject/Own/Own.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/012_foreach_array_2/ChallengeProject/Own/Own.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/012_foreach_array_2/ChallengeProject/Own/Program.cs b/012_foreach_array_2/ChallengeProject/Own/Program.cs new file mode 100644 index 0000000..97211f5 --- /dev/null +++ b/012_foreach_array_2/ChallengeProject/Own/Program.cs @@ -0,0 +1,85 @@ +int exam_assignments = 5; + +string[] students_names = new string[] { "Sophia", "Andrew", "Emma", "Logan" }; +int[] sophia_scores = new int[] { 90, 86, 87, 98, 100, 94, 90 }; +int[] andrew_scores = new int[] { 92, 89, 81, 96, 90, 89 }; +int[] emma_scores = new int[] { 90, 85, 87, 98, 68, 89, 89, 89 }; +int[] logan_scores = new int[] { 90, 95, 87, 88, 96, 96 }; + +int[][] student_scores = new int[4][]; +student_scores[0] = sophia_scores; +student_scores[1] = andrew_scores; +student_scores[2] = emma_scores; +student_scores[3] = logan_scores; + +Console.Clear(); +Console.WriteLine("Student\t\tExam Score\tOverall Grade\tExtra Credit\n"); +int scores_counter = 0; +foreach (string name in students_names){ + print_scores(student_scores[scores_counter], name); + scores_counter += 1; +} + +void print_scores(int[] scores, string name){ + // student_score = (decimal)sophia_sum / current_assignments; + int graded = 0; + int graded_extra = 0; + int exam_score_sum = 0; + int score_count = scores.Length; + int extra_creds_sum = 0; + decimal extra_creds_score = 0; + decimal exam_score = 0; + decimal extra_creds_pts = 0; + decimal grade = 0; + Console.Write($"{name}\t\t"); + foreach (int score in scores){ + graded += 1; + if (graded <= exam_assignments){ + exam_score_sum += score; + } else { + graded_extra += 1; + extra_creds_sum += score; + } + } + exam_score = (decimal)(exam_score_sum) / exam_assignments; + extra_creds_score = (decimal)(extra_creds_sum) / graded_extra; + grade = (decimal)((decimal)exam_score_sum + ((decimal)extra_creds_sum / 10)) + / exam_assignments; + extra_creds_pts = grade - exam_score; + string grade_ltr = getGrade((int)grade); + Console.Write($"{exam_score}\t\t{grade}\t"); + Console.Write($"{grade_ltr}\t {extra_creds_score}"); + Console.WriteLine($" ({extra_creds_pts} pts)"); +} + +string getGrade(decimal score){ + string grade; + if (score < 60){ + grade = "F"; + } else if (score < 63){ + grade = "D-"; + } else if (score < 67){ + grade = "D"; + } else if (score < 70){ + grade = "D+"; + } else if (score < 73){ + grade = "C-"; + } else if (score < 77){ + grade = "C"; + } else if (score < 80){ + grade = "C+"; + } else if (score < 83){ + grade = "B-"; + } else if (score < 87){ + grade = "B"; + } else if (score < 90){ + grade = "B+"; + } else if (score < 93){ + grade = "A-"; + } else if (score < 97){ + grade = "A"; + } else { + grade = "A+"; + } + return grade; +}