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 IFriend
- {
- string Surname { get; set; }
- string Telephone { get; set; }
- void Print();
- }
- interface IEmployee
- {
- string WorkPhone { get; set; }
- string Position { get; set; }
- }
- interface ICompetitor
- {
- string HomePhone { get; set; }
- string HomeAddress { get; set; }
- }
- class Friend : IFriend
- {
- public string Surname { get; set; }
- public string Telephone { get; set; }
- public Friend(string surname = "", string telephone = "")
- {
- Surname = surname;
- Telephone = telephone;
- }
- public void Print()
- {
- Console.WriteLine("ФИО: " + Surname + ". Номер: " + Telephone);
- }
- }
- class Employee : IFriend, IEmployee
- {
- public string Surname { get; set; }
- public string Telephone { get; set; }
- public string WorkPhone { get; set; }
- public string Position { get; set; }
- public Employee(string surname = "", string telephone = "", string workPhone = "", string position = "")
- {
- Surname = surname;
- Telephone = telephone;
- WorkPhone = workPhone;
- Position = position;
- }
- public void Print()
- {
- Console.WriteLine("ФИО: " + Surname + ". Номер: " + Telephone);
- Console.WriteLine("рабочий тел.: " + WorkPhone + " должность: " + Position);
- }
- }
- class Competitor : IFriend, IEmployee, ICompetitor
- {
- public string Surname { get; set; }
- public string Telephone { get; set; }
- public string WorkPhone { get; set; }
- public string Position { get; set; }
- public string HomePhone { get; set; }
- public string HomeAddress { get; set; }
- public Competitor(string surname = "", string telephone = "", string workPhone = "", string position = "", string homePhone = "", string homeAddress = "")
- {
- Surname = surname;
- Telephone = telephone;
- WorkPhone = workPhone;
- Position = position;
- HomePhone = homePhone;
- HomeAddress = homeAddress;
- }
- public void Print()
- {
- Console.WriteLine("ФИО: " + Surname + ". Номер: " + Telephone);
- Console.WriteLine("рабочий тел.: " + WorkPhone + " должность: " + Position);
- Console.WriteLine("дом. тел.: " + HomePhone + " дом. адрес: " + HomeAddress);
- }
- }
- class AddressBook
- {
- Friend[] arrFriend;
- Employee[] arrEmployee;
- Competitor[] arrCompetitor;
- public AddressBook()
- {
- arrFriend = new Friend[0];
- arrEmployee = new Employee[0];
- arrCompetitor = new Competitor[0];
- }
- public void AddSubscriber(object obj, string ch)
- {
- switch (ch)
- {
- case "друг":
- Friend[] newarrF = new Friend[arrFriend.Length + 1];
- for (int i = 0; i < arrFriend.Length; i++)
- {
- newarrF[i] = arrFriend[i];
- }
- newarrF[arrFriend.Length] = (Friend)obj;
- arrFriend = newarrF;
- break;
- case "сотрудник":
- Employee[] newarrE = new Employee[arrEmployee.Length + 1];
- for (int i = 0; i < arrEmployee.Length; i++)
- {
- newarrE[i] = arrEmployee[i];
- }
- newarrE[arrEmployee.Length] = (Employee)obj;
- arrEmployee = newarrE;
- break;
- case "конкурент":
- Competitor[] newarrC = new Competitor[arrCompetitor.Length + 1];
- for (int i = 0; i < arrCompetitor.Length; i++)
- {
- newarrC[i] = arrCompetitor[i];
- }
- newarrC[arrCompetitor.Length] = (Competitor)obj;
- arrCompetitor = newarrC;
- break;
- }
- }
- public void PrintBook()
- {
- Console.WriteLine("\nДрузья:\n");
- foreach (Friend a in arrFriend)
- {
- a.Print();
- }
- Console.WriteLine("\nСотрудники:\n");
- foreach (Employee a in arrEmployee)
- {
- a.Print();
- }
- Console.WriteLine("\nКонкуренты:\n");
- foreach (Competitor 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("Заполните следующие поля: ФИО, телефон");
- Friend f = new Friend(Console.ReadLine(), Console.ReadLine());
- a.AddSubscriber(f, "друг");
- break;
- case 1:
- Console.WriteLine("Заполните следующие поля: ФИО, телефон, рабочий телефон, должность");
- Employee e = new Employee(Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine());
- a.AddSubscriber(e, "сотрудник");
- break;
- case 2:
- Console.WriteLine("Заполните следующие поля: ФИО, телефон, рабочий телефон, должность, домашний телефон, домашний адрес");
- Competitor c = new Competitor(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