Advertisement
Guest User

dodelat`

a guest
Nov 15th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. namespace Лаба2
  10. {
  11. class Program
  12. {
  13. public static void Main(string[] args)
  14. {
  15. Console.ForegroundColor = ConsoleColor.Green;
  16. Console.Title = " База данных ";
  17.  
  18. string menu = null;
  19. string end = "1";
  20.  
  21.  
  22.  
  23.  
  24. while (end != "2")
  25. {
  26.  
  27. while (menu != "1" && menu != "2" && menu != "3" && menu != "4")
  28. {
  29. Console.WriteLine($"\nСтуденты: \nВывести список - 1 \n\nДобавить студента в список - 2 \n\nУдалить студента из списка - 3 \n\nНайти студента по ФИО в списке - 4 \n\nНайти студента по дате рождения в спике - 5 \n\nСортировать список - 6");
  30. menu = Console.ReadLine();
  31. }
  32. switch (menu)
  33. {
  34. case ("1"):
  35. TeloBD();
  36. break;
  37.  
  38. case ("2"):
  39. showbd();
  40. break;
  41.  
  42. case ("3"):
  43. sort();
  44. break;
  45.  
  46. case ("4"):
  47. Poisk();
  48. break;
  49.  
  50.  
  51.  
  52. }
  53. menu = null;
  54.  
  55. Console.WriteLine($"\nПовторить программу? 1 - да. 2 - нет.");
  56. end = Console.ReadLine();
  57. }
  58.  
  59.  
  60.  
  61.  
  62. }
  63.  
  64. public static void showbd()
  65. {
  66. //StreamReader fr = new StreamReader("BD.txt", Encoding.Default);
  67. //string[] Filemass = fr.ReadToEnd().Split(Console.WriteLine());
  68. string[] name = File.ReadAllLines("BD.txt", Encoding.Default);
  69. foreach (string show in name)
  70. {
  71. Console.WriteLine(show);
  72. }
  73. }
  74.  
  75.  
  76. public static void TeloBD()
  77. {
  78. StreamReader fr = new StreamReader("BD.txt", Encoding.Default);
  79. string[] Filemass = fr.ReadToEnd().Split('\n' );
  80.  
  81.  
  82. StreamReader fileRead = new StreamReader("BD.txt", Encoding.Default);
  83. string[] Filemass1 = fileRead.ReadToEnd().Split('#');
  84. int countBds = Filemass1.Length - 1;
  85.  
  86.  
  87. string[,] bds = new string[countBds,8];
  88. int n = 0;
  89.  
  90. double[] ocenka = new double[countBds];
  91.  
  92.  
  93.  
  94. for (int i = 0; i<countBds; i++)
  95. {
  96.  
  97. for (int j = 0; j < 8; j++)
  98. {
  99. bds[i,j] += $" {Filemass[n]}";
  100. n++;
  101. }
  102.  
  103.  
  104. }
  105.  
  106. for (int i=0; i< countBds; i++)
  107. {
  108. ocenka[i] = Convert.ToDouble(bds[i, 6]);
  109.  
  110. }
  111. string[] maxOcenka = new string[countBds];
  112. maxOcenka[0] = Convert.ToString($" Максимальный балл - {ocenka.Max()} имеет(имеют):");
  113. string[] minOcenka = new string[countBds];
  114. minOcenka[0] = Convert.ToString($" Минимальный балл - {ocenka.Min()} имеет(имеют): ");
  115.  
  116. double middleOcenka = 0;
  117.  
  118. for(int i = 0; i < countBds; i++)
  119. {
  120.  
  121. middleOcenka += ocenka[i];
  122.  
  123. if (ocenka.Max() == Convert.ToDouble(bds[i, 6]))
  124. {
  125. if (i == 0)
  126. {
  127. maxOcenka[i] += $"\n-{bds[i, 1]} ";
  128. }
  129. else
  130. {
  131. maxOcenka[i] += $"-{bds[i,1]} ";
  132. }
  133. }
  134.  
  135. if (ocenka.Min() == Convert.ToDouble(bds[i, 6]))
  136. {
  137. if (i == 0)
  138. {
  139. minOcenka[i] += $"\n-{bds[i, 1]} ";
  140. }
  141. else
  142. {
  143. minOcenka[i] += $"-{bds[i,1]} ";
  144. }
  145. }
  146.  
  147. }
  148.  
  149.  
  150. middleOcenka = middleOcenka / countBds;
  151.  
  152.  
  153. for (int i = 0; i < countBds; i++)
  154. {
  155. //Console.WriteLine("\n");
  156. for(int j =0; j<8; j++)
  157. {
  158. Console.WriteLine(bds[i,j]);
  159.  
  160. }
  161. }
  162.  
  163. foreach (string show in maxOcenka)
  164. {
  165. if (show != null)
  166. {
  167. Console.WriteLine($"{show}");
  168. }
  169. }
  170. Console.WriteLine("\n");
  171.  
  172. foreach (string show in minOcenka)
  173. {
  174. if (show != null)
  175. {
  176. Console.WriteLine($"{show}");
  177. }
  178. }
  179. Console.WriteLine("\n");
  180.  
  181.  
  182. Console.WriteLine($" Средняя оценка студентов - {middleOcenka}");
  183.  
  184.  
  185.  
  186.  
  187.  
  188. }
  189.  
  190. public static void Poisk()
  191. {
  192.  
  193. Console.WriteLine("\nВведите имя студента или его дату рождения:");
  194.  
  195. StreamReader fileRead = new StreamReader("BD.txt", Encoding.Default);
  196. string[] Filemass1 = fileRead.ReadToEnd().Split('#');
  197. int countBds = Filemass1.Length - 1;
  198.  
  199. string[] Filemass = File.ReadAllLines("BD.txt", Encoding.Default);
  200. string[,] bds = new string[countBds, 8];
  201. int n = 0;
  202.  
  203. for (int i = 0; i < countBds; i++)
  204. {
  205.  
  206. for (int j = 0; j < 8; j++)
  207. {
  208. bds[i, j] = Filemass[n];
  209. n++;
  210. }
  211.  
  212.  
  213. }
  214.  
  215. //string name1;
  216. string name;
  217. name = Console.ReadLine();
  218. Console.WriteLine();
  219.  
  220. for (int i = 0; i < countBds; i++)
  221. {
  222.  
  223. if (Equals(name, bds[i, 1]))
  224. {
  225.  
  226. Console.WriteLine($"\nДосье на {name}: ");
  227. for (int j = 0; j < 8; j++)
  228. {
  229. Console.WriteLine(bds[i,j]);
  230. }
  231. }
  232.  
  233. if (Equals(name, bds[i, 2]))
  234. {
  235. Console.WriteLine($"\nДосье на на студента с датой рождениея {name} ");
  236. for (int j = 0; j < 8; j++)
  237. {
  238. Console.WriteLine(bds[i, j]);
  239. }
  240. }
  241.  
  242.  
  243. }
  244.  
  245. Console.WriteLine($"\nКонец поиска.");
  246.  
  247.  
  248. }
  249.  
  250.  
  251. static void trydo()
  252. {
  253. int n = 0;
  254.  
  255. StreamReader fileRead = new StreamReader("BD.txt", Encoding.Default);
  256. string[] Filemass1 = fileRead.ReadToEnd().Split('#');
  257. int countBds = Filemass1.Length - 1;
  258.  
  259.  
  260. string [] text = File.ReadAllLines("BD.txt", Encoding.Default);
  261. string[,] bds = new string[countBds, 8];
  262.  
  263.  
  264.  
  265. for (int i = 0; i < countBds; i++)
  266. {
  267.  
  268. for (int j = 0; j < 8; j++)
  269. {
  270. bds[i, j] = text[n];
  271. n++;
  272. Console.WriteLine($"{bds[i,j]}");
  273. }
  274.  
  275.  
  276. }
  277.  
  278. }
  279.  
  280.  
  281. static void sort()
  282. {
  283. StreamReader fileRead = new StreamReader("BD.txt", Encoding.Default);
  284. string[] Filemass1 = fileRead.ReadToEnd().Split('#');
  285. int countBds = Filemass1.Length - 1;
  286.  
  287. string[] Filemass = File.ReadAllLines("BD.txt", Encoding.Default);
  288. string[,] bds = new string[countBds, 8];
  289. int n = 0;
  290.  
  291. string[] sort = new string[countBds];
  292. int[] getsort = new int[countBds];
  293.  
  294. for (int i = 0; i < countBds; i++)
  295. {
  296.  
  297. for (int j = 0; j < 8; j++)
  298. {
  299. bds[i, j] = Filemass[n];
  300. n++;
  301. }
  302.  
  303.  
  304. }
  305.  
  306. for (int i = 0; i< countBds; i++)
  307. {
  308. sort[i] = $"{bds[i,1]} {i}";
  309. }
  310.  
  311. Array.Sort(sort);
  312.  
  313. string help = null;
  314. for (int i = 0; i < countBds; i++)
  315. {
  316. help = sort[i];
  317. sort[i] = help[help.Length-1].ToString();
  318. getsort[i] = Convert.ToInt32(sort[i]);
  319. }
  320.  
  321.  
  322. Console.WriteLine($"\nСортировка по алфовиту:\n");
  323.  
  324. for (int i =0; i<countBds; i++)
  325. {
  326. for (int j = 0; j<8; j++)
  327. {
  328. Console.WriteLine(bds[getsort[i], j]);
  329. }
  330. }
  331.  
  332.  
  333.  
  334. //sort data.
  335.  
  336.  
  337. }
  338.  
  339.  
  340. static void ADDDELL()
  341. {
  342.  
  343. }
  344.  
  345. }
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement