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;
- // HÁZI:
- // Főprogram (30% cica, 70% sziámi)
- // Két readonly property: hány cica, hány sziámi (a listában, menhelyben)
- // Kulcssszavak: "is" operátor
- namespace prog_II_1
- {
- class Cica
- {
- protected int _honapos;
- protected bool _ivartalan;
- public bool ivartalan
- {
- get { return _ivartalan; }
- set
- {
- if (_ivartalan && value == false)
- {
- _ivartalan = value;
- }
- else throw new Exception("Ivarosítani már nem lehet");
- }
- }
- public int honapos
- {
- get
- {
- return _honapos;
- }
- set
- {
- if (0 < value && value < 241)
- _honapos = value;
- else throw new Exception("Hibás hónapérték");
- }
- }
- // Constructor
- public Cica(int phonapos, bool pivartalan)
- {
- honapos = phonapos;
- _ivartalan = pivartalan;
- }
- public Cica(int phonapos) : this(phonapos, false) { }
- }
- class Sziami : Cica
- {
- public bool tud_koszonni;
- protected string _nev;
- public string nev
- {
- get { return _nev; }
- protected set
- {
- if (value == null || (value.Length != 0 && value.Length < 50))
- {
- _nev = value;
- }
- else throw new Exception("Hibás név!");
- }
- }
- // Constructor
- public Sziami(int phonapos, bool pivartalan, bool pkoszon, string pnev)
- : base(phonapos, pivartalan)
- {
- tud_koszonni = pkoszon;
- nev = pnev;
- }
- public Sziami(int phonapos, string pnev)
- : this(phonapos, false, false, pnev) { }
- public Sziami(int phonapos) : this(phonapos, null) { }
- }
- class Menhely
- {
- protected List<Cica> menhely = new List<Cica>();
- public bool Hozzaad(Cica x)
- {
- if (x != null || menhely.Count >= 20)
- {
- foreach (var y in menhely) // nemjó mert csak a referenciákat hasonlítja össze, mindegy
- {
- if (x == y)
- {
- return false;
- }
- }
- menhely.Add(x);
- return true;
- }
- return false;
- }
- public bool Torol(Cica x)
- {
- int index = menhely.IndexOf(x);
- if (index > -1)
- {
- menhely.RemoveAt(index);
- return true;
- }
- else return false;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement