Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Form1 : Form
- {
- public static int k=0;
- Student[] mas = new Student[3];
- public Form1()
- {
- InitializeComponent();
- }
- public delegate int CompareHealth(Student o1, Student o2);
- public class Student
- {
- public string name = "";
- public int days = 0;
- public int hemoglobin = 0;
- public Student() { }
- public Student(string name, int days, int hemoglobin)
- {
- this.name = name;
- this.days = days;
- this.hemoglobin = hemoglobin;
- }
- public Student(Student s)
- {
- name = s.name;
- days = s.days;
- hemoglobin = s.hemoglobin;
- }
- public string add
- {
- set { name = value; }
- get { return name; }
- }
- private static int CompareName(Student o1, Student o2)
- {
- return (string.Compare(o1.name, o2.name));
- }
- private static int CompareDays(Student o1, Student o2)
- {
- if (o1.days > o2.days) return (1);
- else if (o1.days < o2.days) return (-1);
- else return (0);
- }
- private static int CompareHemoglobin(Student o1, Student o2)
- {
- if (o1.hemoglobin > o2.hemoglobin) return (1);
- else if (o1.hemoglobin < o2.hemoglobin) return (-1);
- else return (0);
- }
- public static CompareHealth SortByName { get { return (new CompareHealth(CompareName)); } }
- public static CompareHealth SortByDays { get { return (new CompareHealth(CompareDays)); } }
- public static CompareHealth SortByHemoglobin { get { return (new CompareHealth(CompareHemoglobin)); } }
- }
- class Students
- {
- private int items = 0; const int n = 10;
- private Student[] students = new Student[n];
- public Student this[int num]
- {
- get { return (students[num - 1]); }
- set { (students[num - 1]) = value; }
- }
- public void Vivod(ListBox h)
- {
- for (int i = 0; i < items; i++)
- {
- h.Items.Add(students[i].name + " " + students[i].days + " " + students[i].hemoglobin + " ");
- }
- }
- public void LoadStudents()
- {
- Student p = new Student("А", 13, 68);
- students[items++] = p;
- Student w = new Student("Б", 18, 67);
- students[items++] = w;
- Student e = new Student("В", 5, 75);
- students[items++] = e;
- }
- public void Add(TextBox t1, TextBox t2, TextBox t3)
- {
- if (k < 3)
- {
- Student load = new Student();
- students[items++] = load;
- k++;
- }
- }
- public void SortStudent(CompareHealth compare)
- {
- Student temp = new Student();
- for (int i = 1; i < items; i++)
- for (int j = items - 1; j >= i; j--)
- if (compare(students[j], students[j - 1]) == -1)
- { temp = students[j - 1]; students[j - 1] = students[j]; students[j] = temp; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement