Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.09 KB | None | 0 0
  1. using System;
  2. //using System.Text;
  3. //using System.Threading.Tasks;
  4. //using System.Linq;
  5. //using System.IO;
  6. using System.Collections.Generic; //пространство имен для List <>
  7.  
  8. namespace bazaRabochihTheBEST
  9. {
  10.     class Program
  11.     {
  12.        public static List<object> otdely = new List<object>();
  13.        public static List<object> bosses = new List<object>();
  14.        public static List<object> rabotniki = new List<object>();
  15.  
  16.       public static  int nomer_otdela;
  17.        
  18.         public struct OTDEL
  19.         {
  20.             public string name;
  21.  
  22.             public OTDEL(string name)
  23.             {
  24.                 this.name = name;
  25.             }
  26.         }
  27.  
  28.         public struct BOSS
  29.         {
  30.             public string name;
  31.             public int age;
  32.             public long salary;
  33.             public object name_otd;
  34.  
  35.             //МАССИВ(ЛИСТ/СПИСОК) ИЗ СТРУКТУР РАБОТНИКОВ
  36.  
  37.                 //В КАКОМ ОТДЕЛЕ
  38.  
  39.             public BOSS(string name, int age, long salary, object name_otd)
  40.             {
  41.                 this.name = name;
  42.                 this.age = age;
  43.                 this.salary = salary;
  44.                 this.name_otd = name_otd;
  45.             }
  46.         }
  47.  
  48.         public struct RABOTNIK
  49.         {
  50.             public string name;
  51.             public int age;
  52.             public long salary;
  53.             public object name_otd;
  54.             public object name_boss;
  55.  
  56.             public RABOTNIK (string name, int age, long salary, object name_otd, object name_boss)
  57.             {
  58.                 this.name = name;
  59.                 this.age = age;
  60.                 this.salary = salary;
  61.                 this.name_otd = name_otd;
  62.                 this.name_boss = name_boss;
  63.             }
  64.             //КТО БОСС
  65.  
  66.             //В КАКОМ ОТДЕЛЕ
  67.  
  68.         }
  69.  
  70.         public static void whatCreate()
  71.         {
  72.             int x = 1;
  73.             while (x != 0)
  74.             {
  75.                 Console.WriteLine("Что вы хотите создать? (введите выбранный пункт) \n 1. Отдел \n 2. Начальника \n 3. Работника \n Введите 0, если хотите выйти из программы.");
  76.                 int a = Convert.ToInt32(Console.ReadLine());
  77.                 x = a;
  78.                 switch (a)
  79.                 {
  80.                     case 1:
  81.                         Console.WriteLine("Создание отдела!");
  82.                         genOtdel();
  83.  
  84.                         break;
  85.  
  86.                     case 2:
  87.                         Console.WriteLine("Создание начальника!");
  88.                         genBoss();
  89.                         break;
  90.  
  91.                     case 3:
  92.                         Console.WriteLine("Создание работника!");
  93.                         //genRabotnik();
  94.                         break;
  95.  
  96.                     case 0:
  97.                         break;
  98.                 }
  99.             }
  100.  
  101.                
  102.            
  103.         }
  104.  
  105.         public static string write(string x)
  106.         {
  107.             Console.Write($"{x} : ");
  108.             return Console.ReadLine();
  109.         }
  110.  
  111.         public static void genOtdel()
  112.         {
  113.             OTDEL otd = new OTDEL();
  114.             otd.name = write("Название отдела");
  115.             Console.WriteLine(" ");
  116.             otdely.Add(otd.name);
  117.         }
  118.  
  119.       /*  public static void vKakoiOtdelBossa (int a)
  120.         {
  121.             switch (a)
  122.             {
  123.                 case 0:
  124.                     genOtdel();
  125.                     break;
  126.  
  127.             }
  128.         }*/
  129.  
  130.  
  131.         public static void kudaOpredelitBossa()
  132.         {
  133.             Console.WriteLine("Перед тем, как создать босса, необходимо выбрать отдел, в котором он будет. Список отделов:");
  134.  
  135.  
  136.             for(int i = 0; i < otdely.Count; i++)
  137.             {
  138.                 Console.WriteLine($"{i+1}. {otdely[i]} ");
  139.             }
  140.             Console.WriteLine("Введите номер отдела, в который вы ходите определить босса. Введите 0, если хотите создать новый отдел.");
  141.             int a = Convert.ToInt32(Console.ReadLine());
  142.  
  143.             if (a != 0)
  144.             {
  145.                 nomer_otdela = a - 1;
  146.             }
  147.             else
  148.             {
  149.                 nomer_otdela = otdely.Count;
  150.                 genOtdel();
  151.             }
  152.  
  153.            
  154.            
  155.         }
  156.  
  157.         public static void genBoss()
  158.         {
  159.             kudaOpredelitBossa();
  160.             BOSS boss = new BOSS();
  161.             boss.name = write("Имя босса");
  162.             boss.age = Convert.ToInt32(write("Возраст босса"));
  163.             boss.salary = Convert.ToInt64(write("Зарплата босса"));
  164.             boss.name_otd = otdely[nomer_otdela];
  165.  
  166.             Console.WriteLine($"Отдел босса: {boss.name_otd}");
  167.             Console.WriteLine(" ");
  168.  
  169.             bosses.Add(boss);
  170.  
  171.  
  172.                // otdely[a].Add(boss);
  173.         }
  174.  
  175.  
  176.         public static void genOtdelANDBoss()
  177.         {
  178.             int index_otd = otdely.Count;
  179.  
  180.             genOtdel();
  181.  
  182.             //int index_bosses = bosses.Count;
  183.  
  184.             BOSS boss = new BOSS();
  185.             boss.name = write("Имя босса");
  186.             boss.age = Convert.ToInt32(write("Возраст босса"));
  187.             boss.salary = Convert.ToInt64(write("Зарплата босса"));
  188.             boss.name_otd = otdely[index_otd];
  189.  
  190.             Console.WriteLine($"Отдел босса: {boss.name_otd}");
  191.             Console.WriteLine(" ");
  192.  
  193.             bosses.Add(boss);
  194.  
  195.         }
  196.  
  197.         public static void genRabotnik()
  198.         {
  199.             Console.WriteLine("Прежде чем создать работника, необходимо выбрать отдел, в котором он будет числиться. Список отделов: ");
  200.  
  201.             for (int i = 0; i < otdely.Count; i++)
  202.             {
  203.                 Console.WriteLine($"{i + 1}. {otdely[i]} ");
  204.             }
  205.  
  206.             Console.WriteLine("Введите номер выбранного отдела. Если хоите создать новый отдел - введите 0.");
  207.  
  208.             int nomer_otdela2 = Convert.ToInt32(Console.ReadLine());
  209.  
  210.             if (nomer_otdela2 == 0)
  211.             {
  212.                 RABOTNIK rab = new RABOTNIK();
  213.                 int index_otd = otdely.Count;
  214.                // int index_bosses = bosses.Count;
  215.                 genOtdelANDBoss();
  216.                 rab.name = write("Имя работника");
  217.                 rab.age = Convert.ToInt32(write("Возраст работника"));
  218.                 rab.salary = Convert.ToInt64(write("Зарплата работника"));
  219.                 rab.name_otd = otdely[index_otd];
  220.  
  221.             }
  222.  
  223.         }
  224.  
  225.      
  226.         static void Main(string[] args)
  227.         {
  228.            
  229.            
  230.            
  231.                 /*Console.WriteLine("Что вы хотите создать? (введите выбранный пункт) \n 1. Отдел \n 2. Начальника \n 3. Работника");
  232.                 int a = Convert.ToInt32(Console.ReadLine());*/
  233.                 whatCreate();
  234.            
  235.                 /*if (a==0)
  236.                 {
  237.                     Console.WriteLine("Вы вышли из программы!!!");
  238.                     return 0;
  239.                 }
  240.                 else
  241.                 {
  242.                     whatCreate(a);
  243.                 }*/
  244.  
  245.        
  246.             }
  247.  
  248.           //  otdely.AddRange(OTDEL);
  249.  
  250.  
  251.            /* foreach(object i in otdely)
  252.             {
  253.                 Console.WriteLine(i); //первый прогон: i=0, но здесь при foreach в первом прогоне i=otdely[i], т.е. самому значению элемента
  254.             }
  255.             */
  256.  
  257.  
  258.            // Console.WriteLine("Hello World!");
  259.        
  260.     }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement