Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Фоновая_4._2
- {
- enum Weather { солнечно, облачно, пасмурно, дождь, снег}
- class Weather2
- {
- int date;
- int month;
- Weather[] weather = new Weather[31];
- int[] temperature = new int[31];
- static Random rnd = new Random();
- public Weather2()
- {
- date = 1; month = 1;
- for (int i = date - 1; i < weather.Length; i++)
- {
- weather[i] = (Weather)rnd.Next(0, 5);
- }
- for (int i = date - 1; i < temperature.Length; i++)
- {
- temperature[i] = rnd.Next(-30, 30);
- }
- }
- public int Days
- {
- get { return 32 - date; }
- }
- public static bool operator > (Weather2 ob1, Weather2 ob2)
- {
- if (ob1.Days > ob2.Days)
- return true;
- else
- return false;
- }
- public static bool operator <(Weather2 ob1, Weather2 ob2)
- {
- if (ob1.Days < ob2.Days)
- return true;
- else
- return false;
- }
- public static Weather2 operator ++(Weather2 ob)
- {
- ob.date--;
- return ob;
- }
- public static Weather2 operator —(Weather2 ob)
- {
- ob.date++;
- return ob;
- }
- public static bool operator true(Weather2 ob)
- {
- bool a=true;
- for (int i = ob.date-1; i < 31; i++)
- {
- if (ob.temperature[i] < 0)
- {
- a = false;
- break;
- }
- }
- return a;
- }
- public static bool operator false(Weather2 ob)
- {
- bool a = true;
- for (int i = ob.date - 1; i < 31; i++)
- {
- if (ob.temperature[i] < 0)
- {
- a = false;
- break;
- }
- }
- return a;
- }
- public int this[int i]
- {
- get
- {
- try
- {
- if (i > 31) throw new Exception("Столько дней в месяце не бывает");
- else
- return temperature[i - 1];
- }
- catch(Exception error)
- {
- Console.Write("Ошибка" + error.Message);
- return 100000000;
- }
- }
- set {
- try
- {
- if (i > 31) throw new Exception("Столько дней в месяце не бывает");
- else
- temperature[i - 1]=value;
- }
- catch (Exception error)
- {
- Console.Write("Ошибка" + error.Message);
- }
- }
- }
- public Weather2(int date, int month)
- {
- this.date = date; this.month = month;
- for (int i = date - 1; i < weather.Length; i++)
- {
- weather[i] = (Weather)rnd.Next(0, 5);
- }
- for (int i = date - 1; i < temperature.Length; i++)
- {
- temperature[i] = rnd.Next(-20, 20);
- }
- }
- //public int min()
- //{
- // int Min = temperature[30];
- // for (int i = 30; i > date-1; i--)
- // {
- // if (temperature[i] < Min)
- // Min = temperature[i];
- // }
- // return Min;
- //}
- public void Output()
- {
- Console.Write("Дата ");
- for (int i = date; i < 32; i++)
- {
- Console.Write("{0}.{1} ", i, month);
- }
- Console.WriteLine();
- Console.Write("Температура ");
- for (int i = date-1; i < 31; i++)
- {
- Console.Write("{0}° ", temperature[i]);
- }
- Console.WriteLine();
- Console.Write("Погода ");
- for (int i = date - 1; i < 31; i++)
- {
- Console.Write("{0} ", weather[i]);
- }
- Console.WriteLine();
- }
- public int Date
- {
- set {
- try
- {
- if (value <= 0) throw new Exception("День не может быть отрицательной");
- else date = value;
- }
- catch (Exception error)
- {
- Console.WriteLine("Ошибка" + error.Message);
- }
- }
- get { return date; }
- }
- public int Cold
- {
- get
- {
- int x = date - 1, min = 31;
- for (int i = date-1; i < temperature.Length-1; i++)
- {
- if(min>temperature[i])
- {
- min = temperature[i];
- x = i;
- }
- }
- return x + 1;
- }
- }
- public int Hot
- {
- get
- {
- int x = date - 1, max = -31;
- for (int i = date - 1; i < temperature.Length-1; i++)
- {
- if (max < temperature[i])
- {
- max = temperature[i];
- x = i;
- }
- }
- return x + 1;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int a = int.Parse(Console.ReadLine());
- int b = int.Parse(Console.ReadLine());
- Weather2 ob1 = new Weather2(a, b);
- ob1.Output();
- //Console.WriteLine("Минимальная температура: {0}°", ob1.min());
- Console.WriteLine("Дней проводилось наблюдение: {0}", ob1.Days);
- Console.WriteLine("Отсчет начинается с {0} дня", ob1.Date);
- Console.Write("Введите новую дату: ");
- int x = int.Parse(Console.ReadLine());
- ob1.Date = x;
- ob1.Output();
- Console.WriteLine("Самый
- холодный день: {0}", ob1.Cold);
- Console.WriteLine("Самый горячий день: {0}", ob1.Hot);
- Console.Write("Теперь введите сами:");
- a = int.Parse(Console.ReadLine());
- b = int.Parse(Console.ReadLine());
- Weather2 ob2 = new Weather2(a, b);
- if (ob1 > ob2)
- Console.WriteLine("в первом дневнике больше дней отслеживается");
- else
- Console.WriteLine("во втором дневнике больше дней отслеживается");
- Console.WriteLine("Убрали одну запись первого дневника");
- ob1--;
- ob1.Output();
- Console.WriteLine("Добавили одну запись второго дневника");
- ob2++;
- ob2.Output();
- if (ob1)
- Console.WriteLine("Температура не падала ниже 0");
- else
- Console.WriteLine("Температура падала ниже 0");
- Console.Write("Какой день вам нужен? ");
- int q = int.Parse(Console.ReadLine());
- Console.WriteLine(ob2[q]);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement