132 lines
3.5 KiB
C#
132 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
using System.Diagnostics.Tracing;
|
|
using System.Diagnostics.Contracts;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
DataRead("C:\\Users\\szabomarton\\Desktop\\C#\\ProgaOra\\20240919\\termekek.csv", ';');
|
|
//Feladat1();
|
|
Feladat2();
|
|
Feladat3();
|
|
Feladat4();
|
|
|
|
Console.ReadLine();
|
|
}
|
|
|
|
static void Feladat1()
|
|
{
|
|
int fizetes_sum = Fizetes_SUM(Data.alkalmazottak);
|
|
double fizetes_avg = Fizetes_AVG(Data.alkalmazottak);
|
|
Console.WriteLine($"A fizetések összege: {fizetes_sum}");
|
|
Console.WriteLine($"A fizetések Átlaga: {fizetes_avg:F2}");
|
|
}
|
|
|
|
static int Fizetes_SUM(List<Alkalmazott> T) {
|
|
var result = T.Select(x => x.fizetes);
|
|
return result.Sum();
|
|
}
|
|
|
|
static double Fizetes_AVG(List<Alkalmazott> T)
|
|
{
|
|
IEnumerable<int> asd = T.Select(x => x.fizetes);
|
|
return asd.Average();
|
|
}
|
|
|
|
static void Feladat2()
|
|
{
|
|
foreach (var item in Data.raktar)
|
|
{
|
|
Console.WriteLine($"{item.nev}");
|
|
}
|
|
}
|
|
|
|
static void Feladat3()
|
|
{
|
|
var result = Data.raktar.GroupBy(y => y.kategoria).Select(x => new {x.Key, darab = x.Count()});
|
|
foreach (var item in result)
|
|
{
|
|
Console.WriteLine($"{item.Key} {item.darab}");
|
|
}
|
|
|
|
}
|
|
|
|
static void Feladat4()
|
|
{
|
|
var legolcsobb = Data.raktar.OrderBy(x => x.ar).Select(y => new {y.nev, y.ar});
|
|
Console.WriteLine(legolcsobb);
|
|
}
|
|
|
|
|
|
static void DataRead(string path, char splitchar)
|
|
{
|
|
using (StreamReader streamReader = new StreamReader(path))
|
|
{
|
|
string line = streamReader.ReadLine();
|
|
line = streamReader.ReadLine();
|
|
while (line != null)
|
|
{
|
|
string[] datas = line.Split(splitchar);
|
|
|
|
TermekAdd(datas);
|
|
|
|
line = streamReader.ReadLine();
|
|
}
|
|
}
|
|
}
|
|
|
|
static void TermekAdd(string[] datas)
|
|
{
|
|
Termek termek = new Termek(datas[0], datas[1], Int32.Parse(datas[2]));
|
|
Data.raktar.Add(termek);
|
|
}
|
|
|
|
static void AlkalmazottAdd(string[] datas)
|
|
{
|
|
Alkalmazott alkalmazott = new Alkalmazott(datas[0], Int32.Parse(datas[1]));
|
|
Data.alkalmazottak.Add(alkalmazott);
|
|
}
|
|
}
|
|
|
|
public class Alkalmazott
|
|
{
|
|
public string nev;
|
|
public int fizetes;
|
|
|
|
public Alkalmazott(string Nev, int Fizetes)
|
|
{
|
|
nev = Nev;
|
|
fizetes = Fizetes;
|
|
}
|
|
}
|
|
|
|
public class Termek
|
|
{
|
|
public string nev;
|
|
public string kategoria;
|
|
public int ar;
|
|
|
|
public Termek(string Nev, string Kategoria, int Ar)
|
|
{
|
|
nev = Nev;
|
|
kategoria = Kategoria;
|
|
ar = Ar;
|
|
}
|
|
}
|
|
|
|
public static class Data
|
|
{
|
|
public static List<Alkalmazott> alkalmazottak = new List<Alkalmazott> ();
|
|
public static List<Termek> raktar = new List<Termek> ();
|
|
}
|
|
}
|