Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- namespace ConsoleApp4
- {
- class Program
- {
- struct adatsor
- {
- public string nev; //tanár
- public string targy; //tanitott tárgy
- public string oszt; //osztály beve
- public int ora; //óraszám
- }
- static void Main(string[] args)
- {
- //1.feladat
- int szamol=0;
- adatsor [] adat= new adatsor[1000];
- StreamReader sr= new StreamReader("beosztas.txt");
- while(!sr.EndOfStream)
- { adat[szamol].nev=sr.ReadLine();
- adat[szamol].targy = sr.ReadLine();
- adat[szamol].oszt = sr.ReadLine();
- adat[szamol].ora = Convert.ToInt32(sr.ReadLine());
- szamol++;
- }
- sr.Close();
- //2.feladat
- Console.WriteLine("\n2. feladat");
- Console.WriteLine("A fájlban {0} bejegyzés van.", szamol);
- //3.feladat
- Console.WriteLine("\n3. feladat: ");
- int osszora=0;
- for (int i = 0; i <= szamol; i++)
- {
- osszora=osszora+adat[i].ora;
- }
- Console.WriteLine("Az iskolában a heti összóraszám: {0}", osszora);
- //4.feladat
- Console.WriteLine("\n4.Feladat: ");
- Console.Write("Egy tanár neve= ");
- string tanarnev=Console.ReadLine();
- int oraneki=0;
- for (int i = 0; i <= szamol; i++)
- {
- if(adat[i].nev==tanarnev)
- {
- oraneki=oraneki+adat[i].ora;
- }
- }
- Console.WriteLine("A tanár heti óraszáma: {0}", oraneki);
- //5.feladat
- Console.WriteLine("\n5.Feladat: ");
- StreamWriter sw= new StreamWriter("of.txt");
- for (int i = 0; i <=szamol; i++)
- {
- if( adat[i].targy=="osztalyfonoki")
- {
- sw.WriteLine("{0} - {1}", adat[i].oszt, adat[i].nev);
- }
- }
- sw.Close();
- Console.WriteLine("fájl kész");
- //6.feladat
- Console.WriteLine("\n6.Feladat: ");
- Console.Write("Osztály= ");
- string beosztaly=Console.ReadLine();
- Console.Write("Tárgy= ");
- string betargy=Console.ReadLine();
- int csop=0;
- for (int i = 0; i <=szamol; i++)
- {
- if((adat[i].oszt==beosztaly) && (adat[i].targy==betargy))
- { csop++;}
- }
- if (csop < 2) { Console.WriteLine("Egész osztályban tanulják."); }
- else
- { Console.WriteLine("Csoport bontásban tanulják."); }
- //7.feladat
- Console.WriteLine("\n7. Feladat: ");
- List <string> tanarok=new List<string>();
- for (int i = 1; i <szamol; i++)
- {
- if(!tanarok.Contains(adat[i].nev))
- {
- tanarok.Add(adat[i].nev);
- }
- }
- Console.WriteLine("Az iskolában {0} tanár tanít.", tanarok.Count);
- }
- }
- }
Add Comment
Please, Sign In to add comment