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 CSLight
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] fullNames = { "Иванов Иван Иванович" };
- string[] positions = { "Программист" };
- int userChoice;
- bool isWorking = true;
- while (isWorking)
- {
- Console.WriteLine("1) добавить досье\n2) вывести все досье\n3) удалить досье\n4) поиск по фамилии\n5) выход\n");
- userChoice = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- switch (userChoice)
- {
- case 1:
- AddDossier(ref fullNames, ref positions);
- break;
- case 2:
- PrintDossier(fullNames, positions);
- break;
- case 3:
- DeleteDossier(ref fullNames, ref positions);
- break;
- case 4:
- Search(fullNames, positions);
- break;
- case 5:
- isWorking = false;
- break;
- default:
- Console.WriteLine("\nПовторите ввод:");
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void PrintDossier(string[] fullNames, string[] positions)
- {
- Console.WriteLine("Список сотрудников:");
- for (int i = 0; i < fullNames.Length; i++)
- {
- Console.Write($"{i + 1}. " + fullNames[i] + " - " + positions[i] + " ");
- }
- }
- static void DeleteDossier(ref string[] fullNames, ref string[] positions)
- {
- string fullName;
- int indexForDelete = 0;
- string[] tempFullNames = new string[fullNames.Length - 1];
- string[] tempPositions = new string[positions.Length - 1];
- Console.WriteLine("Введите инициалы сотрудника: ");
- fullName = Console.ReadLine();
- for (int i = 0; i < fullNames.Length; i++)
- {
- if (fullNames[i].Contains(fullName))
- {
- indexForDelete = i;
- }
- }
- for (int i = 0; i < indexForDelete; i++)
- {
- tempFullNames[i] = fullNames[i];
- tempPositions[i] = positions[i];
- }
- for (int i = indexForDelete + 1; i < fullNames.Length; i++)
- {
- tempFullNames[i - 1] = fullNames[i];
- tempPositions[i - 1] = positions[i];
- }
- ReplaceArray(ref tempFullNames, ref fullNames, ref tempPositions, ref positions);
- }
- static void AddDossier(ref string[] fullNames, ref string[] positions)
- {
- string fullName;
- string position;
- string[] tempFullNames = new string[fullNames.Length + 1];
- string[] tempPositions = new string[positions.Length + 1];
- Console.WriteLine("Введите ФИО сотрудника:");
- fullName = Console.ReadLine();
- Console.WriteLine("\nВведите должность сотрудника: ");
- position = Console.ReadLine();
- for (int i = 0; i < fullNames.Length; i++)
- {
- tempFullNames[i] = fullNames[i];
- tempPositions[i] = positions[i];
- }
- tempFullNames[tempPositions.Length - 1] = fullName;
- tempPositions[tempPositions.Length - 1] = position;
- ReplaceArray(ref tempFullNames, ref fullNames, ref tempPositions, ref positions);
- }
- static void ReplaceArray(ref string[] previousFullNames, ref string[] presentFullNames, ref string[] previousPositions, ref string[] presentPositions)
- {
- presentFullNames = previousFullNames;
- presentPositions = previousPositions;
- }
- static void Search(string[] fullNames, string[] positions)
- {
- Console.WriteLine("Введите фамилию сотрудника: ");
- string lastName = Console.ReadLine();
- for (int i = 0; i < fullNames.Length; i++)
- {
- if (fullNames[i].Contains(lastName))
- {
- Console.WriteLine("\n" + fullNames[i] + " занимает должность " + positions[i]);
- }
- else
- {
- if (i == fullNames.Length - 1)
- {
- Console.WriteLine("\nНет сотрудников с такой фамилией");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement