Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- interface ISubscriberF
- {
- void Print();
- }
- class SubscriberFriend : ISubscriberF
- {
- string surname;
- string telephone;
- public string Surname
- {
- get
- {
- return surname;
- }
- set
- {
- surname = value;
- }
- }
- public string Telephone
- {
- get
- {
- return telephone;
- }
- set
- {
- telephone = value;
- }
- }
- public SubscriberFriend(string surname = "", string telephone = "")
- {
- this.surname = surname;
- this.telephone = telephone;
- }
- public void Print()
- {
- Console.WriteLine("ФИО: " + surname + ". Номер: " + telephone);
- }
- }
- class SubscriberEmployee : SubscriberFriend
- {
- string workPhone;
- string position;
- public string WorkPhone
- {
- get
- {
- return workPhone;
- }
- set
- {
- workPhone = value;
- }
- }
- public string Position
- {
- get
- {
- return position;
- }
- set
- {
- position = value;
- }
- }
- public SubscriberEmployee(string surname = "", string telephone = "",string workPhone = "",string position = "")
- {
- base.Surname = surname;
- base.Telephone = telephone;
- this.workPhone = workPhone;
- this.position = position;
- }
- public void Print()
- {
- base.Print();
- Console.WriteLine("рабочий тел.: " + workPhone + " должность: " + position);
- }
- }
- class SubscriberCompetitor : SubscriberEmployee
- {
- string homePhone;
- string homeAddress;
- public string HomePhone
- {
- get
- {
- return homePhone;
- }
- set
- {
- homePhone = value;
- }
- }
- public string HomeAddress
- {
- get
- {
- return homeAddress;
- }
- set
- {
- homeAddress = value;
- }
- }
- public SubscriberCompetitor(string surname = "", string telephone = "",string workPhone = "",string position = "",string homePhone = "", string homeAddress = "")
- {
- base.Surname = surname;
- base.Telephone = telephone;
- base.WorkPhone = workPhone;
- base.Position = position;
- this.homePhone = homePhone;
- this.homeAddress = homeAddress;
- }
- public void Print()
- {
- base.Print();
- Console.WriteLine("дом. тел.: " + homePhone + " дом. адрес: " + homeAddress);
- }
- }
- class AddressBook
- {
- SubscriberFriend[] arrFriend;
- SubscriberEmployee[] arrEmployee;
- SubscriberCompetitor[] arrCompetitor;
- public AddressBook()
- {
- arrFriend = new SubscriberFriend[0];
- arrEmployee = new SubscriberEmployee[0];
- arrCompetitor = new SubscriberCompetitor[0];
- }
- public void AddSubscriber(object obj, string ch)
- {
- switch (ch)
- {
- case "друг":
- case "Друг":
- SubscriberFriend[] newarrF = new SubscriberFriend[arrFriend.Length + 1];
- for (int i = 0; i < arrFriend.Length; i++)
- {
- newarrF[i] = arrFriend[i];
- }
- newarrF[arrFriend.Length] = (SubscriberFriend)obj;
- arrFriend = newarrF;
- break;
- case "сотрудник":
- case "Сотрудник":
- SubscriberEmployee[] newarrE = new SubscriberEmployee[arrEmployee.Length + 1];
- for (int i = 0; i < arrEmployee.Length; i++)
- {
- newarrE[i] = arrEmployee[i];
- }
- newarrE[arrEmployee.Length] = (SubscriberEmployee)obj;
- arrEmployee = newarrE;
- break;
- case "конкурент":
- case "Конкурент":
- SubscriberCompetitor[] newarrC = new SubscriberCompetitor[arrCompetitor.Length + 1];
- for (int i = 0; i < arrCompetitor.Length; i++)
- {
- newarrC[i] = arrCompetitor[i];
- }
- newarrC[arrCompetitor.Length] = (SubscriberCompetitor)obj;
- arrCompetitor = newarrC;
- break;
- }
- }
- public void PrintBook()
- {
- foreach (SubscriberFriend a in arrFriend)
- {
- a.Print();
- }
- foreach (SubscriberEmployee a in arrEmployee)
- {
- a.Print();
- }
- foreach (SubscriberCompetitor a in arrCompetitor)
- {
- a.Print();
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- AddressBook a = new AddressBook();
- string ch;
- while(true)
- {
- Console.Clear();
- Console.Write("Адресная книга\nДобавить абонента - 1\nПросмотреть книгу - 2\nВыйти из приложения - 3\nВаш выбор - ");
- ch = Console.ReadLine();
- switch (ch)
- {
- case "1":
- Console.Clear();
- Console.Write("Абонента какой группы: \nдруг - 1\nсотрудник - 2\nконкурент - 3\nВаш выбор - ");
- ch = Console.ReadLine();
- switch (ch)
- {
- case "1":
- Console.WriteLine("Заполните следующие поля: ФИО, телефон");
- SubscriberFriend f = new SubscriberFriend(Console.ReadLine(), Console.ReadLine());
- a.AddSubscriber(f, "друг");
- break;
- case "2":
- Console.WriteLine("Заполните следующие поля: ФИО, телефон, рабочий телефон, должность");
- SubscriberEmployee e = new SubscriberEmployee(Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine());
- a.AddSubscriber(e, "Сотрудник");
- break;
- case "3":
- Console.WriteLine("Заполните следующие поля: ФИО, телефон, рабочий телефон, должность, домашний телефон, домашний адрес");
- SubscriberCompetitor c = new SubscriberCompetitor(Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine());
- a.AddSubscriber(c, "Конкурент");
- break;
- default:
- break;
- }
- break;
- case "2":
- a.PrintBook();
- Console.ReadKey();
- break;
- case "3":
- default:
- return;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement