131 lines
3.4 KiB
C#
131 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace WpfStatisztika
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
///
|
|
|
|
public partial class MainWindow : Window
|
|
{
|
|
public static int Osszeg(List<int> values)
|
|
{
|
|
return values.Sum();
|
|
}
|
|
|
|
public static int Atlag(List<int> values)
|
|
{
|
|
return values.Sum() / values.Count();
|
|
}
|
|
|
|
public static int Min(List<int> values)
|
|
{
|
|
return values.Min();
|
|
}
|
|
|
|
public static int Max(List<int> values)
|
|
{
|
|
return values.Max();
|
|
}
|
|
|
|
public void FileRead(string path)
|
|
{
|
|
if (File.Exists(path))
|
|
{
|
|
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
|
StreamReader streamReader = new StreamReader(fileStream);
|
|
|
|
List<int> values = new List<int>();
|
|
string line = streamReader.ReadLine();
|
|
while (line != null)
|
|
{
|
|
if (Int32.TryParse(line, out int num))
|
|
{
|
|
values.Add(num);
|
|
}
|
|
|
|
|
|
line = streamReader.ReadLine();
|
|
}
|
|
|
|
|
|
streamReader.Close();
|
|
fileStream.Close();
|
|
|
|
if (values.Count > 0)
|
|
{
|
|
osszeg.Content = $"A számok összege: {Osszeg(values)}";
|
|
atlag.Content = $"A számok átlaga: {Atlag(values)}";
|
|
min.Content = $"A legkisebb szám: {Min(values)}";
|
|
max.Content = $"A legnagyobb szám: {Max(values)}";
|
|
|
|
StreamWriter streamWriter = new StreamWriter("kimenet.txt");
|
|
streamWriter.WriteLine($"A számok összege: {Osszeg(values)}");
|
|
streamWriter.WriteLine($"A számok átlaga: {Atlag(values)}");
|
|
streamWriter.WriteLine($"A legkisebb szám: {Min(values)}");
|
|
streamWriter.WriteLine($"A legnagyobb szám: {Max(values)}");
|
|
streamWriter.Close();
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("ERROR! A megadott fájlba nem szerepeltek számok, vagy azok nem jó formátumba voltak.");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("ERROR! A file nem létezik.");
|
|
MessageBox.Show("ERROR! A file nem létezik.");
|
|
}
|
|
}
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (input.Text != "")
|
|
{
|
|
string path = input.Text;
|
|
FileRead(path);
|
|
} else
|
|
{
|
|
input.Text = "bemenet.txt";
|
|
string path = input.Text;
|
|
FileRead(path);
|
|
}
|
|
}
|
|
|
|
private void Save_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|