using System namespace lolo abstract class Element public int id publi

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
namespace lolo
{
abstract class Element{
public int id;
public int input_count;
public int[] values;
public int[] input;
public int output;
public int type = 0; //1 - and, 0 - or
public int function(int type, int input_count, int[] values){
if (type == 1) {
output = 1;
for (int i = 0; i < input_count; i++) {
if (id < 4)
break;
if (values [i] == 0) {
output = 0;
}
}
} else if (type == 0) {
output = 0;
for (int i=0; i < input_count; i++){
if (id < 4)
break;
if (values [i] == 1) {
output = 1;
}
}
}
return output;
}
}
class AND : Element{
public AND(int id, int input_count, int[] input, int[] values){
this.id = id;
this.input_count = input_count;
this.values = values;
this.input = input;
}
}
class OR : Element{
public OR(int id, int input_count, int[] input, int[] values){
this.id = id;
this.input_count = input_count;
this.values = values;
this.input = input;
}
}
class Scheme {
int[] values0, values1, values2, values3;
Element[] mass;
public Scheme(int[] values0, int[] values1, int[] values2, int[] values3){
this.values0 = values0;
this.values1 = values1;
this.values2 = values2;
this.values3 = values3;
Element[] mass;
}
public void onScreen(int number, Element[] mass){
this.mass = mass;
Console.Write ("1. id элемента: " + mass[number].id + "\n" +
"2. Количество входов: " + mass [number].input_count + "\n" +
"3. id присоединенных элементов: ");
for (int i = 0; i < mass [number].input_count; i++) {
if (number < 4) {
Console.Write ("нет подключенных элементов");
break;
}
Console.Write (mass [number].input [i] + " ");
}
Console.WriteLine ();
Console.Write ("4. Значения на входе: ");
for(int i=0; i<mass[number].input_count; i++)
Console.Write(mass[number].values[i] + " ");
Console.WriteLine ();
Console.Write("5. Значение на выходе: " + mass[number].function(0,mass[0].input_count,values0));
}
public Element[] ono(){
// Элемент с id = 0
int[] inputs0 = new int[]{ 0 };
OR idZero = new OR (0, 2, inputs0, values0);
int result0 = idZero.function(0,2,values0);
// Элемент с id = 1
int[] inputs1 = new int[]{ 0 };
AND idOne = new AND (1, 3, inputs1, values1);
int result1 = idOne.function(1,3,values1);
// Элемент с id = 2
int[] inputs2 = new int[]{ 0 };
AND idTwo = new AND (2, 4, inputs2, values2);
int result2 = idTwo.function(1,4,values2);
// Элемент с id = 3
int[] inputs3 = new int[]{ 0 };
OR idThree = new OR (3, 4, inputs3, values3);
int result3 = idThree.function(0,4,values3);
// Элемент с id = 4
int[] inputs4 = new int[]{ 0, 1 };
int[] values4 = new int[]{ result0, result1 };
AND idFour = new AND (4, 2, inputs4, values4);
int result4 = idFour.function(1,2,values4);
// Элемент с id = 5
int[] inputs5 = new int[]{ 4, 2 };
int[] values5 = new int[]{ result2, result4 };
OR idFive = new OR (5, 2, inputs5, values5);
int result5 = idFive.function(0,2,values5);
// Элемент с id = 6
int[] inputs6 = new int[]{ 5, 3 };
int[] values6 = new int[]{ result3, result5 };
AND idSix = new AND (6, 2, inputs6, values6);
Console.WriteLine ("Значение на выходе схемы:" + idSix.function(1,2,values6));
Element[] mass = new Element[]{idZero, idOne, idTwo, idThree, idFour, idFive, idSix};
return mass;
}
}
class MainClass
{
public static void Main (string[] args)
{
int[] values0 = new int[]{ 0, 1 };
int[] values1 = new int[]{ 1, 1, 1 };
int[] values2 = new int[]{ 0, 1, 1, 1 };
int[] values3 = new int[]{ 0, 1, 0, 0 };
Scheme inside = new Scheme (values0, values1, values1, values3);
int num = 0;
Element[] mass = inside.ono ();
Console.WriteLine ("Характеристики " + num + " элемента");
inside.onScreen (num, mass);
}
}
}