Пример #1
0
        private static void Main()
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            Console.InputEncoding  = System.Text.Encoding.UTF8;

            string path = @"../../../data.txt";

            double[][]             data = SwitchChoice(path);
            WeatherParametersDay[] weatherParametersDays = new WeatherParametersDay[data.Length];
            try
            {
                for (int i = 0; i < data.Length; i++)
                {
                    weatherParametersDays[i] = new WeatherParametersDay(data[i][0],
                                                                        data[i][1],
                                                                        data[i][2],
                                                                        data[i][3],
                                                                        (int)data[i][4]);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Не вдалось виконати програму.\n{ex.Message}");
                Environment.Exit(0);
            }
            WeatherDays weatherDays = new WeatherDays(weatherParametersDays);

            Console.Clear();
            Console.WriteLine($"Кількість туманних днів: {weatherDays.CountFogDays()}"
                              + $"\nКількість днів, коли був дощ або гроза: {weatherDays.CountRainOrThunderstormDays()}"
                              + $"\nСередній атмосферний тиск за місяць: {weatherDays.AveragePressure():f0}");
        }
Пример #2
0
        public static WeatherParametersDay[] ReadConsole(int days_in_month)
        {
            WeatherParametersDay[] array = new WeatherParametersDay[days_in_month];

            Console.WriteLine($"\nВведіть 5 значень для погоди через пробіл для кожного дня у порядку: середня температура вдень, " +
                              "середня температура вночі, середній атмосферний тиск, кількість опадів(мм / день), тип погоди за день.");

            for (int i = 0; i < days_in_month; i++)
            {
                bool Flag = true;
                while (Flag)
                {
                    Console.Write($"{i + 1}. ");
                    string[] line_split = Console.ReadLine().Split();
                    if (line_split.Length == 5)
                    {
                        double[] result = new double[line_split.Length];
                        for (int j = 0; j < line_split.Length; j++)
                        {
                            while (!double.TryParse(line_split[j], out result[j]))
                            {
                                Console.WriteLine($"\nВи вказали некоректне значення {j + 1}. Спрбуйте ще раз");
                            }
                        }
                        array[i] = new WeatherParametersDay(result[0], result[1], result[2], result[3], (TypeOfWeather)result[4]);
                        Flag     = false;
                    }
                    else
                    {
                        Console.WriteLine("Введіть 5 значень, розділяючи їх пробілом.");
                    }
                }
            }
            return(array);
        }
Пример #3
0
        public void ReadFromFile()  // читаємо з файлу
        {
            string path = @"..\data.txt";

            try
            {
                StreamReader sr   = new StreamReader(path);
                int          rows = CountRows(path);
                if (rows != 31)
                {
                    Console.WriteLine("\nКількість днів у липні 31! Зміни дані у файлі і спробуй ще раз.");
                }
                else
                {
                    for (int i = 0; i < rows; i++)
                    {
                        WeatherParametersDay day = new WeatherParametersDay();
                        julyArray[i] = day;
                        day.SetParametersFromFile(sr);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("\nФайл не знайдено. Спробуй ще раз.");
            }
        }
Пример #4
0
            public void ReadFromFile()
            {
                string path = @"..\weather_data.txt";

                try
                {
                    StreamReader sr    = new StreamReader(path);
                    int          count = 0;
                    foreach (string i in File.ReadAllLines(path))
                    {
                        count++;
                    }
                    int numberOfRows = count;
                    if (numberOfRows != 31)
                    {
                        Console.WriteLine("\nMarch has 31 days.");
                    }
                    else
                    {
                        for (int i = 0; i < numberOfRows; i++)
                        {
                            WeatherParametersDay day = new WeatherParametersDay();
                            MarchArray[i] = day;
                            day.FileDataReading(sr);
                        }
                    }
                }
                catch (FileNotFoundException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
Пример #5
0
        static void Main(string[] args)
        {
            Console.InputEncoding  = System.Text.Encoding.Unicode;
            Console.OutputEncoding = System.Text.Encoding.Unicode;

            WeatherParametersDay.GetDayTemperature_File();
            WeatherParametersDay.OutputDayTemperature();

            WeatherParametersDay.GetNightTemperature_File();
            WeatherParametersDay.OutputNightTemperature();

            WeatherParametersDay.GetAtmospherePressure_File();
            WeatherParametersDay.OutputAtmospherePressure();

            WeatherParametersDay.GetPrecipitation();
            WeatherParametersDay.OutputPrecipitation();

            WeatherParametersDay.GetWeatherType();
            WeatherParametersDay.OutputWeatherType();

            WeatherDays.NumberCloudyDays();
            WeatherDays.OutputConsoleNumberCloudyDays();

            WeatherDays.NumberRainyDays();
            WeatherDays.OutputConsoleNumberRainyDays();

            WeatherDays.MidPrecipitation();
            WeatherDays.OutputConsoleMidPrecipitation();
        }
Пример #6
0
 public void ReadFromKeyboard()
 {
     for (int i = 0; i < 31; i++)
     {
         WeatherParametersDay day = new WeatherParametersDay();
         MarchArray[i] = day;
         day.KeyboardInput();
     }
 }
Пример #7
0
 public void ReadFromKeyboard()  // читаємо з клавіатури
 {
     for (int i = 0; i < 31; i++)
     {
         WeatherParametersDay day = new WeatherParametersDay();
         julyArray[i] = day;
         day.SetParameters();
     }
 }
Пример #8
0
        private int CountDays(params TypeOfWeather[] typeOfWeather)
        {
            int count = 0;

            for (int i = 0; i < DataWeatherArray.Length; i++)
            {
                WeatherParametersDay day = DataWeatherArray[i];
                count += typeOfWeather.Contains(day.TypeOfWeather) ? 1 : 0;
            }
            return(count);
        }
Пример #9
0
        public double AveragePressure()
        {
            double sumOfAtmosphericPressure = 0;

            for (int i = 0; i < DataWeatherArray.Length; i++)
            {
                WeatherParametersDay day = DataWeatherArray[i];
                sumOfAtmosphericPressure += day.AverageAtmosphericPressure;
            }
            return(sumOfAtmosphericPressure / DataWeatherArray.Length);
        }
Пример #10
0
        public override string ToString()
        {
            string AllText = ("\nДень Температура днём (\u00b0C) Температура ночью (\u00b0C) Атмосферное давление (мм рт. ст.) Осадки (мм) Тип погоды");
            int    idx     = 0;

            while (idx != ArrWeatherDays.Length)
            {
                WeatherParametersDay day = ArrWeatherDays[idx];
                string NewDayParams      = $"\n{idx + 1}\t{day.AverageTemperaturePerDay}\t\t\t{day.AverageTemperatureAtNight}\t\t\t\t{day.AverageAtmosphericPressure}\t\t\t{day.Precipitation}\t{day.TypeOfWeatherAtDay}";
                AllText = AllText + NewDayParams;
                idx++;
            }
            return(AllText + "\n");
        }
Пример #11
0
        public int NumberOfGloomyDays()
        {
            int nogd  = 0;
            int count = 0;

            while (count != ArrWeatherDays.Length)
            {
                WeatherParametersDay day = ArrWeatherDays[count];
                if (day.TypeOfWeatherAtDay == TypeOfWeather.хмуро)
                {
                    nogd++;
                }
                count++;
            }
            return(nogd);
        }
Пример #12
0
        public int NumberOfDaysWithRain()
        {
            int nodwr = 0;
            int count = 0;

            while (count != ArrWeatherDays.Length)
            {
                WeatherParametersDay day = ArrWeatherDays[count];
                if (day.TypeOfWeatherAtDay == TypeOfWeather.дождь)
                {
                    nodwr++;
                }
                count++;
            }
            return(nodwr);
        }
Пример #13
0
        public int NumberOfThunderstormDay()
        {
            int notd  = 0;
            int count = 0;

            while (count != ArrWeatherDays.Length)
            {
                WeatherParametersDay day = ArrWeatherDays[count];
                if (day.TypeOfWeatherAtDay == TypeOfWeather.гроза)
                {
                    notd++;
                }
                count++;
            }
            return(notd);
        }
Пример #14
0
        public static WeatherParametersDay[] StringToArray(string[] text_array)
        {
            WeatherParametersDay[] array = new WeatherParametersDay[text_array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                string[] line_split = text_array[i].Split();

                double[] result = new double[line_split.Length];
                for (int j = 0; j < line_split.Length; j++)
                {
                    if (!double.TryParse(line_split[j], out result[j]))
                    {
                        Console.WriteLine("\nУ файлі вказані некоректні значення. Перевірте файл та спробуйте знову.");
                        Environment.Exit(1);
                    }
                }
                array[i] = new WeatherParametersDay(result[0], result[1], result[2], result[3], (TypeOfWeather)result[4]);
            }
            return(array);
        }
Пример #15
0
        public float MaxTemperatureAtDays()
        {
            int idx   = 0;
            int count = 1;

            while (count != ArrWeatherDays.Length)
            {
                WeatherParametersDay day1 = ArrWeatherDays[idx];
                WeatherParametersDay day2 = ArrWeatherDays[count];

                if (day1.AverageTemperatureAtNight < day2.AverageTemperatureAtNight)
                {
                    idx = count;
                }
                count++;
            }
            WeatherParametersDay day = ArrWeatherDays[idx];

            return(day.AverageTemperatureAtNight);
        }
Пример #16
0
        static void Main(string[] args)
        {
            WeatherDays arrDays = WeatherDays.InputData();

            WeatherParametersDay[] arrParams = arrDays.ArrWeatherDays;
            WeatherParametersDay   firstDay  = arrParams[0];

            Console.WriteLine();
            firstDay.GetInfo();

            arrDays.PrintTable();
            arrDays.PrintNumberOfGloomyDays();
            arrDays.PrintTotalDaysWithRainOrThunderstorm();
            arrDays.PrintMinTemperatureAtNights();
            arrDays.PrintMaxTemperatureAtDays();

            //WeatherParametersDay mondey = new WeatherParametersDay(12, 6, 133, 0);
            //WeatherParametersDay tuesday = new WeatherParametersDay(13, 7, 125, 3, TypeOfWeather.кратковременный_дождь);
            //mondey.GetInfo();
            //tuesday.GetInfo();
        }
Пример #17
0
 private void insertDaySettings(int idx, WeatherParametersDay wpd)
 {
     arrWeatherDays[idx] = wpd;
 }
Пример #18
0
        private static WeatherDays InputDataFromConsole()
        {
            WeatherDays arrDaysParams;

            Console.WriteLine("Ввод из консоли");
            int numberOfDays;

            while (true)
            {
                Console.WriteLine("Введите количество дней:");
                string strNumberOfDays = Console.ReadLine();
                try
                {
                    numberOfDays = Convert.ToInt32(strNumberOfDays);
                    break;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Вы не правильно ввели данные: {ex.Message}");
                    continue;
                }
            }
            arrDaysParams = new WeatherDays(numberOfDays);

            Console.WriteLine("В слудующих строчках вводите параметры погоды дня в формате:");
            Console.WriteLine("f1 f2 f3 i s");
            Console.WriteLine("f1 = Средняя температура днём - float");
            Console.WriteLine("f2 = Средняя температура ночью - float");
            Console.WriteLine("f3 = Средняе атмосферное давление - float (мм ртутного столба");
            Console.WriteLine("i = Количество осадков - int (мм/день)");
            Console.WriteLine("s = Тип погоды в этот день - string (ниже примеры типов погоды, вводить это значение необязательно)");
            Console.WriteLine("Типы погоды: не_определено, дождь, кратковременный_дождь, гроза, снег, туман, хмуро, солнечно\n");

            int count = 0;

            while (count != numberOfDays)
            {
                while (true)
                {
                    Console.WriteLine($"Вводите параметры {count + 1} дня:");
                    string   nextLine  = Console.ReadLine();
                    string[] splitLine = nextLine.Split(" ");
                    if (splitLine.Length != 4 & splitLine.Length != 5)
                    {
                        Console.WriteLine($"Данные введены неверно");
                        continue;
                    }
                    try
                    {
                        float         AverageTemperaturePerDay   = float.Parse(splitLine[0], System.Globalization.CultureInfo.InvariantCulture);
                        float         AverageTemperatureAtNight  = float.Parse(splitLine[1], System.Globalization.CultureInfo.InvariantCulture);
                        float         AverageAtmosphericPressure = float.Parse(splitLine[2], System.Globalization.CultureInfo.InvariantCulture);
                        int           Precipitation      = Convert.ToInt32(splitLine[3]);
                        TypeOfWeather TypeOfWeatherAtDay = TypeOfWeather.не_определено;
                        if (splitLine.Length == 5)
                        {
                            TypeOfWeatherAtDay = (TypeOfWeather)Enum.Parse(typeof(TypeOfWeather), splitLine[4], true);
                        }
                        WeatherParametersDay dayParams = new WeatherParametersDay(AverageTemperaturePerDay, AverageTemperatureAtNight, AverageAtmosphericPressure, Precipitation, TypeOfWeatherAtDay);
                        arrDaysParams.insertDaySettings(count, dayParams);
                        break;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Данные введены неверно");
                        Console.WriteLine($"Ошибка: {ex.Message}");
                        continue;
                    }
                }
                count++;
            }

            return(arrDaysParams);
        }
Пример #19
0
        private static WeatherDays InputDataFromFile()
        {
            WeatherDays arrDaysParams;

            Console.WriteLine("Ввод из файла");
            Console.WriteLine("В первой строчке введите количество дней.");
            Console.WriteLine("В слудующих строчках вводите параметры погоды дня в формате:");
            Console.WriteLine("f1 f2 f3 i s");
            Console.WriteLine("f1 = Средняя температура днём - float");
            Console.WriteLine("f2 = Средняя температура ночью - float");
            Console.WriteLine("f3 = Средняе атмосферное давление - float (мм ртутного столба");
            Console.WriteLine("i = Количество осадков - int (мм/день)");
            Console.WriteLine("s = Тип погоды в этот день - string (ниже примеры типов погоды, вводить это значение необязательно)");
            Console.WriteLine("Типы погоды: не_определено, дождь, кратковременный_дождь, гроза, снег, туман, хмуро, солнечно\n");

            string PathToFile = "D:/OneDrive - ДонНУ/Рабочий стол/Univer/WeatherDays.txt";

            //string PathToFile = "C:/Users/Admin/Desktop/Univer/WeatherDays.txt";
            while (true)
            {
                bool restartRead = false;
                if (!File.Exists(PathToFile))
                {
                    Console.WriteLine($"Файл не найден, создайте файл WeatherDays.txt по пути {PathToFile}");
                    Console.WriteLine("Нажмите \"Enter\", если создали файл");
                    Console.ReadLine();
                    continue;
                }
                int numberOfDays;
                using (StreamReader fileData = new StreamReader(PathToFile))
                {
                    //StreamReader fileData = new StreamReader(PathToFile);
                    string firstLine = fileData.ReadLine();

                    if (firstLine == null)
                    {
                        Console.WriteLine($"Файл {Path.GetFileName(PathToFile)} пустой, введите в него данные!");
                        fileData.Close();
                        Console.WriteLine("Нажмите \"Enter\", если изменили файл");
                        Console.ReadLine();
                        continue;
                    }
                    try
                    { numberOfDays = Convert.ToInt32(firstLine); }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Вы не правильно ввели данные: {ex.Message}");
                        fileData.Close();
                        Console.WriteLine("Нажмите \"Enter\", если изменили файл");
                        Console.ReadLine();
                        continue;
                    }
                    arrDaysParams = new WeatherDays(numberOfDays);
                    int count = 0;
                    while (count != numberOfDays)
                    {
                        string nextLine = fileData.ReadLine();
                        if (nextLine == null)
                        {
                            Console.WriteLine($"В строке {count + 2} пусто");
                            fileData.Close();
                            Console.WriteLine("Нажмите \"Enter\", если исправили строку");
                            Console.ReadLine();
                            restartRead = true;
                            break;
                        }
                        string[] splitLine = nextLine.Split(" ");
                        if (splitLine.Length != 4 & splitLine.Length != 5)
                        {
                            Console.WriteLine($"В строке {count + 2} данные введены неверно");
                            fileData.Close();
                            //Console.WriteLine($"count: {count}, splitLine.Length {splitLine.Length}");
                            Console.WriteLine("Нажмите \"Enter\", если исправили строку");
                            Console.ReadLine();
                            restartRead = true;
                            break;
                        }
                        try
                        {
                            float         AverageTemperaturePerDay   = float.Parse(splitLine[0], System.Globalization.CultureInfo.InvariantCulture);
                            float         AverageTemperatureAtNight  = float.Parse(splitLine[1], System.Globalization.CultureInfo.InvariantCulture);
                            float         AverageAtmosphericPressure = float.Parse(splitLine[2], System.Globalization.CultureInfo.InvariantCulture);
                            int           Precipitation      = Convert.ToInt32(splitLine[3]);
                            TypeOfWeather TypeOfWeatherAtDay = TypeOfWeather.не_определено;
                            if (splitLine.Length == 5)
                            {
                                TypeOfWeatherAtDay = (TypeOfWeather)Enum.Parse(typeof(TypeOfWeather), splitLine[4], true);
                            }
                            WeatherParametersDay dayParams = new WeatherParametersDay(AverageTemperaturePerDay, AverageTemperatureAtNight, AverageAtmosphericPressure, Precipitation, TypeOfWeatherAtDay);
                            arrDaysParams.insertDaySettings(count, dayParams);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"В строке {count + 2} данные введены неверно");
                            Console.WriteLine($"Ошибка: {ex.Message}");
                            fileData.Close();
                            Console.WriteLine("Нажмите \"Enter\", если исправили строку");
                            Console.ReadLine();
                            restartRead = true;
                            break;
                        }
                        count++;
                        if (restartRead)
                        {
                            break;
                        }
                    }
                    if (restartRead)
                    {
                        continue;
                    }
                }

                break;
            }
            Console.WriteLine("\nФайл принят");
            return(arrDaysParams);
        }