Advertisement
Levi0227

Tantárgyfelosztás-2019 május (idegen)

Mar 30th, 2023 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.49 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace tanfel
  9. {
  10.     class tanfel
  11.     {
  12.         struct ST{
  13.             public string nev, tant, oszt;
  14.             public int orasz;
  15.         }
  16.         static List<ST> lista = new List<ST>();
  17.         static ST one;
  18.  
  19.         static void Ex1() {
  20.             StreamReader sr = new StreamReader("beosztas.txt");
  21.             while (!sr.EndOfStream){
  22.                 one.nev = sr.ReadLine();
  23.                 one.tant = sr.ReadLine();
  24.                 one.oszt = sr.ReadLine();
  25.                 one.orasz = Convert.ToInt16(sr.ReadLine());
  26.                 lista.Add(one);
  27.             }
  28.             sr.Close();
  29.  
  30.             //foreach (var e in lista){
  31.             //    Console.WriteLine($"{e.nev} {e.tant} {e.oszt} {e.orasz}");
  32.             //}
  33.         }
  34.  
  35.         static void Ex2() {
  36.  
  37.             Console.WriteLine($"2. feladat\nA fájlban {lista.Count()} bejegyzés van.");
  38.         }
  39.  
  40.         static void Ex3(){
  41.             int sum = 0;
  42.             foreach (var e in lista)
  43.             {
  44.                 sum += e.orasz;
  45.             }
  46.             Console.WriteLine($"3. feladat\nAz iskolában a heti összóraszám: {sum}");
  47.         }
  48.  
  49.         static void Ex4() {
  50.             int db = 0;
  51.             Console.Write("4.feladat\nEgy tanár neve=");
  52.             string tanar = Console.ReadLine();
  53.             foreach (var e in lista){
  54.                 if (tanar == e.nev)
  55.                     db += e.orasz;
  56.             }
  57.             Console.WriteLine($"A tanár heti óraszáma: {db}");
  58.         }
  59.  
  60.         static void Ex5() {
  61.             StreamWriter sw = new StreamWriter("of.txt");
  62.             foreach (var e in lista){
  63.                 if (e.tant == "osztalyfonoki"){
  64.                     sw.WriteLine($"{e.oszt} - {e.nev}");
  65.                 }
  66.             }
  67.             sw.Close();
  68.         }
  69.  
  70.         static void Ex6() {
  71.             bool dupla = false;
  72.             Console.Write("6. feladat\nOsztály= ");
  73.             string o = Console.ReadLine();
  74.             Console.Write("Tantárgy= ");
  75.             string t = Console.ReadLine();
  76.  
  77.             for (int i = 0; i < lista.Count; i++){
  78.                 if (o == lista[i].oszt && t == lista[i].tant)
  79.                 {
  80.                     for (int j = i+1; j < lista.Count; j++)
  81.                     {
  82.                         if (o == lista[j].oszt && t == lista[j].tant)
  83.                         {
  84.                             dupla = true;
  85.                         }
  86.                     }
  87.                 }
  88.             }
  89.             if (dupla==true)
  90.             {
  91.                 Console.WriteLine("Csoportbontásban tanulják.");
  92.             }
  93.             else
  94.             {
  95.                 Console.WriteLine("Osztályszinten tanulják.");
  96.             }
  97.  
  98.         }
  99.  
  100.         static void Ex7() {
  101.             List<string> tempList = new List<string>();
  102.             foreach (var e in lista)
  103.             {
  104.                 if (!tempList.Contains(e.nev))
  105.                 {
  106.                     tempList.Add(e.nev);
  107.                 }
  108.             }
  109.             Console.WriteLine($"7. feladat\nAz iskolában {tempList.Count()} tanár tanít.");
  110.  
  111.         }
  112.  
  113.         static void Main(string[] args)
  114.         {
  115.             Ex1();
  116.             Ex2();
  117.             Ex3();
  118.             Ex4();
  119.             Ex5();
  120.             Ex6();
  121.             Ex7();
  122.  
  123.  
  124.             Console.ReadKey();
  125.         }
  126.     }
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement