Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Exam1
- {
- class School
- {
- private string name;
- private List<Student> students;
- public School (string name)
- {
- this.name = name;
- this.students = new List<Student>();
- }
- public School()
- {
- }
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- public List<Student> Students
- {
- get
- {
- return students;
- }
- set
- {
- students = value;
- }
- }
- public void AddStudent (string name, double grade)
- {
- Student student = new Student(name, grade);
- students.Add(student);
- }
- public double AverageResultInRange(int start, int end)
- {
- double sum = 0;
- int count = 0;
- for (int index = start; index <= end; index++)
- {
- sum += students[index].Grade;
- count++;
- }
- return sum / count;
- }
- public List<string> RemoveStudentsByGrade(double grade)
- {
- List<String> leftStudents = new List<String>();
- foreach (Student student in students)
- {
- if(student.Grade < grade)
- {
- leftStudents.Add(student.Name);
- }
- }
- return leftStudents;
- }
- public List<Student> SortAscendingByName()
- {
- List<Student> sorted = students.OrderBy(s => s.Name).ToList();
- students = sorted;
- return sorted;
- }
- public List<Student> SortDescendingByGrade()
- {
- List<Student> sorted = students.OrderByDescending(s => s.Grade).ToList();
- students = sorted;
- return sorted;
- }
- public bool CheckStudentIsInSchool(string name)
- {
- foreach (Student student in students)
- {
- if (student.Name == name)
- {
- return true;
- }
- }
- return false;
- }
- public string[] ProvideInformationAboutAllStudents()
- {
- List<string> infoList = new List<string>();
- foreach(Student student in students)
- {
- infoList.Add(student.ToString());
- }
- return infoList.ToArray();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement