Advertisement
desislava_topuzakova

Untitled

Jul 5th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Exam1
  8. {
  9. class School
  10. {
  11. private string name;
  12. private List<Student> students;
  13.  
  14. public School (string name)
  15. {
  16. this.name = name;
  17. this.students = new List<Student>();
  18. }
  19.  
  20. public School()
  21. {
  22. }
  23.  
  24. public string Name
  25. {
  26. get
  27. {
  28. return name;
  29. }
  30. set
  31. {
  32. name = value;
  33. }
  34. }
  35.  
  36. public List<Student> Students
  37. {
  38. get
  39. {
  40. return students;
  41. }
  42. set
  43. {
  44. students = value;
  45. }
  46. }
  47.  
  48. public void AddStudent (string name, double grade)
  49. {
  50. Student student = new Student(name, grade);
  51. students.Add(student);
  52. }
  53.  
  54. public double AverageResultInRange(int start, int end)
  55. {
  56. double sum = 0;
  57. int count = 0;
  58. for (int index = start; index <= end; index++)
  59. {
  60. sum += students[index].Grade;
  61. count++;
  62. }
  63.  
  64. return sum / count;
  65. }
  66.  
  67. public List<string> RemoveStudentsByGrade(double grade)
  68. {
  69. List<String> leftStudents = new List<String>();
  70. foreach (Student student in students)
  71. {
  72. if(student.Grade < grade)
  73. {
  74. leftStudents.Add(student.Name);
  75. }
  76. }
  77. return leftStudents;
  78. }
  79.  
  80. public List<Student> SortAscendingByName()
  81. {
  82. List<Student> sorted = students.OrderBy(s => s.Name).ToList();
  83. students = sorted;
  84. return sorted;
  85. }
  86.  
  87. public List<Student> SortDescendingByGrade()
  88. {
  89. List<Student> sorted = students.OrderByDescending(s => s.Grade).ToList();
  90. students = sorted;
  91. return sorted;
  92. }
  93.  
  94. public bool CheckStudentIsInSchool(string name)
  95. {
  96. foreach (Student student in students)
  97. {
  98. if (student.Name == name)
  99. {
  100. return true;
  101. }
  102. }
  103.  
  104. return false;
  105. }
  106.  
  107. public string[] ProvideInformationAboutAllStudents()
  108. {
  109. List<string> infoList = new List<string>();
  110. foreach(Student student in students)
  111. {
  112. infoList.Add(student.ToString());
  113. }
  114. return infoList.ToArray();
  115. }
  116.  
  117.  
  118.  
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement