コード例 #1
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();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ArtemHryniuk/OOP-Tasks
        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}");
        }
コード例 #3
0
            static void Main(string[] args)
            {
                WeatherDays july = new WeatherDays();

                july.FileOrKeyboard();

                Console.ReadKey();
            }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.Unicode;
            Console.InputEncoding  = Encoding.Unicode;

            WeatherDays july = new WeatherDays();

            july.FromFileOrKeyboard();

            Console.ReadKey();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: MarynaOhorodnik/OOP_tasks
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.Unicode;
            Console.InputEncoding  = Encoding.Unicode;

            const int days_in_month = 5;

            WeatherDays weather_days = new WeatherDays();

            weather_days.GetData(days_in_month);

            Console.WriteLine("\nВиводимо інформацію за місяць:");
            weather_days.Print();

            Console.WriteLine($"\nКількість туманних днів: {weather_days.Count_Days_Fog()}");
            Console.WriteLine($"\nКількість днів коли не було опадів: {weather_days.Count_Days_Without_Precipitation()}");
            Console.WriteLine($"\nМаксимальний тиск за місяць: {weather_days.Max_atmospheric_pressure()}");
            Console.WriteLine($"\nМінімальний тиск за місяць: {weather_days.Min_atmospheric_pressure()}");
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Eger37/OOP_C_Sharp
        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();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Eger37/OOP_C_Sharp
        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);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Eger37/OOP_C_Sharp
        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);
        }