Example #1
0
        public static ClassGradeData calculateGradeData(ClassInformation classInfo)
        {
            int                       sumOfAllGrades    = 0;
            double                    averageClassMarks = 0.0;
            int                       gradedStudents;
            List <String>             studentsWithZeroMarks = new List <string>();
            List <StudentInformation> studentsInfo          = classInfo.StudentInfo;

            foreach (StudentInformation studentInfo in studentsInfo)
            {
                if (!(studentInfo.isGradeZero()))
                {
                    sumOfAllGrades += studentInfo.StudentGrade;
                }
                else
                {
                    studentsWithZeroMarks.Add(studentInfo.StudentName);
                }
            }
            gradedStudents    = studentsInfo.Count - studentsWithZeroMarks.Count;
            averageClassMarks = (double)sumOfAllGrades / (double)gradedStudents;
            ClassGradeData classGradeData = new ClassGradeData();

            classGradeData.ClassName             = classInfo.ClassName;
            classGradeData.StudentsWithZeroMarks = studentsWithZeroMarks;
            classGradeData.GradedStudents        = gradedStudents;
            classGradeData.ClassAverageGrade     = averageClassMarks;
            return(classGradeData);
        }
Example #2
0
 private void write_classAverage(ClassGradeData classGradeData)
 {
     writer.WriteLine("\t Name of the Class = {0} ", classGradeData.ClassName);
     writer.WriteLine();
     writer.WriteLine("\t i. Average score for the class = {0}", UptoOneDecimalPoints(classGradeData.ClassAverageGrade));
     writer.WriteLine("\t ii. Total number of students within the class = {0}", classGradeData.GradedStudents + classGradeData.StudentsWithZeroMarks.Count);
     writer.WriteLine("\t iii. The number of students used to calculate the class average = {0}", classGradeData.GradedStudents);
     if (classGradeData.StudentsWithZeroMarks.Count > 0)
     {
         writer.WriteLine("\t iv. The names of any students who were discarded from consideration:");
         foreach (string name in classGradeData.StudentsWithZeroMarks)
         {
             writer.WriteLine("\t\t - {0}", name);
             writer.WriteLine();
         }
     }
     else
     {
         writer.WriteLine("\t iv. All the students were considered");
         writer.WriteLine();
     }
 }