Advertisement
cherepenkovaa

weather

Apr 7th, 2020
1,289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.07 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.  
  7. namespace Фоновая_4._2
  8. {
  9. enum Weather { солнечно, облачно, пасмурно, дождь, снег}
  10. class Weather2
  11. {
  12. int date;
  13. int month;
  14. Weather[] weather = new Weather[31];
  15. int[] temperature = new int[31];
  16. static Random rnd = new Random();
  17. public Weather2()
  18. {
  19. date = 1; month = 1;
  20. for (int i = date - 1; i < weather.Length; i++)
  21. {
  22. weather[i] = (Weather)rnd.Next(0, 5);
  23. }
  24. for (int i = date - 1; i < temperature.Length; i++)
  25. {
  26. temperature[i] = rnd.Next(-30, 30);
  27. }
  28. }
  29. public int Days
  30. {
  31. get { return 32 - date; }
  32. }
  33. public static bool operator > (Weather2 ob1, Weather2 ob2)
  34. {
  35. if (ob1.Days > ob2.Days)
  36. return true;
  37. else
  38. return false;
  39. }
  40. public static bool operator <(Weather2 ob1, Weather2 ob2)
  41. {
  42. if (ob1.Days < ob2.Days)
  43. return true;
  44. else
  45. return false;
  46. }
  47. public static Weather2 operator ++(Weather2 ob)
  48. {
  49. ob.date--;
  50. return ob;
  51. }
  52. public static Weather2 operator(Weather2 ob)
  53. {
  54. ob.date++;
  55. return ob;
  56. }
  57. public static bool operator true(Weather2 ob)
  58. {
  59. bool a=true;
  60. for (int i = ob.date-1; i < 31; i++)
  61. {
  62. if (ob.temperature[i] < 0)
  63. {
  64. a = false;
  65. break;
  66. }
  67. }
  68. return a;
  69. }
  70. public static bool operator false(Weather2 ob)
  71. {
  72. bool a = true;
  73. for (int i = ob.date - 1; i < 31; i++)
  74. {
  75. if (ob.temperature[i] < 0)
  76. {
  77. a = false;
  78. break;
  79. }
  80. }
  81. return a;
  82. }
  83. public int this[int i]
  84. {
  85. get
  86. {
  87. try
  88. {
  89. if (i > 31) throw new Exception("Столько дней в месяце не бывает");
  90. else
  91. return temperature[i - 1];
  92. }
  93. catch(Exception error)
  94. {
  95. Console.Write("Ошибка" + error.Message);
  96. return 100000000;
  97. }
  98. }
  99. set {
  100. try
  101. {
  102. if (i > 31) throw new Exception("Столько дней в месяце не бывает");
  103. else
  104. temperature[i - 1]=value;
  105. }
  106. catch (Exception error)
  107. {
  108. Console.Write("Ошибка" + error.Message);
  109. }
  110. }
  111. }
  112. public Weather2(int date, int month)
  113. {
  114. this.date = date; this.month = month;
  115. for (int i = date - 1; i < weather.Length; i++)
  116. {
  117. weather[i] = (Weather)rnd.Next(0, 5);
  118. }
  119. for (int i = date - 1; i < temperature.Length; i++)
  120. {
  121. temperature[i] = rnd.Next(-20, 20);
  122. }
  123. }
  124. //public int min()
  125. //{
  126. // int Min = temperature[30];
  127. // for (int i = 30; i > date-1; i--)
  128. // {
  129. // if (temperature[i] < Min)
  130. // Min = temperature[i];
  131. // }
  132. // return Min;
  133. //}
  134.  
  135. public void Output()
  136. {
  137. Console.Write("Дата ");
  138. for (int i = date; i < 32; i++)
  139. {
  140. Console.Write("{0}.{1} ", i, month);
  141. }
  142. Console.WriteLine();
  143. Console.Write("Температура ");
  144. for (int i = date-1; i < 31; i++)
  145. {
  146. Console.Write("{0}° ", temperature[i]);
  147. }
  148. Console.WriteLine();
  149. Console.Write("Погода ");
  150. for (int i = date - 1; i < 31; i++)
  151. {
  152. Console.Write("{0} ", weather[i]);
  153. }
  154. Console.WriteLine();
  155. }
  156. public int Date
  157. {
  158. set {
  159. try
  160. {
  161. if (value <= 0) throw new Exception("День не может быть отрицательной");
  162. else date = value;
  163. }
  164. catch (Exception error)
  165. {
  166. Console.WriteLine("Ошибка" + error.Message);
  167. }
  168. }
  169. get { return date; }
  170. }
  171. public int Cold
  172. {
  173. get
  174. {
  175. int x = date - 1, min = 31;
  176. for (int i = date-1; i < temperature.Length-1; i++)
  177. {
  178. if(min>temperature[i])
  179. {
  180. min = temperature[i];
  181. x = i;
  182. }
  183. }
  184. return x + 1;
  185. }
  186. }
  187. public int Hot
  188. {
  189. get
  190. {
  191. int x = date - 1, max = -31;
  192. for (int i = date - 1; i < temperature.Length-1; i++)
  193. {
  194. if (max < temperature[i])
  195. {
  196. max = temperature[i];
  197. x = i;
  198. }
  199. }
  200. return x + 1;
  201. }
  202. }
  203. }
  204. class Program
  205. {
  206. static void Main(string[] args)
  207. {
  208. int a = int.Parse(Console.ReadLine());
  209. int b = int.Parse(Console.ReadLine());
  210. Weather2 ob1 = new Weather2(a, b);
  211. ob1.Output();
  212. //Console.WriteLine("Минимальная температура: {0}°", ob1.min());
  213. Console.WriteLine("Дней проводилось наблюдение: {0}", ob1.Days);
  214. Console.WriteLine("Отсчет начинается с {0} дня", ob1.Date);
  215. Console.Write("Введите новую дату: ");
  216. int x = int.Parse(Console.ReadLine());
  217. ob1.Date = x;
  218. ob1.Output();
  219. Console.WriteLine("Самый
  220.  
  221. холодный день: {0}", ob1.Cold);
  222. Console.WriteLine("Самый горячий день: {0}", ob1.Hot);
  223. Console.Write("Теперь введите сами:");
  224. a = int.Parse(Console.ReadLine());
  225. b = int.Parse(Console.ReadLine());
  226. Weather2 ob2 = new Weather2(a, b);
  227. if (ob1 > ob2)
  228. Console.WriteLine("в первом дневнике больше дней отслеживается");
  229. else
  230. Console.WriteLine("во втором дневнике больше дней отслеживается");
  231. Console.WriteLine("Убрали одну запись первого дневника");
  232. ob1--;
  233. ob1.Output();
  234. Console.WriteLine("Добавили одну запись второго дневника");
  235. ob2++;
  236. ob2.Output();
  237. if (ob1)
  238. Console.WriteLine("Температура не падала ниже 0");
  239. else
  240. Console.WriteLine("Температура падала ниже 0");
  241. Console.Write("Какой день вам нужен? ");
  242. int q = int.Parse(Console.ReadLine());
  243. Console.WriteLine(ob2[q]);
  244. Console.ReadKey();
  245. }
  246. }
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement