Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. public partial class Form1 : Form
  2. {
  3. public static int k=0;
  4. Student[] mas = new Student[3];
  5. public Form1()
  6. {
  7. InitializeComponent();
  8. }
  9. public delegate int CompareHealth(Student o1, Student o2);
  10. public class Student
  11. {
  12. public string name = "";
  13. public int days = 0;
  14. public int hemoglobin = 0;
  15. public Student() { }
  16. public Student(string name, int days, int hemoglobin)
  17. {
  18. this.name = name;
  19. this.days = days;
  20. this.hemoglobin = hemoglobin;
  21. }
  22. public Student(Student s)
  23. {
  24. name = s.name;
  25. days = s.days;
  26. hemoglobin = s.hemoglobin;
  27. }
  28. public string add
  29. {
  30. set { name = value; }
  31. get { return name; }
  32. }
  33.  
  34. private static int CompareName(Student o1, Student o2)
  35. {
  36. return (string.Compare(o1.name, o2.name));
  37. }
  38.  
  39. private static int CompareDays(Student o1, Student o2)
  40. {
  41. if (o1.days > o2.days) return (1);
  42. else if (o1.days < o2.days) return (-1);
  43. else return (0);
  44. }
  45. private static int CompareHemoglobin(Student o1, Student o2)
  46. {
  47. if (o1.hemoglobin > o2.hemoglobin) return (1);
  48. else if (o1.hemoglobin < o2.hemoglobin) return (-1);
  49. else return (0);
  50. }
  51. public static CompareHealth SortByName { get { return (new CompareHealth(CompareName)); } }
  52. public static CompareHealth SortByDays { get { return (new CompareHealth(CompareDays)); } }
  53. public static CompareHealth SortByHemoglobin { get { return (new CompareHealth(CompareHemoglobin)); } }
  54. }
  55. class Students
  56. {
  57. private int items = 0; const int n = 10;
  58. private Student[] students = new Student[n];
  59. public Student this[int num]
  60. {
  61. get { return (students[num - 1]); }
  62. set { (students[num - 1]) = value; }
  63. }
  64. public void Vivod(ListBox h)
  65. {
  66. for (int i = 0; i < items; i++)
  67. {
  68. h.Items.Add(students[i].name + " " + students[i].days + " " + students[i].hemoglobin + " ");
  69. }
  70. }
  71. public void LoadStudents()
  72. {
  73. Student p = new Student("А", 13, 68);
  74. students[items++] = p;
  75. Student w = new Student("Б", 18, 67);
  76. students[items++] = w;
  77. Student e = new Student("В", 5, 75);
  78. students[items++] = e;
  79. }
  80. public void Add(TextBox t1, TextBox t2, TextBox t3)
  81. {
  82. if (k < 3)
  83. {
  84. Student load = new Student();
  85. students[items++] = load;
  86. k++;
  87. }
  88. }
  89. public void SortStudent(CompareHealth compare)
  90. {
  91. Student temp = new Student();
  92. for (int i = 1; i < items; i++)
  93. for (int j = items - 1; j >= i; j--)
  94. if (compare(students[j], students[j - 1]) == -1)
  95. { temp = students[j - 1]; students[j - 1] = students[j]; students[j] = temp; }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement