Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Elem;
- using System;
- using System.IO;
- namespace Lab3
- {
- class MyClass
- {
- static void Main()
- {
- Console.WriteLine("#########################################################################");
- Console.Write("#\t\t\t\t");
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("LAB №3 MOD 3");
- Console.ResetColor();
- Console.WriteLine("\t\t\t\t#");
- Console.Write("#\t\t\t\t");
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Console.Write(" SLAPOGUZOV");
- Console.ResetColor();
- Console.WriteLine("\t\t\t\t#");
- Console.WriteLine("#########################################################################");
- Console.WriteLine();
- Menu();
- Console.ReadKey();
- }
- static void Menu()
- {
- Console.WriteLine("1. Демонстрация работы класса Elements;");
- Console.WriteLine("2. Демонстрация работы класса Combinative;");
- Console.WriteLine("3. Демонстрация работы класса Register;");
- Console.WriteLine("4. Закрыть.");
- try
- {
- switch (int.Parse(Console.ReadLine()))
- {
- case 1:
- {
- Console.Write("Введите имя элемента: ");
- string name = Console.ReadLine();
- Console.Write("Введите количество входов: ");
- byte numIn = System.Convert.ToByte(Console.ReadLine());
- Console.Write("Введите количество выходов: ");
- byte numOut = System.Convert.ToByte(Console.ReadLine());
- Elements myElement = new Elements(name, numIn, numOut);
- Console.WriteLine();
- Console.Write("Создан элемент ");
- highlight(myElement.Name);
- Console.Write(" c ");
- highlight(myElement.NumInputs.ToString());
- Console.Write(" входами(-ом) и с ");
- highlight(myElement.NumOutputs.ToString());
- Console.WriteLine(" выходами(-ом)");
- break;
- }
- case 2:
- {
- Console.Write("Введите имя элемента: ");
- string name = Console.ReadLine();
- bool[] val = new bool[6];
- for (int i = 0; i < 6; i++)
- {
- Console.WriteLine("Введите значение {0} входа: ", i);
- string temp = Console.ReadLine();
- if ("1" == temp)
- {
- val[i] = true;
- }
- else if ("0" == temp)
- {
- val[i] = false;
- }
- else
- {
- throw new System.InvalidCastException();
- }
- }
- Combinative myCombinative = new Combinative(name, val);
- Console.WriteLine();
- Console.Write("Создан комбинационный элемент ");
- highlight(myCombinative.Name);
- Console.Write(" c ");
- highlight(myCombinative.NumInputs.ToString());
- Console.Write(" входами(-ом) и с ");
- highlight(myCombinative.NumOutputs.ToString());
- Console.WriteLine(" выходами(-ом)");
- Console.WriteLine("#########################################################################");
- Console.WriteLine();
- Console.WriteLine("1. Получить состояние отдельного входа;");
- Console.WriteLine("2. Вычислить значение выхода;");
- Console.WriteLine("3. Перейти в главное меню;");
- switch (int.Parse(Console.ReadLine()))
- {
- case 1:
- {
- Console.WriteLine();
- Console.Write("Введите номер входа: ");
- Console.WriteLine("Значение входа = {0}", convertBoolInStr(myCombinative.getValInput(byte.Parse(Console.ReadLine()))));
- break;
- }
- case 2:
- {
- Console.WriteLine();
- Console.Write("Значение выхода: {0}", convertBoolInStr(myCombinative.calcValOutput()));
- break;
- }
- case 3:
- {
- Menu();
- break;
- }
- default:
- {
- throw new System.ArgumentException();
- break;
- }
- }
- break;
- }
- case 3:
- {
- Console.Write("Введите имя элемента: ");
- string name = Console.ReadLine();
- bool[] val = new bool[7];
- for (int i = 0; i < 7; i++)
- {
- Console.Write("Введите значение {0} ячейки: ", i);
- string temp = Console.ReadLine();
- if ("1" == temp)
- {
- val[i] = true;
- }
- else if ("0" == temp)
- {
- val[i] = false;
- }
- else
- {
- throw new InvalidCastException();
- }
- }
- Register MyRegister = new Register(name, val);
- Console.WriteLine();
- Console.WriteLine("#########################################################################");
- Console.WriteLine();
- Console.WriteLine("1. Получить состояние отдельного выхода;");
- Console.WriteLine("2. Вычислить значения нового состояния экземпляра класса;");
- Console.WriteLine("3. Перейти в главное меню;");
- switch (int.Parse(Console.ReadLine()))
- {
- case 1:
- {
- Console.WriteLine();
- Console.Write("Введите номер входа: ");
- Console.WriteLine("Значение входа = {0}", convertBoolInStr(MyRegister.getValOutput(byte.Parse(Console.ReadLine()))));
- break;
- }
- case 2:
- {
- for (int i = 0; i < 7; i++)
- {
- Console.WriteLine("Введите значение {0} ячейки: ", i);
- string temp = Console.ReadLine();
- if ("1" == temp)
- {
- val[i] = true;
- }
- else if ("0" == temp)
- {
- val[i] = false;
- }
- else
- {
- throw new InvalidCastException();
- }
- }
- MyRegister.calcNewStatus(val);
- for (int i = 0; i < 7; i++)
- {
- Console.WriteLine("Значение {0} ячейки: {1}", i, convertBoolInStr(MyRegister.getValOutput(Convert.ToByte(i))));
- }
- break;
- }
- case 3:
- {
- Menu();
- break;
- }
- default:
- {
- throw new System.ArgumentException();
- break;
- }
- }
- break;
- }
- case 4:
- {
- Environment.Exit(0);
- break;
- }
- default:
- {
- throw new System.ArgumentException();
- break;
- }
- }
- }
- catch (ArgumentException)
- {
- Console.WriteLine("Номер пункта не коректен");
- Menu();
- }
- catch (InvalidCastException)
- {
- Console.WriteLine("Ошибка преобразования");
- Menu();
- }
- }
- static void highlight(string str)
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write(str);
- Console.ResetColor();
- }
- static string convertBoolInStr(bool bl)
- {
- if (bl)
- {
- return "1";
- }
- else
- {
- return "0";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement