public static void GetMaxMinTemperature() { var maxValue = 0; var minValue = 1000; List <Tavirat> maxTemp = new List <Tavirat>(); List <Tavirat> minTemp = new List <Tavirat>(); foreach (Tavirat item in tElements) { while (item.Temp != 0 && maxValue < item.Temp) { maxTemp.Clear(); maxValue = item.Temp; Tavirat op = new Tavirat(item.Station, item.Time, item.Dow, item.Temp); maxTemp.Add(op); } while (item.Temp != 0 && minValue > item.Temp) { minTemp.Clear(); minValue = item.Temp; Tavirat op = new Tavirat(item.Station, item.Time, item.Dow, item.Temp); minTemp.Add(op); } } Console.Write($"A minimum hőmrséklet: "); ShowFormatedLines(minTemp[0]); Console.Write($"A maximum hőmrséklet: "); ShowFormatedLines(maxTemp[0]); }
public static void GetZeroWind() { List <Tavirat> zeroWind = new List <Tavirat>(); foreach (Tavirat item in tElements) { if (item.Dow == "00000") { Tavirat op = new Tavirat(item.Station, item.Time, item.Dow, item.Temp); zeroWind.Add(op); } } if (zeroWind.Count() == 0) { Console.WriteLine($"Nincs szélcsendes időszak!"); } else { Console.WriteLine($"Találatok száma: {zeroWind.Count()}"); Console.WriteLine("Szélcsendes települések, és időszakok:"); foreach (Tavirat item in zeroWind) { Console.WriteLine(item.Station + " " + item.TimeFormatShow(item.Time)); } } }
// 2. FELADAT public static void GetLastMeasurementMoment() { Console.WriteLine("2. Feladat"); Console.Write("Adja meg egy település kódját! Település:"); string userData = Console.ReadLine().ToUpper(); while (!Cities.Contains(userData)) { Console.WriteLine("A kfiejezés nem szerepel a városkódok között!\nAz alábbiak közül tudsz váalsztani:"); Console.WriteLine(string.Join(", ", Cities)); Console.Write("\nAdja meg egy település kódját! Település:"); userData = Console.ReadLine().ToUpper(); } string time = ""; for (int i = tElements.Count - 1; i >= 0; i--) { if (userData == tElements[i].Station) { time = tElements[i].Time; break; } } Console.WriteLine(time); Tavirat tv = new Tavirat(); string tm = Convert.ToString(time); Console.WriteLine($"Az utolsó mérési adat {userData} településről {tv.TimeFormatShow(tm)} időpontban érkezett!\n"); }
// 3. FELADAT public static void GetMaxMinTemperature() { Tavirat minTemp = tElements[0]; Tavirat maxTemp = tElements[0]; Console.WriteLine("3. Feladat"); for (int i = 0; i < tElements.Count; i++) { if (minTemp.Temp > tElements[i].Temp) { minTemp = tElements[i]; } if (maxTemp.Temp < tElements[i].Temp) { maxTemp = tElements[i]; } } Console.Write($"A minimum hőmrséklet: "); Console.WriteLine($"{minTemp.Station} {minTemp.TimeFormatShow(minTemp.Time)} {minTemp.Temp} fok"); Console.Write($"A maximum hőmrséklet: "); Console.WriteLine($"{maxTemp.Station} {maxTemp.TimeFormatShow(maxTemp.Time)} {maxTemp.Temp} fok"); }
static void Main(string[] args) { string filePath = "tavirathu13.txt"; FileStream fs = new FileStream(filePath, FileMode.Open); StreamReader sr = new StreamReader(fs, Encoding.Default); while (!sr.EndOfStream) { Tavirat temp = new Tavirat("", "", "", 0); try { string[] puffer = sr.ReadLine().Split(' '); string a = puffer[0]; string b = puffer[1]; string c = puffer[2]; int d = Convert.ToInt32(puffer[3]); if (a.Length != 2) { a = "err"; } if (b == "") { b = "err"; } if (c == "") { c = "err"; } temp = new Tavirat(a, b, c, d); Tavirat.tElements.Add(temp); } catch (Exception) { temp = new Tavirat("err", "err", "err", 0); Tavirat.tElements.Add(temp); } } Console.WriteLine($"Sorok száma: { Tavirat.tElements.Count()}"); sr.Close(); fs.Close(); Tavirat.GetLastMeasurementMoment(); Tavirat.GetMaxMinTemperature(); Tavirat.GetZeroWind(); Tavirat.GetMedTempAndFluct(); Console.ReadKey(); }
public static void ShowFormatedLines(Tavirat item) { if (item.Station == "err" || item.Time == "err" || item.Dow == "err" || item.Temp == 0) { Console.ForegroundColor = ConsoleColor.Red; } Console.WriteLine(item.Station + " " + item.TimeFormatShow(item.Time) + " " + item.DowFormatShow(item.Dow) + " " + item.TempFormatShow(item.Temp)); Console.ForegroundColor = ConsoleColor.White; }
// 5.1 FELADAT private static void createPufferList(List <string> Cities, List <Tavirat> MedTempList, int i) { foreach (Tavirat item in tElements) { if (item.Station == Cities[i]) { Tavirat op = new Tavirat(item.Station, item.Time, item.Dow, item.Temp); MedTempList.Add(op); } } }
// 1. FELADAT public static void ReadDataFromTXT() { string filePath = "tavirathu13.txt"; using (FileStream fs = new FileStream(filePath, FileMode.Open)) { using (StreamReader sr = new StreamReader(fs, Encoding.Default)) { while (!sr.EndOfStream) { string[] puffer = sr.ReadLine().Split(' '); string a = puffer[0]; string b = puffer[1]; string c = puffer[2]; int d = Convert.ToInt32(puffer[3]); Tavirat temp = new Tavirat(a, b, c, d); Tavirat.tElements.Add(temp); } } } }
public static void GetMedTempAndFluct() { List <string> Cities = new List <string>(); // BP,DC,SM,PA,SN,PR,BC,PP,KE, foreach (var item in tElements) { if (!(Cities.Contains(item.Station))) { Cities.Add(item.Station); } } List <Tavirat> MedTempList = new List <Tavirat>(); for (int i = 0; i < Cities.Count; i++) { var counter = 0; var sum = 0; var maxTemp = 0; var minTemp = 100; var tempText = ""; string CityTxtPath = ""; MedTempList.Clear(); foreach (Tavirat item in tElements) { if (item.Station == Cities[i]) { Tavirat op = new Tavirat(item.Station, item.Time, item.Dow, item.Temp); MedTempList.Add(op); } } CityTxtPath = Cities[i] + ".txt"; StreamWriter sw = new StreamWriter(CityTxtPath); sw.WriteLine(Cities[i]); foreach (Tavirat item in MedTempList) { int windPower = Convert.ToInt32(item.Dow.Substring(3)); string windChar = ""; if (windPower >= 1) { for (int j = 0; j < windPower; j++) { windChar += "#"; } } else { windChar = ""; } sw.WriteLine(item.TimeFormatShow(item.Time) + " " + windChar); } sw.Flush(); sw.Close(); List <char> checkList = new List <char>(); foreach (Tavirat item in MedTempList) { if (item.Temp > maxTemp) { maxTemp = item.Temp; } if (item.Temp < minTemp) { minTemp = item.Temp; } var crit = item.Time.Substring(0, 2); switch (crit) { case "01": sum += item.Temp; counter++; checkList.Add('!'); break; case "07": sum += item.Temp; counter++; checkList.Add('!'); break; case "13": sum += item.Temp; counter++; checkList.Add('!'); break; case "19": sum += item.Temp; counter++; checkList.Add('!'); break; default: break; } } float a = (float)sum / counter; if (checkList.Count <= 4) { tempText = $"{MedTempList[i].Station} NA;"; } else { tempText = $"{MedTempList[i].Station} középhőmérséklet: {Math.Round(a)}°C"; } Console.WriteLine(tempText + $" Hőmérséklet-ingadozás: {maxTemp - minTemp}"); } }