Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- public class Program
- {
- public static void Main()
- {
- string[] names = new string[0];
- string[] positions = new string[0];
- string choose;
- bool isRun = true;
- while (isRun)
- {
- Console.WriteLine("\nInput number of action : ");
- Console.WriteLine("1. Add case.\n" +
- "2. Output all cases.\n" +
- "3. Remove case.\n" +
- "4. Search case on name.\n" +
- "5. Exit.");
- choose = Console.ReadLine();
- switch (choose)
- {
- case "1":
- AddCase(ref names, ref positions);
- break;
- case "2":
- OutputCases(names, positions);
- break;
- case "3":
- RemoveCase(ref names, ref positions);
- break;
- case "4":
- SearchCase(names, positions);
- break;
- case "5":
- isRun = false;
- break;
- default:
- Console.WriteLine("You write wrong number of command.");
- break;
- }
- }
- }
- public static void AddCase(ref string[] names, ref string[] positions)
- {
- string name;
- string position;
- Console.WriteLine("Input name of person : ");
- name = Console.ReadLine();
- AddElement(ref names, name);
- Console.WriteLine("Input position of person : ");
- position = Console.ReadLine();
- AddElement(ref positions, position);
- }
- public static void AddElement(ref string[] array, string element)
- {
- string[] arrayNew = new string[array.Length + 1];
- for (int i = 0; i < array.Length; ++i)
- arrayNew[i] = array[i];
- arrayNew[array.Length] = element;
- array = arrayNew;
- }
- public static void SearchCase(string[] names, string[] positions)
- {
- bool isFind = true;
- bool isFound = false;
- string input;
- Console.WriteLine("Please input name of person : ");
- input = Console.ReadLine();
- for (int i = 0; isFind && i < names.Length; ++i)
- {
- if (names[i].Equals(input))
- {
- isFound = true;
- isFind = false;
- Console.WriteLine($"{i}. {names[i]} - {positions[i]}");
- }
- }
- if (isFound == false)
- {
- Console.WriteLine("Cannot find person");
- }
- }
- public static void OutputCases(string[] names, string[] positions)
- {
- for (int i = 0; i < names.GetLength(0); ++i)
- Console.Write($"{i}. {names[i]} - {positions[i]} ");
- Console.WriteLine();
- }
- public static void RemoveCase(ref string[] names, ref string[] positions)
- {
- if (names.Length != 0)
- {
- int caseIndex = 0;
- bool isInput = true;
- while (isInput)
- {
- Console.WriteLine($"Amount of cases : {names.Length}");
- Console.WriteLine("Please type a number of case : ");
- caseIndex = Convert.ToInt32(Console.ReadLine());
- if (caseIndex >= 0 && caseIndex < names.Length)
- isInput = false;
- }
- RemoveElement(ref names, caseIndex);
- RemoveElement(ref positions, caseIndex);
- }
- }
- public static void RemoveElement(ref string[] array, int index)
- {
- string[] arrayNew = new string[array.Length - 1];
- for (int i = 0; i < index; ++i)
- arrayNew[i] = array[i];
- for (int i = index, j = index + 1; j < array.Length; ++i, ++j)
- arrayNew[i] = array[j];
- array = arrayNew;
- }
- }
Add Comment
Please, Sign In to add comment