Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.82 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10.  
  11. namespace Students
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  21. {
  22.  
  23. }
  24.  
  25. private void button1_Click(object sender, EventArgs e)
  26. {
  27.  
  28. }
  29.  
  30. private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
  31. {
  32.  
  33. }
  34. }
  35.  
  36. class Group
  37. {
  38. class Student : Group
  39. {
  40. private string Surname;
  41. private string Name;
  42. private string Middlename;
  43. private int salary;
  44. private bool sessionclosed = false;
  45. private int[] Marks;
  46. private int[] Credits;
  47.  
  48. public Student()
  49. {
  50. Surname = null;
  51. Name = null;
  52. Middlename = null;
  53. salary = 0;
  54. sessionclosed = false;
  55. Marks = null;
  56. Credits = null;
  57. }
  58.  
  59. public Student(string SN, string N, string MN, int[] marks, int[] credits, int Salary)
  60. {
  61. if ((SN != null) && (N != null) && (MN != null))
  62. {
  63. Surname = SN;
  64. Name = N;
  65. Middlename = MN;
  66. }
  67. else
  68. {
  69. Surname = null;
  70. Name = null;
  71. Middlename = null;
  72. }
  73. if (marks.Length != 0)
  74. {
  75. Marks = new int[marks.Length];
  76. for (int i = 0; i < marks.Length; i++)
  77. {
  78. Marks[i] = marks[i];
  79. }
  80.  
  81. }
  82. else
  83. Marks = null;
  84.  
  85. if ((credits.Length > 0) && (credits.Length < 13))
  86. {
  87. Credits = new int[credits.Length];
  88. for (int i = 0; i < credits.Length; i++)
  89. {
  90. Credits[i] = credits[i];
  91. }
  92. }
  93. else
  94. Credits = null;
  95. if (Salary != 0)
  96. salary = Salary;
  97. else
  98. salary = 0;
  99. }
  100.  
  101. public string surname
  102. {
  103. get { return Surname; }
  104. set { Surname = value; }
  105. }
  106.  
  107. public string name
  108. {
  109. get { return Name; }
  110. set { Name = value; }
  111. }
  112.  
  113. public string middlename
  114. {
  115. get { return Middlename; }
  116. set { Middlename = value; }
  117. }
  118.  
  119. public int SALARY
  120. {
  121. get { return salary; }
  122. set { salary = value; }
  123. }
  124.  
  125. public bool Sessionclosed
  126. {
  127. get { return sessionclosed; }
  128. set { sessionclosed = value; }
  129. }
  130.  
  131. public int[] MARKS
  132. {
  133. get { return Marks; }
  134. set { Marks = value; }
  135. }
  136.  
  137. public int[] CREDITS
  138. {
  139. get { return Credits; }
  140. set { Credits = value; }
  141. }
  142.  
  143. public static bool operator ==(Student A, Student B) //перегрузка операторов == !=
  144. {
  145. string Id1 = A.Surname + ' ' + A.Name + ' ' + A.Middlename;
  146. string Id2 = B.Surname + ' ' + B.Name + ' ' + B.Middlename;
  147. if ((Id1 == Id2) && (A.Marks == B.Marks) && (A.Credits == B.Credits) && (A.salary == B.salary))
  148. return true;
  149. else
  150. return false;
  151. }
  152.  
  153. public static bool operator !=(Student A, Student B)
  154. {
  155. string Id1 = A.Surname + ' ' + A.Name + ' ' + A.Middlename;
  156. string Id2 = B.Surname + ' ' + B.Name + ' ' + B.Middlename;
  157. if ((Id1 == Id2) && (A.Marks == B.Marks) && (A.Credits == B.Credits) && (A.salary == B.salary))
  158. return false;
  159. else
  160. return true;
  161. }
  162.  
  163. public static bool operator true(Student A) //перегрузка операторов true false
  164. {
  165. bool B = false;
  166. bool C = false;
  167. for (int i = 0; i < A.Marks.Length; i++)
  168. {
  169. if ((A.Marks[i] == 4) || (A.Marks[i] == 5)) //добавить про кредитс
  170. B = true;
  171. else
  172. C = true;
  173. }
  174. if (B && !C)
  175. return true;
  176. else
  177. return false;
  178. }
  179.  
  180. public static bool operator false(Student A)
  181. {
  182. bool B = false;
  183. for (int i = 0; i < A.Marks.Length; i++)
  184. {
  185. if ((A.Marks[i] != 4) || (A.Marks[i] != 5)) //добавить про кредитс
  186. B = true;
  187. }
  188. if (B)
  189. return true;
  190. else
  191. return false;
  192. }
  193. }
  194.  
  195. private string namegroup;
  196. private int countStudents;
  197. private LinkedList<Student> listGroup;
  198. private int countMarks;
  199. private int countCredits;
  200. private string[] NameSubject;
  201. private string[] NameCredits;
  202. private int course;
  203.  
  204. public Group()
  205. { namegroup = null; listGroup = null; countStudents = 0; countCredits = 0; countMarks = 0; course = 0;
  206. NameCredits = null; NameSubject = null;}
  207. public Group(string NameG, int crs, string[] NameS, string[] NameC)
  208. {
  209. if (NameG != null)
  210. namegroup = NameG;
  211. else
  212. namegroup = null;
  213. if ((crs > 0) && (crs <7))
  214. course = crs;
  215. else
  216. course = 0;
  217. if (NameS.Length != 0)
  218. {
  219. countMarks = NameS.Length;
  220. for (int i=0; i<NameS.Length;i++)
  221. NameSubject[i] = NameS[i];
  222. }
  223. else
  224. {
  225. countMarks = 0;
  226. NameSubject = null;
  227. }
  228. if (NameC.Length != 0)
  229. {
  230. countCredits = NameC.Length;
  231. for (int i=0; i<NameC.Length;i++)
  232. NameCredits[i] = NameC[i];
  233. }
  234. else
  235. {
  236. countCredits = 0;
  237. NameCredits = null;
  238. }
  239.  
  240. countStudents = 0;
  241. listGroup = null;
  242. }
  243.  
  244. public string NameGr
  245. {
  246. get { return namegroup;}
  247. set { namegroup = value;}
  248. }
  249.  
  250. public int countStuds
  251. {
  252. get { return countStudents;}
  253. set { countStudents = value;}
  254. }
  255. public int countMrks
  256. {
  257. get { return countMarks;}
  258. set { countMarks = value;}
  259. }
  260.  
  261. public int countCreds
  262. {
  263. get { return countCredits;}
  264. set { countCredits = value;}
  265. }
  266. public int Course
  267. {
  268. get { return course;}
  269. set { course = value;}
  270. }
  271. public string[] Subs
  272. {
  273. get { return NameSubject;}
  274. set { NameSubject = value;}
  275. }
  276.  
  277. public string[] Creds
  278. {
  279. get { return NameCredits;}
  280. set { NameCredits = value;}
  281. }
  282. public LinkedList<Student> List
  283. {
  284. get { return listGroup; }
  285. set { listGroup = value;}
  286. }
  287. public Group ReadFromFile(string NameFile) //считывает файл
  288. {
  289. Group G = new Group();
  290. if (NameFile != null)
  291. {
  292. try
  293. {
  294. StreamReader stream = new StreamReader(NameFile);
  295. string Str = stream.ReadToEnd();
  296. char[] sprt = { '\n', ':' };
  297. string[] Mas = Str.Split(sprt);
  298. for (int i = 0; i < Mas.Length; i++)
  299. {
  300. if (Mas[i] == "Group")
  301. namegroup = Mas[i + 1];
  302. if (Mas[i] == "Course")
  303. course = Convert.ToInt32(Mas[i + 1]);
  304.  
  305. if (Mas[i] == "Subjects")
  306. {
  307. for (int q = i + 1; Mas[i] != "Credits"; q++)
  308. {
  309. int k = 0;
  310. NameSubject[k] = Mas[q];
  311. k++;
  312. }
  313. }
  314. if (Mas[i] == "Credits")
  315. {
  316. for (int f = i + 1; Mas[i] != "Students"; f++)
  317. {
  318. int m = 0;
  319. NameCredits[m] = Mas[f];
  320. m++;
  321. }
  322. }
  323. if (Mas[i] == "Students") //добавление студентов в список
  324. {
  325. char[] sprt2 = { ' ', '[', ']', '{', '}' };
  326. string[] Info;
  327. int n = 0; //считает количество студентов
  328. for (int j = i + 1; j < Mas.Length; j++)
  329. {
  330. n++;
  331. Info = Mas[j].Split(sprt2);
  332. Student S = new Student();
  333.  
  334. listGroup.AddLast(S);
  335. }
  336.  
  337.  
  338. countStudents = n;
  339. }
  340. }
  341. }
  342.  
  343. catch
  344. {
  345. MessageBox.Show("Неверный формат данных");
  346. }
  347. }
  348. else
  349. G = null;
  350. return G;
  351. }
  352. }
  353.  
  354.  
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement