end challenge project 012
This commit is contained in:
parent
a88065976c
commit
96e36600b4
@ -278,3 +278,7 @@ Logan 91.2 93.12 A 96 (1.92 pts)
|
|||||||
```
|
```
|
||||||
|
|
||||||
Congratulations if you succeeded in this challenge!
|
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)
|
||||||
|
10
012_foreach_array_2/ChallengeProject/Own/Own.csproj
Normal file
10
012_foreach_array_2/ChallengeProject/Own/Own.csproj
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
85
012_foreach_array_2/ChallengeProject/Own/Program.cs
Normal file
85
012_foreach_array_2/ChallengeProject/Own/Program.cs
Normal file
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user