Advertisement
Guest User

my project

a guest
Nov 20th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Xml.Linq;
  5. using static System.Console;
  6.  
  7. /*#49
  8. Создать приложение для учета данных автосалона, в котором есть следующие элементы:
  9. 1. Автомобиль со следующими атрибутами: высота, стоимость, мощность двигателя, длина, название, модель, дата последнего тех. обслуживания, год выпуска, тип привода, цвет.
  10. 2. Автосалон со следующими атрибутами: прибыль, название, дата открытия, класс.
  11. 3. Рабочий со следующими атрибутами: зарплата, премия, отчество, имя, email, фамилия, дата приема на работу, дата рождения, должность.
  12. Также приложение должно реализовывать следующий функционал:
  13. 1. Самый старый магазин это ...
  14. 2. Вывести список автомобилей, где <тип_кпп> равняется Х
  15. 3. Реализовать автоматическое заполнение данными для автомобиля*/
  16.  
  17. namespace BaseAvtosalon
  18. {
  19.     class Program
  20.     {
  21.         static List<Employee> CEmployee = new List<Employee> { }; // Список подчиненных
  22.         static List<Saloon> CSaloon = new List<Saloon> { }; // Список салонов
  23.         static List<Auto> CAuto = new List<Auto> { };
  24.  
  25.         public static int CLC = 0; // slaoon - счётчик для динамического создания экземпляров класса Cheifs
  26.         public static int ELC = 0; // Employees Lisc Counter - счётчик для динамического создания экземпляров класса Employees
  27.         public static int ALC = 0; // auto
  28.         class Employee
  29.         {
  30.             private int _Age;
  31.             private int _Salary;
  32.             private int _Premia;
  33.             private string _Name;
  34.             private string _Surname;
  35.             private string _Thirdname;
  36.             private string _Dr;
  37.             private string _Dataraboty;
  38.             private string _Department;
  39.  
  40.             public string Name
  41.             {
  42.                 get { return _Name; }
  43.                 set
  44.                 {
  45.                     _Name = value;
  46.                 }
  47.             }
  48.             public string Surname
  49.             {
  50.                 get { return _Surname; }
  51.                 set
  52.                 {
  53.                     _Surname = value;
  54.                 }
  55.             }
  56.             public string Thirdname
  57.             {
  58.                 get { return _Thirdname; }
  59.                 set
  60.                 {
  61.                     _Thirdname = value;
  62.                 }
  63.             }
  64.  
  65.             public int Age
  66.             {
  67.                 get { return _Age; }
  68.                 set
  69.                 {
  70.                     if (value > 0)
  71.                     {
  72.                         _Age = value;
  73.                     }
  74.                     else
  75.                     {
  76.                         WriteLine(new String('-', 20));
  77.                         WriteLine("Age must be positive");
  78.                         WriteLine(new String('-', 20));
  79.                         Environment.Exit(1);
  80.                     }
  81.                 }
  82.             }
  83.             public int Premia
  84.             {
  85.                 get { return _Premia; }
  86.                 set
  87.                 {
  88.                     if (value > 0)
  89.                     {
  90.                         _Premia = value;
  91.                     }
  92.                     else
  93.                     {
  94.                         WriteLine(new String('-', 20));
  95.                         WriteLine("Premia must be positive");
  96.                         WriteLine(new String('-', 20));
  97.                         Environment.Exit(1);
  98.                     }
  99.                 }
  100.             }
  101.  
  102.             public int Salary
  103.             {
  104.                 get { return _Salary; }
  105.                 set
  106.                 {
  107.                     if (value > 0)
  108.                     {
  109.                         _Salary = value;
  110.                     }
  111.                     else
  112.                     {
  113.                         WriteLine(new String('-', 23));
  114.                         WriteLine("Salary must be positive");
  115.                         WriteLine(new String('-', 23));
  116.                         Environment.Exit(1);
  117.                     }
  118.                 }
  119.             }
  120.             public string Dr
  121.             {
  122.                 get { return _Dr; }
  123.                 set
  124.                 {
  125.                    _Dr = value;
  126.                 }
  127.             }
  128.             public string Dataraboty
  129.             {
  130.                 get { return _Dataraboty; }
  131.                 set
  132.                 {
  133.                     _Dataraboty = value;
  134.                 }
  135.             }
  136.  
  137.             public string Department
  138.             {
  139.                 get { return _Department; }
  140.                 set { _Department = value; }
  141.             }
  142.         }
  143.  
  144.          class Auto
  145.         {
  146.             private int _Height;
  147.             private int _Cost;
  148.             private int _Length;
  149.             private int _Hp;
  150.             private string _Birth;
  151.             private string _Date;
  152.             private string _Privod;
  153.             private string _Color;
  154.             private string _Name;
  155.             private string _Model;
  156.             private string _Tipkpp;
  157.  
  158.  
  159.             public int Height
  160.             {
  161.                 get { return _Height; }
  162.                 set
  163.                 {
  164.                     _Height = value;
  165.                 }
  166.             }
  167.             public int Cost
  168.             {
  169.                 get { return _Cost; }
  170.                 set
  171.                 {
  172.                     _Cost = value;
  173.                 }
  174.             }
  175.             public int Length
  176.             {
  177.                 get { return _Length; }
  178.                 set
  179.                 {
  180.                     _Length = value;
  181.                 }
  182.             }
  183.             public int Hp
  184.             {
  185.                 get { return _Hp; }
  186.                 set
  187.                 {
  188.                     _Hp = value;
  189.                 }
  190.             }
  191.             public string Birth
  192.             {
  193.                 get { return _Birth; }
  194.                 set
  195.                 {
  196.                     _Birth = value;
  197.                 }
  198.             }
  199.             public string Date
  200.             {
  201.                 get { return _Date; }
  202.                 set
  203.                 {
  204.                     _Date = value;
  205.                 }
  206.             }
  207.             public string Privod
  208.             {
  209.                 get { return _Privod; }
  210.                 set
  211.                 {
  212.                     _Privod = value;
  213.                 }
  214.             }
  215.             public string Color
  216.             {
  217.                 get { return _Color; }
  218.                 set
  219.                 {
  220.                     _Color = value;
  221.                 }
  222.             }
  223.             public string Name
  224.             {
  225.                 get { return _Name; }
  226.                 set
  227.                 {
  228.                     _Name = value;
  229.                 }
  230.             }
  231.             public string Model
  232.             {
  233.                 get { return _Model; }
  234.                 set
  235.                 {
  236.                     _Model = value;
  237.                 }
  238.             }
  239.             public string Tipkpp
  240.             {
  241.                 get { return _Tipkpp; }
  242.                 set
  243.                 {
  244.                     _Tipkpp = value;
  245.                 }
  246.             }
  247.         }
  248.  
  249.         class Saloon
  250.         {
  251.             private int _Profit;
  252.             private string _Name;
  253.             private string _Class;
  254.             private int _Birth;
  255.  
  256.             public int Profit
  257.             {
  258.                 get { return _Profit; }
  259.                 set
  260.                 {
  261.                     _Profit = value;
  262.                 }
  263.             }
  264.             public string Name
  265.             {
  266.                 get { return _Name; }
  267.                 set
  268.                 {
  269.                     _Name = value;
  270.                 }
  271.             }
  272.             public string Class
  273.             {
  274.                 get { return _Class; }
  275.                 set
  276.                 {
  277.                     _Class = value;
  278.                 }
  279.             }
  280.             public int Birth
  281.             {
  282.                 get { return _Birth; }
  283.                 set
  284.                 {
  285.                     _Birth = value;
  286.                 }
  287.             }
  288.         }
  289.        
  290.         static void AddAuto()
  291.         {
  292.             /*  private int _Height;
  293.             private int _Cost;
  294.             private int _Length;
  295.             private int _Hp;
  296.             private string _Birth;
  297.             private string _Date;
  298.             private string _Privod;
  299.             private string _Color;
  300.             private string _Name;
  301.             private string _Model;
  302.             private string _Tipkpp;*/
  303.             WriteLine("Write cost of car");
  304.             CAuto[ALC].Cost = Convert.ToInt32(ReadLine());
  305.  
  306.             WriteLine("Write height of car");
  307.             CAuto[ALC].Height = Convert.ToInt32(ReadLine());
  308.  
  309.             WriteLine("Write length of car");
  310.             CAuto[ALC].Length= Convert.ToInt32(ReadLine());
  311.  
  312.             WriteLine("Write profit of company");
  313.             CAuto[ALC].Hp = Convert.ToInt32(ReadLine());
  314.  
  315.             WriteLine("Write profit of company");
  316.             CAuto[ALC].Birth = ReadLine();
  317.  
  318.             WriteLine("Write profit of company");
  319.             CAuto[ALC].Date = ReadLine();
  320.  
  321.             WriteLine("Write profit of company");
  322.             CAuto[ALC].Privod = ReadLine();
  323.  
  324.             WriteLine("Write profit of company");
  325.             CAuto[ALC].Color = ReadLine();
  326.  
  327.             WriteLine("Write profit of company");
  328.             CAuto[ALC].Name = ReadLine();
  329.  
  330.             WriteLine("Write profit of company");
  331.             CAuto[ALC].Model = ReadLine();
  332.  
  333.             WriteLine("Write profit of company");
  334.             CAuto[ALC].Tipkpp = ReadLine();
  335.         }
  336.  
  337.         static void AddSaloon()
  338.         {
  339.             CSaloon.Add(new Saloon());
  340.  
  341.             WriteLine("Write profit of company");
  342.             CSaloon[CLC].Profit = Convert.ToInt32(ReadLine());
  343.  
  344.             WriteLine("Write name of company");
  345.             CSaloon[CLC].Name = ReadLine();
  346.  
  347.             WriteLine("Write birth of company");
  348.             CSaloon[CLC].Birth = Convert.ToInt32(ReadLine());
  349.  
  350.             WriteLine("Write class of company");
  351.             CSaloon[CLC].Class = ReadLine();
  352.             CLC++;
  353.         }
  354.  
  355.         static void AddEmployee()
  356.         {
  357.         CEmployee.Add(new Employee());
  358.  
  359.             WriteLine("Write first name");
  360.             CEmployee[ELC].Name = ReadLine();
  361.  
  362.             WriteLine("Write second name");
  363.             CEmployee[ELC].Surname = ReadLine();
  364.  
  365.             WriteLine("Write third name");
  366.             CEmployee[ELC].Thirdname = ReadLine();
  367.  
  368.             WriteLine("Write age of employee");
  369.             CEmployee[ELC].Age = Convert.ToInt32(ReadLine());
  370.  
  371.             WriteLine("Write salary of employee");
  372.             CEmployee[ELC].Salary = Convert.ToInt32(ReadLine());
  373.  
  374.             WriteLine("Write premia of employee");
  375.             CEmployee[ELC].Premia = Convert.ToInt32(ReadLine());
  376.  
  377.             WriteLine("Write birthday");
  378.             CEmployee[ELC].Dr = ReadLine();
  379.  
  380.             WriteLine("Write date of work");
  381.             CEmployee[ELC].Dataraboty = ReadLine();
  382.  
  383.             WriteLine("Write department of employee");
  384.             CEmployee[ELC].Department = ReadLine();
  385.  
  386.             ELC++;
  387.         }
  388.         static bool AlreadyExist(string Name,string Surname,string Thirdname)
  389.         {
  390.             int local_i = 0;
  391.             foreach (Employee Hmn in CEmployee)
  392.             {
  393.                 if (Hmn.Name == Name && Hmn.Surname == Surname && Hmn.Thirdname == Thirdname)
  394.                 {
  395.                     return true;
  396.                 }
  397.                 else
  398.                 {
  399.                     local_i++;
  400.                 }
  401.             }
  402.             return false;
  403.         }
  404.  
  405.         static void InfoByName()
  406.         {
  407.             WriteLine("Write first, second and third name of person:");
  408.             string[] tmp = ReadLine().Split().ToArray();
  409.             string person1 = tmp[0];
  410.             string person2 = tmp[1];
  411.             string person3 = tmp[2];
  412.             if (AlreadyExist(person1,person2,person3) == false)
  413.             {
  414.                 WriteLine("Person are not exist");
  415.             }
  416.  
  417.             foreach (Employee Hmn in CEmployee)
  418.             {
  419.                 if (person1 == Hmn.Name && person2 == Hmn.Surname && person3 == Hmn.Thirdname)
  420.                 {
  421.                     WriteLine(new String('-', 20));
  422.                     WriteLine("Name: {0}\nSurname:{1}\nThirdname{2}\nAge: {3}\nSalary: {4}\nDepartment: {5}\nBirthday{6}\nDate work{7}\nPremia:{8}\n", Hmn.Name,Hmn.Surname,Hmn.Thirdname, Hmn.Age, Hmn.Salary, Hmn.Department, Hmn.Dr, Hmn.Dataraboty, Hmn.Premia);
  423.                     WriteLine(new String('-', 20));
  424.                     break;
  425.                 }
  426.             }
  427.         }
  428.  
  429.         static void InfoByType()
  430.         {
  431.             Console.WriteLine("Write typy of KPP");
  432.                 string kpp = Console.ReadLine();
  433.                
  434.                 foreach (Auto hauto in CAuto)
  435.                 {
  436.                 if (kpp == "mechanical")
  437.                 {
  438.                     WriteLine(new String('-', 20));
  439.                     WriteLine("Cost:{0}\nLength{1}\nHP:{2}\nBirthdate:{3}\nDate repair:{4}\nType privod:{5}\nColor:{6}\nName:{7}\nModel{8}\n", hauto.Cost, hauto.Length,hauto.Hp,hauto.Birth,hauto.Date,hauto.Privod,hauto.Color,hauto.Name,hauto.Model);
  440.                     WriteLine(new String('-', 20));
  441.                 }
  442.                 else if (kpp == "auto")
  443.                 {
  444.                     WriteLine(new String('-', 20));
  445.                     WriteLine("Cost:{0}\nLength{1}\nHP:{2}\nBirthdate:{3}\nDate repair:{4}\nType privod:{5}\nColor:{6}\nName:{7}\nModel{8}\n", hauto.Cost, hauto.Length, hauto.Hp, hauto.Birth, hauto.Date, hauto.Privod, hauto.Color, hauto.Name, hauto.Model);
  446.                     WriteLine(new String('-', 20));
  447.                 }
  448.                 else if (kpp == "variator")
  449.                 {
  450.                     WriteLine(new String('-', 20));
  451.                     WriteLine("Cost:{0}\nLength{1}\nHP:{2}\nBirthdate:{3}\nDate repair:{4}\nType privod:{5}\nColor:{6}\nName:{7}\nModel{8}\n", hauto.Cost, hauto.Length, hauto.Hp, hauto.Birth, hauto.Date, hauto.Privod, hauto.Color, hauto.Name, hauto.Model);
  452.                     WriteLine(new String('-', 20));
  453.                 }
  454.                 else
  455.                 {
  456.                     Console.WriteLine("Wrong type of KPP");
  457.                 }
  458.                 }
  459.          
  460.            
  461.         }
  462.  
  463.        static void Old()
  464.         {
  465.             int data = 0;
  466.             string name = null;
  467.             foreach (Saloon sln in CSaloon)
  468.             {
  469.             /* private int _Profit;
  470.             private string _Name;
  471.             private string _Class;
  472.             private string _Birth;*/
  473.  
  474.             if (data < sln.Birth)
  475.                 {
  476.                     data = sln.Birth;
  477.                     name = sln.Name;
  478.                     break;
  479.                 }
  480.             }
  481.             Console.WriteLine(name);
  482.         }
  483.  
  484.  
  485.  
  486.  
  487.         static void Main(string[] args)
  488.         {
  489.         label1:
  490.             WriteLine(new String('-', 21) + "\nPrint type of command\n1:Add Auto" +
  491.                       "\n2:Add Employee " +
  492.                       "\n3:Get Info via Name\n4:Get Info via Type KPP\n5:Get elder saloon\n6:Add Saloon\n" + new String('-', 21));
  493.             int typeOfCommand = Convert.ToInt32(ReadLine());
  494.             switch (typeOfCommand)
  495.             {
  496.                 case 1:
  497.                     AddAuto();
  498.                     goto label1;
  499.                     break;
  500.                 case 2:
  501.                     AddEmployee();
  502.                     goto label1;
  503.                     break;
  504.                 case 3:
  505.                     InfoByName();
  506.                     goto label1;
  507.                     break;
  508.                 case 4:
  509.                     InfoByType();
  510.                     goto label1;
  511.                     break;
  512.                 case 5:
  513.                     Old();
  514.                     goto label1;
  515.                     break;
  516.                 case 6:
  517.                     AddSaloon();
  518.                     goto label1;
  519.                     break;
  520.             }
  521.         }
  522.     }
  523. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement