Advertisement
Slapoguzov

Lab3_Main

May 5th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.98 KB | None | 0 0
  1. using Elem;
  2.  
  3. using System;
  4.  
  5. using System.IO;
  6.  
  7. namespace Lab3
  8. {
  9.     class MyClass
  10.     {
  11.  
  12.         static void Main()
  13.         {
  14.  
  15.             Console.WriteLine("#########################################################################");
  16.             Console.Write("#\t\t\t\t");
  17.             Console.ForegroundColor = ConsoleColor.Cyan;
  18.             Console.Write("LAB №3 MOD 3");
  19.             Console.ResetColor();
  20.             Console.WriteLine("\t\t\t\t#");
  21.             Console.Write("#\t\t\t\t");
  22.             Console.ForegroundColor = ConsoleColor.DarkGreen;
  23.             Console.Write(" SLAPOGUZOV");
  24.             Console.ResetColor();
  25.             Console.WriteLine("\t\t\t\t#");
  26.             Console.WriteLine("#########################################################################");
  27.             Console.WriteLine();
  28.  
  29.  
  30.              Menu();
  31.  
  32.             Console.ReadKey();
  33.  
  34.         }
  35.  
  36.         static void Menu()
  37.         {
  38.  
  39.             Console.WriteLine("1. Демонстрация работы класса Elements;");
  40.             Console.WriteLine("2. Демонстрация работы класса Combinative;");
  41.             Console.WriteLine("3. Демонстрация работы класса Register;");
  42.             Console.WriteLine("4. Закрыть.");
  43.             try
  44.             {
  45.  
  46.                 switch (int.Parse(Console.ReadLine()))
  47.                 {
  48.                     case 1:
  49.                         {
  50.                             Console.Write("Введите имя элемента: ");
  51.                             string name = Console.ReadLine();
  52.  
  53.                             Console.Write("Введите количество входов: ");
  54.                             byte numIn = System.Convert.ToByte(Console.ReadLine());
  55.  
  56.                             Console.Write("Введите количество выходов: ");
  57.                             byte numOut = System.Convert.ToByte(Console.ReadLine());
  58.  
  59.                             Elements myElement = new Elements(name, numIn, numOut);
  60.  
  61.                             Console.WriteLine();
  62.  
  63.                             Console.Write("Создан элемент ");
  64.                             highlight(myElement.Name);
  65.                             Console.Write(" c ");
  66.                             highlight(myElement.NumInputs.ToString());
  67.                             Console.Write(" входами(-ом) и с ");
  68.                             highlight(myElement.NumOutputs.ToString());
  69.                             Console.WriteLine(" выходами(-ом)");
  70.  
  71.                             break;
  72.                         }
  73.                     case 2:
  74.                         {
  75.                             Console.Write("Введите имя элемента: ");
  76.                             string name = Console.ReadLine();
  77.                             bool[] val = new bool[6];
  78.  
  79.                             for (int i = 0; i < 6; i++)
  80.                             {
  81.                                 Console.WriteLine("Введите значение {0} входа: ", i);
  82.  
  83.                                 string temp = Console.ReadLine();
  84.  
  85.                                 if ("1" == temp)
  86.                                 {
  87.                                     val[i] = true;
  88.                                 }
  89.                                 else if ("0" == temp)
  90.                                 {
  91.                                     val[i] = false;
  92.                                 }
  93.                                 else
  94.                                 {
  95.                                     throw new System.InvalidCastException();
  96.                                 }
  97.                             }
  98.  
  99.                             Combinative myCombinative = new Combinative(name, val);
  100.  
  101.                             Console.WriteLine();
  102.                             Console.Write("Создан комбинационный элемент ");
  103.                             highlight(myCombinative.Name);
  104.                             Console.Write(" c ");
  105.                             highlight(myCombinative.NumInputs.ToString());
  106.                             Console.Write(" входами(-ом) и с ");
  107.                             highlight(myCombinative.NumOutputs.ToString());
  108.                             Console.WriteLine(" выходами(-ом)");
  109.  
  110.                             Console.WriteLine("#########################################################################");
  111.                             Console.WriteLine();
  112.  
  113.                             Console.WriteLine("1. Получить состояние отдельного входа;");
  114.                             Console.WriteLine("2. Вычислить значение выхода;");
  115.                             Console.WriteLine("3. Перейти в главное меню;");
  116.  
  117.                             switch (int.Parse(Console.ReadLine()))
  118.                             {
  119.                                 case 1:
  120.                                     {
  121.  
  122.                                         Console.WriteLine();
  123.                                         Console.Write("Введите номер входа: ");
  124.                                         Console.WriteLine("Значение входа = {0}", convertBoolInStr(myCombinative.getValInput(byte.Parse(Console.ReadLine()))));
  125.                                         break;
  126.                                     }
  127.                                 case 2:
  128.                                     {
  129.                                         Console.WriteLine();
  130.                                         Console.Write("Значение выхода: {0}", convertBoolInStr(myCombinative.calcValOutput()));
  131.                                         break;
  132.                                     }
  133.                                 case 3:
  134.                                     {
  135.                                         Menu();
  136.                                         break;
  137.                                     }
  138.                                 default:
  139.                                     {
  140.                                         throw new System.ArgumentException();
  141.                                         break;
  142.                                     }
  143.  
  144.                             }
  145.  
  146.                             break;
  147.  
  148.                         }
  149.                     case 3:
  150.                         {
  151.                             Console.Write("Введите имя элемента: ");
  152.                             string name = Console.ReadLine();
  153.                             bool[] val = new bool[7];
  154.  
  155.                             for (int i = 0; i < 7; i++)
  156.                             {
  157.                                 Console.Write("Введите значение {0} ячейки: ", i);
  158.  
  159.                                 string temp = Console.ReadLine();
  160.  
  161.                                 if ("1" == temp)
  162.                                 {
  163.                                     val[i] = true;
  164.                                 }
  165.                                 else if ("0" == temp)
  166.                                 {
  167.                                     val[i] = false;
  168.                                 }
  169.                                 else
  170.                                 {
  171.                                     throw new InvalidCastException();
  172.                                 }
  173.                             }
  174.  
  175.                             Register MyRegister = new Register(name, val);
  176.                             Console.WriteLine();
  177.                             Console.WriteLine("#########################################################################");
  178.                             Console.WriteLine();
  179.  
  180.                             Console.WriteLine("1. Получить состояние отдельного выхода;");
  181.                             Console.WriteLine("2. Вычислить значения нового состояния экземпляра класса;");
  182.                             Console.WriteLine("3. Перейти в главное меню;");
  183.  
  184.                             switch (int.Parse(Console.ReadLine()))
  185.                             {
  186.                                 case 1:
  187.                                     {
  188.  
  189.                                         Console.WriteLine();
  190.                                         Console.Write("Введите номер входа: ");
  191.                                         Console.WriteLine("Значение входа = {0}", convertBoolInStr(MyRegister.getValOutput(byte.Parse(Console.ReadLine()))));
  192.                                         break;
  193.                                     }
  194.                                 case 2:
  195.                                     {
  196.                                         for (int i = 0; i < 7; i++)
  197.                                         {
  198.                                             Console.WriteLine("Введите значение {0} ячейки: ", i);
  199.  
  200.                                             string temp = Console.ReadLine();
  201.  
  202.                                             if ("1" == temp)
  203.                                             {
  204.                                                 val[i] = true;
  205.                                             }
  206.                                             else if ("0" == temp)
  207.                                             {
  208.                                                 val[i] = false;
  209.                                             }
  210.                                             else
  211.                                             {
  212.                                                 throw new InvalidCastException();
  213.                                             }
  214.                                         }
  215.  
  216.                                         MyRegister.calcNewStatus(val);
  217.  
  218.                                         for (int i = 0; i < 7; i++)
  219.                                         {
  220.                                             Console.WriteLine("Значение {0} ячейки: {1}", i, convertBoolInStr(MyRegister.getValOutput(Convert.ToByte(i))));
  221.                                         }
  222.                                         break;
  223.                                     }
  224.                                 case 3:
  225.                                     {
  226.                                         Menu();
  227.                                         break;
  228.                                     }
  229.                                 default:
  230.                                     {
  231.                                         throw new System.ArgumentException();
  232.                                         break;
  233.  
  234.                                     }
  235.  
  236.                             }
  237.  
  238.                             break;
  239.                         }
  240.                     case 4:
  241.                         {
  242.                             Environment.Exit(0);
  243.                             break;
  244.                         }
  245.  
  246.                     default:
  247.                         {
  248.                             throw new System.ArgumentException();
  249.                             break;
  250.                         }
  251.                 }
  252.             }
  253.             catch (ArgumentException)
  254.             {
  255.                 Console.WriteLine("Номер пункта не коректен");
  256.                 Menu();
  257.             }
  258.             catch (InvalidCastException)
  259.             {
  260.                 Console.WriteLine("Ошибка преобразования");
  261.                 Menu();
  262.             }
  263.         }
  264.  
  265.         static void highlight(string str)
  266.         {
  267.             Console.ForegroundColor = ConsoleColor.Cyan;
  268.             Console.Write(str);
  269.             Console.ResetColor();
  270.         }
  271.  
  272.         static string convertBoolInStr(bool bl)
  273.         {
  274.             if (bl)
  275.             {
  276.                 return "1";
  277.             }
  278.             else
  279.             {
  280.                 return "0";
  281.             }
  282.                                    
  283.         }
  284.  
  285.  
  286.     }
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement