HaoAsakura

loh33

Oct 18th, 2023
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace PracticingPolygon
  5. {
  6.     public abstract class id  //sozdaem abstract class
  7.     {
  8.         public abstract int Id { get; set; }
  9.     }
  10.     public class Pc : id
  11.     {
  12.         public override int Id { get; set; }
  13.         public string name { get; private set; }
  14.  
  15.         public Pc(int Id, string name)
  16.         { this.Id = Id; this.name = name; }
  17.  
  18.     }
  19.     public class Kabinet : id
  20.     {
  21.         public override int Id { get; set; }
  22.         public string name { get; private set; }
  23.         public List<Pc> Computers = new List<Pc>();
  24.         public Kabinet(int id, string name, List<Pc> computers)
  25.         {
  26.             this.Id = id;
  27.             this.name = name;
  28.             this.Computers = computers;
  29.         }
  30.         public static void GetComputerFromKabinet(List<Kabinet> kabinets, int id)
  31.         {
  32.             for (int i = 0; i < kabinets.Count; i++)
  33.             {
  34.                 for (int k = 0; k < kabinets[i].Computers.Count; k++)
  35.                 {
  36.                     if (kabinets[i].Computers[k].Id == id)
  37.                         Console.WriteLine($"Компьютер({kabinets[i].Computers[k].name}) " +
  38.                             $"{kabinets[i].Computers[k].Id} " +
  39.                             $"был найден в кабинете №{kabinets[i].Id}({kabinets[i].name})");
  40.                 }
  41.             }
  42.         }
  43.     }
  44.  
  45.     internal class Program
  46.     {
  47.         static void Main(string[] args)
  48.         {
  49.             List<Kabinet> kabinets = new List<Kabinet>()
  50.             {
  51.                 new Kabinet(1,"Химия",new List<Pc>()
  52.                 {
  53.                     new Pc(136,"Асус топ 31 вива букк"),
  54.                     new Pc(1599, "Марин Турбо 5к"),
  55.                     new Pc(33, "UTM super nout 313")
  56.                 }),
  57.                 new Kabinet(55,"Биология",new List<Pc>()
  58.                 {
  59.                     new Pc(6343,"31ok"),
  60.                     new Pc(159, "tubro33"),
  61.                     new Pc(13, "loh1")
  62.                 })
  63.             };
  64.  
  65.             Console.Write("Введите id компьютера который хотите найти: ");
  66.             int id = int.Parse(Console.ReadLine());
  67.  
  68.             Kabinet.GetComputerFromKabinet(kabinets, id);
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment