Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace tanfel
- {
- class tanfel
- {
- struct ST{
- public string nev, tant, oszt;
- public int orasz;
- }
- static List<ST> lista = new List<ST>();
- static ST one;
- static void Ex1() {
- StreamReader sr = new StreamReader("beosztas.txt");
- while (!sr.EndOfStream){
- one.nev = sr.ReadLine();
- one.tant = sr.ReadLine();
- one.oszt = sr.ReadLine();
- one.orasz = Convert.ToInt16(sr.ReadLine());
- lista.Add(one);
- }
- sr.Close();
- //foreach (var e in lista){
- // Console.WriteLine($"{e.nev} {e.tant} {e.oszt} {e.orasz}");
- //}
- }
- static void Ex2() {
- Console.WriteLine($"2. feladat\nA fájlban {lista.Count()} bejegyzés van.");
- }
- static void Ex3(){
- int sum = 0;
- foreach (var e in lista)
- {
- sum += e.orasz;
- }
- Console.WriteLine($"3. feladat\nAz iskolában a heti összóraszám: {sum}");
- }
- static void Ex4() {
- int db = 0;
- Console.Write("4.feladat\nEgy tanár neve=");
- string tanar = Console.ReadLine();
- foreach (var e in lista){
- if (tanar == e.nev)
- db += e.orasz;
- }
- Console.WriteLine($"A tanár heti óraszáma: {db}");
- }
- static void Ex5() {
- StreamWriter sw = new StreamWriter("of.txt");
- foreach (var e in lista){
- if (e.tant == "osztalyfonoki"){
- sw.WriteLine($"{e.oszt} - {e.nev}");
- }
- }
- sw.Close();
- }
- static void Ex6() {
- bool dupla = false;
- Console.Write("6. feladat\nOsztály= ");
- string o = Console.ReadLine();
- Console.Write("Tantárgy= ");
- string t = Console.ReadLine();
- for (int i = 0; i < lista.Count; i++){
- if (o == lista[i].oszt && t == lista[i].tant)
- {
- for (int j = i+1; j < lista.Count; j++)
- {
- if (o == lista[j].oszt && t == lista[j].tant)
- {
- dupla = true;
- }
- }
- }
- }
- if (dupla==true)
- {
- Console.WriteLine("Csoportbontásban tanulják.");
- }
- else
- {
- Console.WriteLine("Osztályszinten tanulják.");
- }
- }
- static void Ex7() {
- List<string> tempList = new List<string>();
- foreach (var e in lista)
- {
- if (!tempList.Contains(e.nev))
- {
- tempList.Add(e.nev);
- }
- }
- Console.WriteLine($"7. feladat\nAz iskolában {tempList.Count()} tanár tanít.");
- }
- static void Main(string[] args)
- {
- Ex1();
- Ex2();
- Ex3();
- Ex4();
- Ex5();
- Ex6();
- Ex7();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement