added solution for the CB example
This commit is contained in:
@@ -4,6 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Xml.Schema;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
namespace ConsoleApp1
|
||||
{
|
||||
public class Uzenet
|
||||
@@ -19,19 +21,124 @@ namespace ConsoleApp1
|
||||
this.nev = nev;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Data
|
||||
{
|
||||
public static List<Uzenet> adatok = new List<Uzenet>();
|
||||
public static List<string> soforok = new List<string>();
|
||||
public static List<int> adas_soforok = new List<int>();
|
||||
}
|
||||
class Program
|
||||
{
|
||||
public static int Feladat3(List<Uzenet> adatok)
|
||||
public static int Feladat3()
|
||||
{
|
||||
return adatok.Count;
|
||||
return Data.adatok.Count;
|
||||
}
|
||||
public static int Feladat4(List<Uzenet> adatok)
|
||||
public static bool Feladat4()
|
||||
{
|
||||
return adatok.Count;
|
||||
foreach (var item in Data.adatok)
|
||||
{
|
||||
if (item.adasdb == 4)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Feladat5()
|
||||
{
|
||||
Console.Write("5. feladat: Kérek egy nevet: ");
|
||||
string name = Console.ReadLine();
|
||||
int cntr = 0;
|
||||
foreach (var item in Data.adatok)
|
||||
{
|
||||
if (item.nev == name)
|
||||
{
|
||||
cntr += item.adasdb;
|
||||
}
|
||||
}
|
||||
|
||||
if (cntr != 0)
|
||||
{
|
||||
Console.WriteLine($"\t{name} {cntr}x használta a CB-rádiót.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("\tNincs ilyen nevű sofőr.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static int AtszamolPercre(int ora, int perc)
|
||||
{
|
||||
return ora * 60 + perc;
|
||||
}
|
||||
|
||||
public static void Feladat7()
|
||||
{
|
||||
FileStream fileStream = new FileStream("cb2.txt", FileMode.Create, FileAccess.Write);
|
||||
StreamWriter streamWriter = new StreamWriter(fileStream);
|
||||
|
||||
streamWriter.WriteLine("Kezdes;Nev;AdasDb");
|
||||
foreach (var item in Data.adatok)
|
||||
{
|
||||
streamWriter.WriteLine($"{AtszamolPercre(item.ora, item.perc)};{item.nev};{item.adasdb}");
|
||||
}
|
||||
|
||||
streamWriter.Close();
|
||||
fileStream.Close();
|
||||
}
|
||||
|
||||
|
||||
public static void Soforok()
|
||||
{
|
||||
foreach (var item in Data.adatok)
|
||||
{
|
||||
if (!Data.soforok.Contains(item.nev))
|
||||
{
|
||||
Data.soforok.Add(item.nev);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static int Feladat8()
|
||||
{
|
||||
return Data.soforok.Count;
|
||||
}
|
||||
|
||||
public static void Adas_soforok()
|
||||
{
|
||||
foreach (var sofor in Data.soforok)
|
||||
{
|
||||
int cntr = 0;
|
||||
foreach (var uzenet in Data.adatok)
|
||||
{
|
||||
if (sofor == uzenet.nev)
|
||||
{
|
||||
cntr += uzenet.adasdb;
|
||||
}
|
||||
}
|
||||
Data.adas_soforok.Add(cntr);
|
||||
}
|
||||
}
|
||||
public static void Feladat9()
|
||||
{
|
||||
Console.WriteLine("9. feladat: Legtöbb adást indító sofőr");
|
||||
int ind = 0;
|
||||
for (int i = 1; i < Data.adas_soforok.Count; i++)
|
||||
{
|
||||
if (Data.adas_soforok[i] > Data.adas_soforok[ind])
|
||||
{
|
||||
ind = i;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"\tNév: {Data.soforok[ind]}");
|
||||
Console.WriteLine($"\tAdások száma: {Data.adas_soforok[ind]}");
|
||||
}
|
||||
static void Main(string[] args)
|
||||
{
|
||||
List<Uzenet> adatok = new List<Uzenet>();
|
||||
Data.adatok.Clear();
|
||||
|
||||
FileStream fileStream = new FileStream("cb.txt", FileMode.Open, FileAccess.Read);
|
||||
StreamReader streamReader = new StreamReader(fileStream);
|
||||
@@ -46,12 +153,26 @@ namespace ConsoleApp1
|
||||
{
|
||||
string[] sor = data[i].Split(';');
|
||||
Uzenet uzi = new Uzenet(int.Parse(sor[0]), int.Parse(sor[1]), int.Parse(sor[2]), sor[3]);
|
||||
adatok.Add(uzi);
|
||||
Data.adatok.Add(uzi);
|
||||
}
|
||||
|
||||
Console.WriteLine($"3. feladat: Bejegyzések száma: {Feladat3(adatok)}");
|
||||
|
||||
Console.WriteLine($"3. feladat: Bejegyzések száma: {Feladat3()}");
|
||||
if (Feladat4())
|
||||
{
|
||||
Console.WriteLine($"4. feladat: Volt négy adást indító sofőr.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"4. feladat: Nem volt négy adást indító sofőr.");
|
||||
}
|
||||
|
||||
Feladat5();
|
||||
|
||||
Feladat7();
|
||||
Soforok();
|
||||
Console.WriteLine($"8. feladat: Sofőrök száma: {Feladat8()} fő");
|
||||
Adas_soforok();
|
||||
Feladat9();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user