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
using System;
namespace lolo
{
abstract class Element{
public int id;
public int input_count;
public int[] values;
public int[] input;
public int 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;
}
public int and_function(int input_count, int[] values){
output = 1;
for (int i=0; i < input_count; i++){
if (values [i] == 0) {
output = 0;
}
}
return output;
}
}
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;
}
int or_function(int input_count, int[] values){
output = 0;
for (int i=0; i < input_count; i++){
if (values [i] == 1) {
output = 1;
}
}
return output;
}
}
class Scheme {
int[] values0;
Element[] mass;
public Scheme(Element idZero, Element idOne, Element idTwo, Element idThree, Element idFour, Element idFive, Element idSix, int[] values0){
mass = new Element[7]{idZero, idOne, idTwo, idThree, idFour, idFive, idSix};
this.values0 = values0;
}
public void onScreen(int number){
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++)
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].output);
Console.WriteLine (mass[number].or_function(mass[0].input_count,values0));
}
public void onScreen2(){
Console.WriteLine("Значение на выходе схемы: " + "result6");
}
}
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 };
// Элемент с id = 0
int[] inputs0 = new int[]{ 0 };
OR idZero = new OR (0, 2, inputs0, values0);
int result0 = idZero.or_function(2,values0);
// Элемент с id = 1
int[] inputs1 = new int[]{ 0 };
AND idOne = new AND (1, 3, inputs1, values1);
int result1 = idOne.and_function(3,values1);
// Элемент с id = 2
int[] inputs2 = new int[]{ 0 };
AND idTwo = new AND (2, 4, inputs2, values2);
int result2 = idTwo.and_function(4,values2);
// Элемент с id = 3
int[] inputs3 = new int[]{ 0 };
OR idThree = new OR (3, 4, inputs3, values3);
int result3 = idThree.or_function(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.and_function(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 = idThree.or_function(2,values5);
// Элемент с id = 6
int[] inputs6 = new int[]{ 5, 3 };
int[] values6 = new int[]{ result3, result5 };
AND idSix = new AND (6, 2, inputs6, values6);
Scheme inside = new Scheme (idZero, idOne, idTwo, idThree, idFour, idFive, idSix, values0);
int num = 0;
Console.WriteLine ("Характеристики " + num + " элемента");
inside.onScreen (num);
inside.onScreen2 ();
}
}
}