Levi0227

Tanár // Tantárgyfelosztás-2019 május (idegen)

Apr 5th, 2023 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.33 KB | Source Code | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4.  
  5. namespace ConsoleApp4
  6. {
  7.     class Program
  8.     {
  9.         struct adatsor
  10.         {
  11.             public string nev; //tanár
  12.             public string targy; //tanitott tárgy
  13.             public string oszt; //osztály beve
  14.             public int ora; //óraszám
  15.            
  16.          }
  17.         static void Main(string[] args)
  18.         {
  19.             //1.feladat
  20.  
  21.             int szamol=0;
  22.             adatsor [] adat= new adatsor[1000];
  23.             StreamReader sr= new StreamReader("beosztas.txt");
  24.             while(!sr.EndOfStream)
  25.             { adat[szamol].nev=sr.ReadLine();
  26.               adat[szamol].targy = sr.ReadLine();
  27.               adat[szamol].oszt = sr.ReadLine();
  28.               adat[szamol].ora = Convert.ToInt32(sr.ReadLine());
  29.             szamol++;
  30.                 }
  31.             sr.Close();
  32.  
  33.             //2.feladat
  34.             Console.WriteLine("\n2. feladat");
  35.             Console.WriteLine("A fájlban {0} bejegyzés van.", szamol);
  36.  
  37.             //3.feladat
  38.             Console.WriteLine("\n3. feladat: ");
  39.             int osszora=0;
  40.             for (int i = 0; i <= szamol; i++)
  41.             {
  42.                 osszora=osszora+adat[i].ora;
  43.              }
  44.             Console.WriteLine("Az iskolában a heti összóraszám: {0}", osszora);
  45.  
  46.  
  47.             //4.feladat
  48.             Console.WriteLine("\n4.Feladat: ");
  49.  
  50.             Console.Write("Egy tanár neve= ");
  51.             string tanarnev=Console.ReadLine();
  52.             int oraneki=0;
  53.  
  54.             for (int i = 0; i <= szamol; i++)
  55.             {
  56.              if(adat[i].nev==tanarnev)
  57.                 {
  58.                     oraneki=oraneki+adat[i].ora;
  59.                     }
  60.              }
  61.             Console.WriteLine("A tanár heti óraszáma: {0}", oraneki);
  62.            
  63.             //5.feladat
  64.             Console.WriteLine("\n5.Feladat: ");
  65.             StreamWriter sw= new StreamWriter("of.txt");
  66.             for (int i = 0; i <=szamol;  i++)
  67.             {
  68.                 if( adat[i].targy=="osztalyfonoki")
  69.                 {
  70.                     sw.WriteLine("{0} - {1}", adat[i].oszt, adat[i].nev);
  71.                     }
  72.             }
  73.             sw.Close();
  74.             Console.WriteLine("fájl kész");
  75.             //6.feladat
  76.             Console.WriteLine("\n6.Feladat: ");
  77.             Console.Write("Osztály= ");
  78.             string beosztaly=Console.ReadLine();
  79.             Console.Write("Tárgy= ");
  80.             string betargy=Console.ReadLine();
  81.             int csop=0;
  82.             for (int i = 0; i <=szamol; i++)
  83.             {
  84.                 if((adat[i].oszt==beosztaly) && (adat[i].targy==betargy))
  85.                 { csop++;}
  86.             }
  87.             if (csop < 2) { Console.WriteLine("Egész osztályban tanulják."); }
  88.             else
  89.             { Console.WriteLine("Csoport bontásban tanulják."); }
  90.  
  91.             //7.feladat
  92.             Console.WriteLine("\n7. Feladat: ");
  93.             List <string> tanarok=new List<string>();
  94.             for (int i = 1; i <szamol; i++)
  95.             {
  96.                 if(!tanarok.Contains(adat[i].nev))
  97.                 {
  98.                     tanarok.Add(adat[i].nev);
  99.                  }
  100.             }
  101.             Console.WriteLine("Az iskolában {0} tanár tanít.", tanarok.Count);
  102.  
  103.         }
  104.     }
  105. }
  106.  
Add Comment
Please, Sign In to add comment