YavorJS

Average Grades

Sep 10th, 2016
440
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _4.Average_Grades
  8. {
  9. class Student
  10. {
  11. public string name { get; set; }
  12. public List<double> grades { get; set; }
  13. public double averageGrade { get {
  14. return grades.Average();
  15. } }
  16. }
  17. class Program
  18. {
  19. static void Main(string[] args)
  20. {
  21. int entry = int.Parse(Console.ReadLine());
  22. List <Student> students= new List<Student>();
  23. for (int name = 0; name < entry; name++)
  24. {
  25. Student oneStudent = new Student();
  26. List<string> studentData = Console.ReadLine().Split().ToList();
  27. string studentName = studentData[0];
  28. oneStudent.name = studentName;
  29. List<double> oneStudentGrades = new List<double>();
  30. for (int grade = 1; grade < studentData.Count; grade++)
  31. {
  32. double studentGrade = double.Parse(studentData[grade]);
  33. oneStudentGrades.Add(studentGrade);
  34. }
  35. oneStudent.grades = oneStudentGrades;
  36. students.Add(oneStudent);
  37. }
  38. List<Student> notableStudents = students.OrderBy(student=>student.name).ThenByDescending(student=>student.averageGrade).ToList();
  39. foreach (var student in notableStudents)
  40. {
  41. if (student.averageGrade >= 5)
  42. {
  43. Console.WriteLine("{0:f2} -> {1:f2}", student.name, student.averageGrade);
  44. }
  45.  
  46. }
  47. }
  48. }
  49. }
RAW Paste Data