Advertisement
AnyaAS

AddressBook

Jun 2nd, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     interface ISubscriberF
  10.     {
  11.         void Print();
  12.     }
  13.    
  14.     class SubscriberFriend : ISubscriberF
  15.     {
  16.         string surname;
  17.         string telephone;
  18.         public string Surname
  19.         {
  20.             get
  21.             {
  22.                 return surname;
  23.             }
  24.             set
  25.             {
  26.                 surname = value;
  27.             }
  28.         }
  29.  
  30.         public string Telephone
  31.         {
  32.             get
  33.             {
  34.                 return telephone;
  35.             }
  36.             set
  37.             {
  38.                 telephone = value;
  39.             }
  40.         }
  41.         public SubscriberFriend(string surname = "", string telephone = "")
  42.         {
  43.             this.surname = surname;
  44.             this.telephone = telephone;
  45.         }
  46.         public void Print()
  47.         {
  48.             Console.WriteLine("ФИО: " + surname + ". Номер: " + telephone);
  49.         }
  50.  
  51.      
  52.     }
  53.     class SubscriberEmployee : SubscriberFriend
  54.     {
  55.         string workPhone;
  56.         string position;
  57.        
  58.         public string WorkPhone
  59.         {
  60.             get
  61.             {
  62.                 return workPhone;
  63.             }
  64.             set
  65.             {
  66.                 workPhone = value;
  67.             }
  68.         }
  69.         public string Position
  70.         {
  71.             get
  72.             {
  73.                 return position;
  74.             }
  75.             set
  76.             {
  77.                 position = value;
  78.             }
  79.         }
  80.         public SubscriberEmployee(string surname = "", string telephone = "",string workPhone = "",string position = "")
  81.         {
  82.             base.Surname = surname;
  83.             base.Telephone = telephone;
  84.             this.workPhone = workPhone;
  85.             this.position = position;
  86.         }
  87.         public void Print()
  88.         {
  89.             base.Print();
  90.             Console.WriteLine("рабочий тел.: " + workPhone + " должность: " + position);
  91.         }
  92.  
  93.     }
  94.     class SubscriberCompetitor : SubscriberEmployee
  95.     {
  96.         string homePhone;
  97.         string homeAddress;        
  98.         public string HomePhone
  99.         {
  100.             get
  101.             {
  102.                 return homePhone;
  103.             }
  104.             set
  105.             {
  106.                 homePhone = value;
  107.             }
  108.         }
  109.  
  110.         public string HomeAddress
  111.         {
  112.             get
  113.             {
  114.                 return homeAddress;
  115.             }
  116.             set
  117.             {
  118.                 homeAddress = value;
  119.             }
  120.         }
  121.         public SubscriberCompetitor(string surname = "", string telephone = "",string workPhone = "",string position = "",string homePhone = "", string homeAddress = "")
  122.         {
  123.             base.Surname = surname;
  124.             base.Telephone = telephone;
  125.             base.WorkPhone = workPhone;
  126.             base.Position = position;
  127.             this.homePhone = homePhone;
  128.             this.homeAddress = homeAddress;
  129.         }
  130.         public void Print()
  131.         {
  132.             base.Print();
  133.             Console.WriteLine("дом. тел.: " + homePhone + " дом. адрес: " + homeAddress);
  134.         }        
  135.     }
  136.  
  137.     class AddressBook
  138.     {
  139.         SubscriberFriend[] arrFriend;
  140.         SubscriberEmployee[] arrEmployee;
  141.         SubscriberCompetitor[] arrCompetitor;
  142.  
  143.         public AddressBook()
  144.         {
  145.             arrFriend = new SubscriberFriend[0];
  146.             arrEmployee = new SubscriberEmployee[0];
  147.             arrCompetitor = new SubscriberCompetitor[0];
  148.         }
  149.  
  150.         public void AddSubscriber(object obj, string ch)
  151.         {
  152.             switch (ch)
  153.             {
  154.                 case "друг":
  155.                 case "Друг":
  156.                     SubscriberFriend[] newarrF = new SubscriberFriend[arrFriend.Length + 1];
  157.                     for (int i = 0; i < arrFriend.Length; i++)
  158.                     {
  159.                         newarrF[i] = arrFriend[i];
  160.                     }
  161.                     newarrF[arrFriend.Length] = (SubscriberFriend)obj;
  162.                     arrFriend = newarrF;
  163.                     break;
  164.                 case "сотрудник":
  165.                 case "Сотрудник":
  166.                     SubscriberEmployee[] newarrE = new SubscriberEmployee[arrEmployee.Length + 1];
  167.                     for (int i = 0; i < arrEmployee.Length; i++)
  168.                     {
  169.                         newarrE[i] = arrEmployee[i];
  170.                     }
  171.                     newarrE[arrEmployee.Length] = (SubscriberEmployee)obj;
  172.                     arrEmployee = newarrE;
  173.                     break;
  174.                 case "конкурент":
  175.                 case "Конкурент":
  176.                     SubscriberCompetitor[] newarrC = new SubscriberCompetitor[arrCompetitor.Length + 1];
  177.                     for (int i = 0; i < arrCompetitor.Length; i++)
  178.                     {
  179.                         newarrC[i] = arrCompetitor[i];
  180.                     }
  181.                     newarrC[arrCompetitor.Length] = (SubscriberCompetitor)obj;
  182.                     arrCompetitor = newarrC;
  183.                     break;
  184.             }
  185.         }
  186.         public void PrintBook()
  187.         {
  188.             foreach (SubscriberFriend a in arrFriend)
  189.             {
  190.                 a.Print();
  191.             }
  192.             foreach (SubscriberEmployee a in arrEmployee)
  193.             {
  194.                 a.Print();
  195.             }
  196.             foreach (SubscriberCompetitor a in arrCompetitor)
  197.             {
  198.                 a.Print();
  199.             }
  200.         }
  201.     }
  202.  
  203.     class Program
  204.     {
  205.         static void Main(string[] args)
  206.         {
  207.             AddressBook a = new AddressBook();
  208.             string ch;
  209.            
  210.             while(true)
  211.             {                
  212.                 Console.Clear();
  213.                 Console.Write("Адресная книга\nДобавить абонента - 1\nПросмотреть книгу - 2\nВыйти из приложения - 3\nВаш выбор - ");
  214.                 ch = Console.ReadLine();
  215.                 switch (ch)
  216.                 {                        
  217.                     case "1":
  218.                         Console.Clear();
  219.                         Console.Write("Абонента какой группы: \nдруг - 1\nсотрудник - 2\nконкурент - 3\nВаш выбор - ");
  220.                         ch = Console.ReadLine();
  221.                         switch (ch)
  222.                         {
  223.                             case "1":
  224.                                 Console.WriteLine("Заполните следующие поля: ФИО, телефон");
  225.                                 SubscriberFriend f = new SubscriberFriend(Console.ReadLine(), Console.ReadLine());
  226.                                 a.AddSubscriber(f, "друг");
  227.                                 break;
  228.                             case "2":
  229.                                 Console.WriteLine("Заполните следующие поля: ФИО, телефон, рабочий телефон, должность");
  230.                                 SubscriberEmployee e = new SubscriberEmployee(Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine());
  231.                                 a.AddSubscriber(e, "Сотрудник");
  232.                                 break;
  233.                             case "3":
  234.                                 Console.WriteLine("Заполните следующие поля: ФИО, телефон, рабочий телефон, должность, домашний телефон, домашний адрес");
  235.                                 SubscriberCompetitor c = new SubscriberCompetitor(Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine());
  236.                                 a.AddSubscriber(c, "Конкурент");
  237.                                 break;
  238.                             default:
  239.                                 break;
  240.                         }
  241.                         break;
  242.                     case "2":
  243.                         a.PrintBook();
  244.                         Console.ReadKey();
  245.                         break;
  246.                     case "3":
  247.                     default:
  248.                         return;
  249.                 }
  250.             }  
  251.         }
  252.     }
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement