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 readonly string arrow = "=> ";
- static readonly string[] menu = { "Добавить абонента", "Просмотреть книгу", "Выйти из приложения" };
- static readonly string[] submenu = { "Друг", "Сотрудник", "Конкурент" ,"Возврат в предыдущее меню"};
- static void PrintMenu(string []arr, int choice)
- {
- Console.Clear();
- for(int i=0;i<arr.Length;i++)
- {
- if (i == choice)
- {
- Console.Write(arrow);
- Console.WriteLine(arr[i]);
- }
- else
- {
- Console.Write(" ");
- Console.WriteLine(arr[i]);
- }
- }
- }
- static void SelectFunc(AddressBook a, int choice)
- {
- Console.CursorVisible = false;
- int ch = 0;
- switch(choice)
- {
- case 0:
- while(true)
- {
- PrintMenu(submenu, ch);
- switch (Console.ReadKey(true).Key)
- {
- case ConsoleKey.UpArrow:
- if (ch != 0)
- {
- ch--;
- }
- break;
- case ConsoleKey.DownArrow:
- if (ch != submenu.Length - 1)
- {
- ch++;
- }
- break;
- case ConsoleKey.Enter:
- Console.CursorVisible = true;
- switch (ch)
- {
- case 0:
- Console.WriteLine("Заполните следующие поля: ФИО, телефон");
- SubscriberFriend f = new SubscriberFriend(Console.ReadLine(), Console.ReadLine());
- a.AddSubscriber(f, "друг");
- break;
- case 1:
- Console.WriteLine("Заполните следующие поля: ФИО, телефон, рабочий телефон, должность");
- SubscriberEmployee e = new SubscriberEmployee(Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine());
- a.AddSubscriber(e, "Сотрудник");
- break;
- case 2:
- Console.WriteLine("Заполните следующие поля: ФИО, телефон, рабочий телефон, должность, домашний телефон, домашний адрес");
- SubscriberCompetitor c = new SubscriberCompetitor(Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine());
- a.AddSubscriber(c, "Конкурент");
- break;
- case 3:
- return;
- }
- break;
- }
- }
- break;
- case 1:
- a.PrintBook();
- Console.ReadKey();
- break;
- case 2:
- System.Environment.Exit(0);
- break;
- }
- }
- static void Main(string[] args)
- {
- AddressBook a = new AddressBook();
- Console.CursorVisible = false;
- int choice = 0;
- while(true)
- {
- PrintMenu(menu, choice);
- switch (Console.ReadKey(true).Key)
- {
- case ConsoleKey.UpArrow:
- if(choice!=0)
- {
- choice--;
- }
- break;
- case ConsoleKey.DownArrow:
- if(choice!=menu.Length - 1)
- {
- choice++;
- }
- break;
- case ConsoleKey.Enter:
- Console.CursorVisible = true;
- SelectFunc(a, choice);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement