Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. using System;
  2.  
  3. public class SinhVien
  4. {
  5. public string maSV;
  6. public int tuoiSV;
  7. public bool gioiTinh;
  8. public string MaSV {
  9. get {
  10. return this.maSV;
  11. }
  12. set {
  13. this.maSV = value;
  14. }
  15. }
  16. public int TuoiSV {
  17. get {
  18. return this.tuoiSV;
  19. }
  20. set {
  21. this.tuoiSV = value;
  22. }
  23. }
  24. public bool GioiTinh {
  25. get {
  26. return this.GioiTinh;
  27. }
  28. set {
  29. this.GioiTinh = value;
  30. }
  31. }
  32. public SinhVien(string maSV, int tuoiSV, bool gioiTinh) {
  33. this.maSV = maSV;
  34. this.tuoiSV = tuoiSV;
  35. this.gioiTinh = gioiTinh;
  36. }
  37. public void ToString() {
  38. Console.WriteLine("Ma Sinh Vien: " + this.maSV);
  39. Console.WriteLine("Tuoi Sinh Vien: " + this.tuoiSV);
  40. Console.WriteLine("Gioi Tinh Sinh Vien: " + this.gioiTinh);
  41. }
  42. public static void Input(SinhVien objSV) {
  43. Console.WriteLine("Nhap ma so sinh vien can them");
  44. objSV.MaSV = Console.ReadLine();
  45. Console.WriteLine("Nhap tuoi sinh vien can them");
  46. objSV.TuoiSV = Int32.Parse(Console.ReadLine());
  47. Console.WriteLine("Nhap gioi sinh vien can them (Nam/Nu) (1/0)");
  48. objSV.GioiTinh = false;
  49. int temp = Int32.Parse(Console.ReadLine());
  50. if(temp == 1) objSV.GioiTinh = true;
  51. else objSV.GioiTinh = false;
  52. }
  53. }
  54. public class ListSV
  55. {
  56. public SinhVien[] listSV;
  57. public int maxSV;
  58. public SinhVien getSV(int i) {
  59. return this.listSV[i];
  60. }
  61. public void setSV(int i, string maSV, int tuoiSV, bool gioiTinh) {
  62. this.listSV[i] = new SinhVien(maSV, tuoiSV, gioiTinh);
  63. }
  64. public int MaxSV {
  65. get {
  66. return this.maxSV;
  67. }
  68. set {
  69. this.maxSV = value;
  70. }
  71. }
  72. public ListSV(SinhVien[] listSV, int maxSV) {
  73. this.listSV = listSV;
  74. this.maxSV = maxSV;
  75. }
  76. public void Add(SinhVien objSV) {
  77. if(listSV.Length == maxSV) {
  78. Console.WriteLine("So luong sinh vien toi da, khong the them SV");
  79. return;
  80. }
  81. SinhVien[] newList = new SinhVien[listSV.Length + 1];
  82. this.listSV = newList;
  83. newList[newList.Length -1] = objSV;
  84. }
  85. public void Edit(SinhVien objSV, int i) {
  86. if(i > listSV.Length - 1) {
  87. Console.WriteLine("Vi tri khong ton tai");
  88. return;
  89. }
  90. listSV[i] = objSV;
  91. }
  92. public void Show(string kw) {
  93. if(kw.Equals("all"))
  94. for(int i=0; i<listSV.Length; i++) {
  95. listSV[i].ToString();
  96. }
  97. else for(int i=0; i<listSV.Length; i++) {
  98. if(listSV[i].MaSV.Equals(kw))
  99. listSV[i].ToString();
  100. }
  101. }
  102. public void SortAscending() {
  103. SinhVien temp = new SinhVien("",0,true);
  104. for(int i=0; i<listSV.Length; i++) {
  105. for(int j=i; j<listSV.Length; j++) {
  106. if(listSV[j].TuoiSV < listSV[i].TuoiSV) {
  107. temp = listSV[j];
  108. listSV[j] = listSV[i];
  109. listSV[i] = temp;
  110. }
  111. }
  112. }
  113. }
  114. public static void Main()
  115. {
  116. Console.WriteLine("Nhap so sinh vien toi da");
  117. int max = Int32.Parse(Console.ReadLine());
  118. SinhVien[] listSV = new SinhVien[0];
  119. ListSV alSV = new ListSV(listSV, max);
  120.  
  121. SinhVien objSV = new SinhVien("",0,false);
  122. SinhVien.Input(objSV);
  123. alSV.Add(objSV);
  124. SinhVien.Input(objSV);
  125. alSV.Edit(objSV, 0);
  126. alSV.Show("all");
  127.  
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement