Element.Cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Second
{
class Element
{
string Name;
int QtyIn;
int QtyOut;
//Конструктор без параметров
public Element()
{
}
//Конструктор задающий имя и кол-во вх, вых =1
public Element(String Name)
{
this.Name = Name;
QtyIn = 1;
QtyOut = 1;
}
//Конструктор задающий значение всех полей
public Element(String Name, int QtyIn, int QtyOut)
{
this.Name = Name;
this.QtyIn = QtyIn;
this.QtyOut = QtyOut;
}
//Свойство Name(только чтение)
public string NameP
{
get
{
return Name;
}
}
//Свойство QtyIn
public int QtyInP
{
get
{
return QtyIn;
}
set
{
if (value > 0) QtyIn = value;
else QtyIn = 0;
}
}
//Свойство QtyOut
public int QtyOutP
{
get
{
return QtyOut;
}
set
{
if (value > 0) QtyOut = value;
else QtyOut = 0;
}
}
//Переопределение метода Equals
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType()) return false;
Element temp = (Element)obj;
return (Name == temp.Name) &&
(QtyIn == temp.QtyIn) &&
(QtyOut == temp.QtyOut);
}
//Метод GetHashCode у одинаковых объектах должен быть одинаковым:
public override int GetHashCode()
{
return Name.GetHashCode() ^ QtyIn.GetHashCode() ^ QtyOut.GetHashCode();
}
}
}
Registr.Cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Second
{
class Registr
{
Trigger[] Reg;
bool[] Input;
bool[] Qt;
public Registr()
{
Reg = new Trigger[10];
Qt = new bool[10];
for (int i = 0; i < 10; i++)
{
Reg[i] = new Trigger();
Qt[i] = true;
}
Input = new bool[20];
}
public bool SetValue(bool[] NewValue)
{
if (Input.GetLength(0) == NewValue.GetLength(0))
{
bool[] tmp = new bool[2];
NewValue.CopyTo(Input, 0);
for (int i = 0; i < Reg.GetLength(0); i++)
{
tmp[0] = Input[i * 2];
tmp[1] = Input[i * 2 + 1];
if (Reg[i].SetValue(tmp) == false)
return false;
}
return true;
}
else
return false;
}
public bool GetOut(int Index, out bool Error)
{
if (Index < Reg.GetLength(0))
{
Error = false;
Reg[Index].Calculate();
return Reg[Index].GetOut();
}
else
{
Error = true;
return false;
}
}
public String Result()
{
String res = "";
bool[] tmp = new bool[2];
for (int i = 0; i < 10; i++)
{
tmp[0] = Input[i * 2];
tmp[1] = Input[i * 2 + 1];
Reg[i].SetValue(tmp);
Reg[i].SetQt(Qt[i]);
Reg[i].Calculate();
res = res + (Convert.ToInt32(Reg[i].GetOut())).ToString();
}
return res;
}
//переопределение метода equals
public override bool Equals(System.Object obj)
{
// если параметр не может быть приведен к CombElem false:
Registr p = obj as Registr;
if ((object)p == null)
{
return false;
}
// сравнение на общее число элементов массива Input
if (Input.Length != p.Input.Length) return false;
//сравнение массива со значением входов
for (int i = 0; i < Input.Length; i++)
{
if (Input[i] != p.Input[i])
return false;
}
// сравнение на общее число элементов массива Reg
if (Reg.Length != p.Reg.Length) return false;
//сравнение массива триггеров
for (int i = 0; i < Reg.Length; i++)
{
if (!Reg[i].Equals(p.Reg[i]))
return false;
}
return true;
}
//метод hashCode у одинаковых объектов должен быть одинаковым:
public override int GetHashCode()
{
return Input.GetHashCode() ^ Reg.GetHashCode();
}
public static bool operator ==(Registr a, Registr b)
{
return a.Equals(b);
}
public static bool operator !=(Registr a, Registr b)
{
return !(a == b);
}
}
}