-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
153 lines (114 loc) · 5.03 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
This C# console application is designed to:
- Use arrays to store student names and assignment scores.
- Use a `foreach` statement to iterate through the student names as an outer program loop.
- Use an `if` statement within the outer loop to identify the current student name and access that student's assignment scores.
- Use a `foreach` statement within the outer loop to iterate though the assignment scores array and sum the values.
- Use an algorithm within the outer loop to calculate the average exam score for each student.
- Use an `if-elseif-else` construct within the outer loop to evaluate the average exam score and assign a letter grade automatically.
- Integrate extra credit scores when calculating the student's final score and letter grade as follows:
- detects extra credit assignments based on the number of elements in the student's scores array.
- divides the values of extra credit assignments by 10 before adding extra credit scores to the sum of exam scores.
- use the following report format to report student grades:
Student Grade
Sophia: 92.2 A-
Andrew: 89.6 B+
Emma: 85.6 B
Logan: 91.2 A-
*/
int examAssignments = 5;
string[] studentNames = new string[] { "Sophia", "Andrew", "Emma", "Logan" };
int[] sophiaScores = new int[] { 90, 86, 87, 98, 100, 94, 90 };
int[] andrewScores = new int[] { 92, 89, 81, 96, 90, 89 };
int[] emmaScores = new int[] { 90, 85, 87, 98, 68, 89, 89, 89 };
int[] loganScores = new int[] { 90, 95, 87, 88, 96, 96 };
int[] studentScores = new int[10];
string currentStudentLetterGrade = "";
// display the header row for scores/grades
Console.Clear();
Console.WriteLine("Student\t\tExam Score\tOverall Grade\tExtra Credit\n");
/*
The outer foreach loop is used to:
- iterate through student names
- assign a student's grades to the studentScores array
- sum assignment scores (inner foreach loop)
- calculate numeric and letter grade
- write the score report information
*/
foreach (string name in studentNames)
{
string currentStudent = name;
if (currentStudent == "Sophia")
studentScores = sophiaScores;
else if (currentStudent == "Andrew")
studentScores = andrewScores;
else if (currentStudent == "Emma")
studentScores = emmaScores;
else if (currentStudent == "Logan")
studentScores = loganScores;
int sumAssignmentScores = 0;
decimal currentStudentGrade = 0;
int gradedAssignments = 0;
// added variables for the sum/average exam scores and extra credit. Also defined a extra credit count.
int sumExamScore = 0;
decimal averageExamScore = 0;
int sumExtraCredit = 0;
int extraCreditCount = 0;
decimal averageExtraCredit = 0;
/*
the inner foreach loop sums assignment scores
extra credit assignments are worth 10% of an exam score
*/
foreach (int score in studentScores)
{
gradedAssignments += 1;
if (gradedAssignments <= examAssignments)
{
sumAssignmentScores += score;
sumExamScore += score;
}
else
{
sumAssignmentScores += score / 10;
sumExtraCredit += score;
extraCreditCount += 1;
}
}
// added calulations for the new columns (exam score, extra credit/extra credit points) and updated overall grade.
averageExamScore = (decimal)(sumExamScore) / examAssignments;
averageExtraCredit = (decimal)(sumExtraCredit) / extraCreditCount;
decimal extraCreditPoints = ((decimal)(sumExtraCredit) / 10) / examAssignments;
currentStudentGrade = (decimal)(extraCreditPoints) + (decimal)(averageExamScore);
if (currentStudentGrade >= 97)
currentStudentLetterGrade = "A+";
else if (currentStudentGrade >= 93)
currentStudentLetterGrade = "A";
else if (currentStudentGrade >= 90)
currentStudentLetterGrade = "A-";
else if (currentStudentGrade >= 87)
currentStudentLetterGrade = "B+";
else if (currentStudentGrade >= 83)
currentStudentLetterGrade = "B";
else if (currentStudentGrade >= 80)
currentStudentLetterGrade = "B-";
else if (currentStudentGrade >= 77)
currentStudentLetterGrade = "C+";
else if (currentStudentGrade >= 73)
currentStudentLetterGrade = "C";
else if (currentStudentGrade >= 70)
currentStudentLetterGrade = "C-";
else if (currentStudentGrade >= 67)
currentStudentLetterGrade = "D+";
else if (currentStudentGrade >= 63)
currentStudentLetterGrade = "D";
else if (currentStudentGrade >= 60)
currentStudentLetterGrade = "D-";
else
currentStudentLetterGrade = "F";
// Student Grade
// Sophia: 92.2 A-
Console.WriteLine($"{currentStudent}\t\t{averageExamScore}\t\t{currentStudentGrade}\t{currentStudentLetterGrade}\t{averageExtraCredit} ({extraCreditPoints} pts)");
}
// required for running in VS Code (keeps the Output windows open to view results)
Console.WriteLine("\n\rPress the Enter key to continue");
Console.ReadLine();