Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace V_labaratorinis
  9. {
  10. class Lecturer
  11. {
  12. const int Cn = 100;
  13. private string lastname;
  14. private string name;
  15. private string faculty;
  16. private string cathedral;
  17. private int hours;
  18. public Lecturer()
  19. {
  20. lastname = "";
  21. name = "";
  22. faculty = "";
  23. cathedral = "";
  24. hours = 0;
  25. }
  26. public Lecturer(string lastname, string name, string faculty, string cathedral)
  27. {
  28.  
  29. this.lastname = lastname;
  30. this.name = name;
  31. this.faculty = faculty;
  32. this.cathedral = cathedral;
  33. }
  34. public override string ToString()
  35. {
  36. string eilute;
  37. eilute = string.Format("| {0, -12}| {1,-11}| {2,-18}|{3,-35}|",
  38. lastname, name, faculty, cathedral);
  39. return eilute;
  40. }
  41. public static bool operator <=(Lecturer L1, Lecturer L2)
  42. {
  43. int p = String.Compare(L1.faculty, L2.faculty);
  44. return (p < 0);
  45. }
  46.  
  47. public static bool operator >=(Lecturer L1, Lecturer L2)
  48. {
  49. int p = String.Compare(L1.faculty, L2.faculty);
  50. return p > 0;
  51. }
  52. public void PutHours(int hour, Lecturer L)
  53. {
  54. L.hours = hour;
  55. }
  56. public int Takehours() { return hours; }
  57. }
  58. class LecturesByTeacher
  59. {
  60. const int CMaxEil = 100; // didžiausias galimas savaičių skaičius
  61. const int CMaxSt = 30; // didžiausias galimas stulpelių (dienų) skaičius
  62. private int [,] L; // duomenų matrica
  63. public int n { get; set; } // eilučių skaičius (savaičių skaičius)
  64. public int m { get; set; } // stulpelių skaičius (dienų skaičius)
  65. public LecturesByTeacher()
  66. {
  67. n = 0;
  68. m = 0;
  69. L = new int [CMaxEil, CMaxSt];
  70. }
  71. public void Put(int i, int j, int numb)
  72. {
  73. L[i, j] = numb;
  74. }
  75. public int TakeNumb(int i, int j)
  76. {
  77. return L[i, j];
  78. }
  79.  
  80. }
  81. class University
  82. {
  83. const int Cn = 100;
  84. private Lecturer[] L;
  85. public int k = 0;
  86.  
  87. public University()
  88. {
  89. k = 0;
  90. L = new Lecturer[Cn];
  91. }
  92. public int Took() { return k; }
  93. public Lecturer Take(int i) { return L[i]; }
  94. public void Put(Lecturer ob) { L[k++] = ob; }
  95. public void Rikiuoti()
  96. {
  97. for (int i = 0; i < k - 1; i++)
  98. {
  99. Lecturer min = L[i];
  100. int im = i;
  101. for (int j = i; j < k; j++)
  102. {
  103. if (L[j] <= min)
  104. {
  105. min = L[j];
  106. im = j;
  107. }
  108. }
  109. L[im] = L[i];
  110. L[i] = min;
  111. }
  112. }
  113.  
  114. }
  115. class Program
  116. {
  117. const int Cn = 100;
  118. const string Cfd = "Data.txt";
  119. const string CFr = "Rezults.txt";
  120. static void Main(string[] args)
  121. {
  122. if (File.Exists(CFr))
  123. File.Delete(CFr);
  124. University university = new University();
  125. LecturesByTeacher lecturesByTeacher = new LecturesByTeacher();
  126. double avelect=0;
  127. ReadLecturerAndData(Cfd, university, ref lecturesByTeacher, ref avelect);
  128. WritingToFileFirstDate(CFr, university, lecturesByTeacher);
  129. int[] D = new int[lecturesByTeacher.m];
  130. AllWentForLectures(lecturesByTeacher, ref D);
  131. HowmanyHoursWorked(university, lecturesByTeacher);
  132. university.Rikiuoti();
  133. WriteAnsersToFile(CFr, D,university,avelect);
  134. Console.WriteLine("Baigiu darba!");
  135.  
  136. }
  137. static void ReadLecturerAndData(string fd, University U, ref LecturesByTeacher K , ref double avelect)
  138. {
  139. int quantlecturer, daysofmonth;
  140. string line, name, lastname, faculty, cathedral;
  141. int hours;
  142. using (StreamReader reader = new StreamReader(fd))
  143. {
  144. line = reader.ReadLine();
  145. string[] parts;
  146. quantlecturer = int.Parse(line);
  147. line = reader.ReadLine();
  148. daysofmonth = int.Parse(line);
  149. line = reader.ReadLine();
  150. avelect = double.Parse(line);
  151. K.n = quantlecturer;
  152. K.m = daysofmonth;
  153. for (int i = 0; i < quantlecturer; i++)
  154. {
  155. line = reader.ReadLine();
  156. parts = line.Split(';');
  157. lastname = parts[0];
  158. name = parts[1];
  159. faculty = parts[2];
  160. cathedral = parts[3];
  161. Lecturer L = new Lecturer(lastname, name,faculty, cathedral);
  162. U.Put(L);
  163. }
  164. for (int i = 0; i < quantlecturer; i++)
  165. {
  166. line = reader.ReadLine();
  167. parts = line.Split(';');
  168. for (int j = 0; j < daysofmonth; j++)
  169. {
  170. hours = int.Parse(parts[j]);
  171. K.Put(i, j, hours);
  172. }
  173. }
  174. }
  175. }
  176. static void WritingToFileFirstDate(string CFr, University U, LecturesByTeacher K)
  177. {
  178. using (var fr = File.AppendText(CFr))
  179. {
  180. fr.WriteLine("Lectures number: {0}",K.n);
  181. fr.WriteLine("Days: {0}", K.m);
  182. const string top = "|-----------------|----------------|-------------------------|-----------------------------------|\n" +
  183. "| LastName | Name | Faculty | Cathedral |\n" +
  184. "| | | | |\n" +
  185. "|-----------------|----------------|-------------------------|-----------------------------------|\n";
  186. fr.Write(top);
  187. for (int i=0; i<K.n; i++)
  188. {
  189. fr.WriteLine("{0}", U.Take(i).ToString());
  190. }
  191. fr.WriteLine("|-----------------|----------------|-------------------------|-----------------------------------|");
  192. fr.WriteLine("---------------------------------------------------");
  193. fr.Write("Dienos |");
  194. for (int i = 0; i < K.m; i++)
  195. fr.Write(" {0,-2}|", i + 1);
  196. fr.WriteLine();
  197. for (int i=0; i<K.n; i++)
  198. {
  199. fr.Write("Dėstytojas nr.{0} |", i+1);
  200. for (int j = 0; j < K.m; j++)
  201. fr.Write(" {0,-2}|",K.TakeNumb(i,j));
  202. fr.WriteLine("");
  203. }
  204. fr.WriteLine("---------------------------------------------------");
  205. }
  206. }
  207. static void AllWentForLectures(LecturesByTeacher K, ref int [] D)
  208. {
  209. int days = 0;
  210. int p = 0; // pozymis
  211. for (int j=0; j<K.m; j++)
  212. {
  213. for (int i=0; i<K.n; i++)
  214. {
  215. if (K.TakeNumb(i, j) > 0)
  216. p = 1;
  217. else { p = 0; i = K.n; }
  218.  
  219. }
  220. if (p == 1)
  221. { D[days] = 1; days++; }
  222. else if (p == 0) { D[days] = 0; days++; }
  223. }
  224. }
  225. static void HowmanyHoursWorked (University U, LecturesByTeacher K)
  226. {
  227. int hours = 0;
  228. for (int i=0; i<K.n; i++)
  229. {
  230. for (int j=0; j<K.m; j++)
  231. {
  232. hours = K.TakeNumb(i, j) + hours;
  233. U.Take(i).PutHours(hours, U.Take(i));
  234. }
  235. hours = 0;
  236. }
  237. }
  238. static int LecturesAvarageHours(int i, University U,double avarage)
  239. {
  240. int p = 0;
  241. if (U.Take(i).Takehours() < avarage)
  242. p = 1;
  243. return p;
  244. }
  245. static void WriteAnsersToFile (string CFr,int [] D, University U, double avarage)
  246. {
  247. using (var fr = File.AppendText(CFr))
  248. {
  249. fr.WriteLine("");
  250. fr.WriteLine("Rezults");
  251. fr.WriteLine("------------------------------------------------------------------------------------------------------------");
  252. fr.Write("Which days all the lecturers taught: ");
  253. int p = 0;
  254. for (int i = 0; i < D.Length; i++)
  255. {
  256. if (D[i] == 1) p++;
  257.  
  258. }
  259. if (p != D.Length && p != 0)
  260. {
  261. for (int i = 0; i < D.Length; i++)
  262. {
  263. if (D[i] == 1)
  264. fr.Write("{0} day ", i + 1);
  265. }
  266. fr.WriteLine();
  267. }
  268. else if (p == 0)
  269. {
  270. fr.WriteLine("There are no such days");
  271. }
  272. else fr.WriteLine("Lectures worked all day together");
  273. fr.WriteLine("------------------------------------------------------------------------------------------------------------");
  274. fr.WriteLine();
  275. fr.WriteLine("Table that has lower than avarage lectures for month:");
  276. int z = 0;
  277. for (int i = 0; i < U.k; i++)
  278. {
  279. if (LecturesAvarageHours(i, U, avarage) == 1)
  280. z++;
  281. }
  282. if (z > 0)
  283. {
  284. const string top = "|-----------------|----------------|-------------------------|-----------------------------------|-----------|\n" +
  285. "| LastName | Name | Faculty | Cathedral | Number of |\n" +
  286. "| | | | | days |\n" +
  287. "|-----------------|----------------|-------------------------|-----------------------------------|-----------|\n";
  288. fr.Write(top);
  289. for (int i = 0; i < U.k; i++)
  290. {
  291. if (LecturesAvarageHours(i, U, avarage) == 1)
  292. fr.WriteLine("{0} {1,-6}|", U.Take(i).ToString(), U.Take(i).Takehours());
  293. }
  294. fr.WriteLine("|-----------------|----------------|-------------------------|-----------------------------------|-----------|");
  295. }
  296. else fr.WriteLine("Table can't be done ,becouse no lectures found");
  297. }
  298. }
  299. }
  300. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement