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;
- namespace prog_I.zh_B_csop
- {
- class zene
- {
- protected string _cim;
- protected int _hossz; // percekben
- public bool _vesztesegmentes;
- protected int _meret; // kbyte, readonly
- // Properties
- public string cim
- {
- get { return _cim; }
- set
- {
- if (value != null)
- {
- if (0 < value.Length && value.Length < 101)
- {
- _cim = value;
- }
- else throw new Exception("0 és 100 közötti érték kell!");
- }
- else throw new Exception("Nem lehet null!");
- }
- }
- public int hossz
- {
- get { return _hossz; }
- set
- {
- if (10 <= value && value <= 400)
- {
- _hossz = value;
- }
- else throw new Exception("10 és 400 között kell lennie! {0}");
- }
- }
- public int meret
- {
- get { return _meret; }
- }
- // Constructors
- public zene(string pcim, int phossz, int pmeret, bool pflac)
- {
- cim = pcim;
- hossz = phossz;
- if (0 < pmeret && pmeret < 200000)
- _meret = pmeret;
- else throw new Exception("Hibás méret!");
- _vesztesegmentes = pflac;
- }
- public zene(string pcim, int phossz, int pmeret) : this(pcim, phossz, pmeret, true) { }
- }
- public enum csatlakozas { ATA, SATA, SATA2, SATA3 }
- class diszk
- {
- protected int _meret; // GB, x % 20 == 0, 100<x<5000, readonly
- protected csatlakozas _csatlakozo; // readonly
- // protected int _szabad; // kbyte, readonly
- protected List<zene> zenelista = new List<zene>();
- // NAS-hoz
- public int zenelista_hossz
- {
- get
- {
- return zenelista.Count;
- }
- }
- public string cimfgv(int index)
- {
- return zenelista[index].cim;
- }
- // Properties
- public int meret
- {
- get { return _meret; }
- }
- public int szabad
- {
- get
- {
- int sizesum = 0;
- foreach (zene x in zenelista)
- {
- sizesum += x.meret;
- }
- return _meret - (sizesum / 1024 / 1024);
- }
- }
- public csatlakozas csatlakozo
- {
- get { return _csatlakozo; }
- }
- // Constructors
- public diszk(int pmeret, csatlakozas pcsat)
- {
- if (100 < pmeret && pmeret < 5000)
- {
- if (pmeret % 20 != 0)
- {
- _meret = pmeret;
- }
- }
- _csatlakozo = pcsat;
- }
- // Functions
- // Zene hozzáadása
- public void hozzaad(zene x)
- {
- if (x != null)
- {
- foreach (var y in zenelista)
- {
- if (y.cim == x.cim)
- {
- throw new Exception("Nem lehet két ugyanolyan cím!");
- }
- }
- if (szabad < x.meret)
- {
- // throw new Exception("Nincs elég hely a diszken!"); // fordítási hiba, a szabad alapvetően kisebb lesz mint az x.meret (nem marad időm kijavítani, elnézést)
- }
- zenelista.Add(x);
- }
- else throw new Exception("Nem lehet null!");
- }
- // Zene törlése
- public bool torles(string cim)
- {
- for (int i = 0; i < zenelista.Count; i++)
- {
- if (zenelista[i].cim == cim)
- {
- zenelista.RemoveAt(i);
- return true;
- }
- }
- return false;
- }
- // Zene keresése
- public zene kereses(string cim)
- {
- for (int i = 0; i < zenelista.Count; i++)
- {
- if (zenelista[i].cim == cim)
- {
- return zenelista[i];
- }
- }
- return null;
- }
- }
- class NAS
- {
- protected int _maxdiszkszam;
- protected List<diszk> diszklista = new List<diszk>();
- public int NASszabad
- {
- get
- {
- int sizesum = 0;
- int freespace = 0;
- foreach (diszk x in diszklista)
- {
- sizesum += x.meret;
- freespace += x.szabad;
- }
- return sizesum - freespace;
- }
- }
- // Diszk hozzáadása
- public void diszkHozzaad(diszk x)
- {
- if (x != null) diszklista.Add(x);
- }
- // Zene lejátszása (UTOLSÓNAK, mert elmegy vele az összes időm)
- public zene lejatszas(string cim)
- {
- List<zene> temp = new List<zene>();
- foreach (var x in diszklista)
- {
- if (x.kereses(cim) != null)
- {
- temp.Add(x.kereses(cim)); // nem praktikus
- }
- }
- if (temp.Count > 1)
- {
- foreach (var x in temp)
- {
- if (x._vesztesegmentes)
- return x;
- }
- }
- return temp[0];
- }
- // Zenék listája
- public List<string> szamCimLista()
- {
- List<string> cimek = new List<string>();
- foreach (diszk x in diszklista)
- {
- for (int i = 0; i < x.zenelista_hossz; i++)
- {
- cimek.Add(x.cimfgv(i));
- }
- }
- return cimek;
- }
- // Zenekereső
- public zene keres(string cim)
- {
- foreach (var x in diszklista)
- {
- if (x.kereses(cim) != null)
- {
- return x.kereses(cim); // nem túl praktikus
- }
- }
- return null;
- }
- // Constructor
- public NAS(int maxdiszk)
- {
- if (2 <= maxdiszk && maxdiszk <= 10)
- {
- _maxdiszkszam = maxdiszk;
- }
- }
- }
- class Program
- {
- static Random rand = new Random();
- static void Main(string[] args)
- {
- // DEBUGGOLT, LEFUT
- NAS nas = new NAS(rand.Next(2, 11));
- for (int i = 0; i < 4; i++)
- {
- diszk d = new diszk(rand.Next(100, 5001), (csatlakozas)rand.Next(0, 4));
- for (int j = 0; j < rand.Next(4, 9); j++)
- {
- zene z = new zene(String.Format("Cím{0}", rand.Next(1000)), rand.Next(10, 401), rand.Next(200000), rand.Next(0, 2) + 1 == 1 ? true : false);
- d.hozzaad(z);
- Console.WriteLine("Cím: {0}\tHossz: {1}\tMéret: {2}\tVeszt.ment.: {3}", z.cim, z.hossz, z.meret, z._vesztesegmentes);
- }
- nas.diszkHozzaad(d);
- }
- Console.WriteLine("\n\n\nAdd meg a zene címét!");
- string cim = Console.ReadLine();
- var zene = nas.keres(cim);
- if (zene != null)
- {
- Console.WriteLine("Hossz: {0}\tVeszteségmentes-e: {1}", zene.hossz, zene._vesztesegmentes);
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement