static void Search2(Airport[] ob1, Airport[] ob2) { int j = 0; //int ii = 1; int chek = 0; Airport[] sum = new Airport[ob1.Length + ob2.Length]; for (int i = 0; i < sum.Length; i++) { if (i < ob1.Length) sum[i] = ob1[i]; else { sum[i] = ob2[j]; j++; } } Console.WriteLine("Enter time in the format hour:minute "); DateTime time = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine("Enter arrival/departure port: "); int f_p = int.Parse(Console.ReadLine()); foreach(Airport z in sum) { if (z.port == f_p) { if (((z.dt.Hour - time.Hour == -1) & (z.dt.Minute - time.Minute >= 0)) | ((z.dt.Hour - time.Hour == 1) & (z.dt.Minute - time.Minute <= 0)) | ((z.dt.Hour - time.Hour == 0) & (Math.Abs(z.dt.Minute - time.Minute) <= 60))) { chek++; } } } if (chek == 0) Console.WriteLine("Not found"); Airport[] copy1 = new Airport[chek]; Airport[] copy = new Airport[1]; for (int z = 0; z < sum.Length ; z++ ) { if (sum[z].port == f_p) { if (((sum[z].dt.Hour - time.Hour == -1) & (sum[z].dt.Minute - time.Minute >= 0)) | ((sum[z].dt.Hour - time.Hour == 1) & (sum[z].dt.Minute - time.Minute <= 0)) | ((sum[z].dt.Hour - time.Hour == 0) & (Math.Abs(sum[z].dt.Minute - time.Minute) <= 60))) { copy1[z] = sum[z]; } } } for (int i = 0; i < copy1.Length; i++) { for (int h = 1; h < copy1.Length; h++) { if (copy1[h - 1].dt.Hour > copy1[h].dt.Hour) { copy[0] = copy1[h]; copy1[h] = copy1[h - 1]; copy1[h - 1] = copy[0]; } } } for (int v = 0; v < copy1.Length; v++ ) { copy1[v].show(); } }
static void Main(string[] args) { int num_a = 0; int num_d = 0; int ar = 0; int de = 0; Airport[] arrivals = new Airport[num_a]; Airport[] departures = new Airport[num_d]; int action; do { Console.WriteLine(@"Select the action : 1. Create the flight; 2. Edit the flight; 3. Delete the flight; 4. Sourch - flight number - time of arrival - arrival/departure port; 5. Sourch flight which is the nearest (1 hour); 6. Emergency information; 7. Exit; "); action = int.Parse(Console.ReadLine()); switch (action) { case 1: Console.WriteLine("Chouse 1 if you wont create arrive flight and 2 for departe flight"); int choise = int.Parse(Console.ReadLine()); switch (choise) { case 1: Airport[] copy = new Airport[num_a + 1]; copy = arrivals; arrivals = new Airport[++num_a]; for (int j = 0; j < copy.Length; j++) { arrivals[j] = copy[j]; } arrivals[ar].create(); ar++; break; case 2: Airport[] copy1 = new Airport[num_d + 1]; copy1 = departures; departures = new Airport[++num_d]; for (int j = 0; j < copy1.Length; j++) { departures[j] = copy1[j]; } departures[de].create(); de++; break; } break; case 2: if (num_a ==0 & num_d == 0) { Console.WriteLine("You need to create first"); break; } Console.WriteLine(" Chouse 1 if you wont edit arrive flight and 2 for departe flight"); int choise1 = int.Parse(Console.ReadLine()); switch (choise1) { case 1: int ii = 1; for (int j = 0; j < arrivals.Length; j++) { Console.ForegroundColor = (ConsoleColor)ii; Console.WriteLine("Number: " + (j + 1)); arrivals[j].show(); ii++; if (ii == 15) ii = 1; } Console.ResetColor(); Console.WriteLine("Enter the number:"); int k = int.Parse(Console.ReadLine()); k = k - 1; arrivals[k].create(); break; case 2: int iii = 1; for (int j = 0; j < departures.Length; j++) { Console.ForegroundColor = (ConsoleColor)iii; Console.WriteLine("Number: " + (j + 1)); departures[j].show(); iii++; if (iii == 15) iii = 1; } Console.ResetColor(); Console.WriteLine("Enter the number:"); int d = int.Parse(Console.ReadLine()); d = d - 1; departures[d].create(); break; } break; case 3: if (num_a == 0 & num_d == 0) { Console.WriteLine("Create first"); break; } Console.WriteLine(" Chouse 1 if you wont delete arrive flight and 2 for departe flight"); int choise2 = int.Parse(Console.ReadLine()); if (num_a == 1 & choise2 == 1) { Console.WriteLine("Done"); num_a -= 1; ar--; arrivals = new Airport[num_a]; break; } else if (num_d == 1 & choise2 == 2) { Console.WriteLine("Done"); num_d -= 1; de--; departures = new Airport[num_d]; break; } switch (choise2) { case 1: int ii = 1; for (int j = 0; j < arrivals.Length; j++) { Console.ForegroundColor = (ConsoleColor)ii; Console.WriteLine("Number: " + (j + 1)); arrivals[j].show(); ii++; if (ii == 15) ii = 1; } Console.ResetColor(); Console.WriteLine("Enter the number:"); int k = int.Parse(Console.ReadLine()); Airport[] copy = new Airport[num_a - 1]; int c = 0; for (int j = 0; j < arrivals.Length; j++) { if (j != (k - 1)) { copy[c] = arrivals[j]; c++; } } ar--; arrivals = new Airport[--num_a]; arrivals = copy; break; case 2: int iii = 1; for (int j = 0; j < departures.Length ; j++) { Console.ForegroundColor = (ConsoleColor)iii; Console.WriteLine("Number: " + (j + 1)); departures[j].show(); iii++; if (iii == 15) iii = 1; } Console.ResetColor(); Console.WriteLine("Enter the number:"); int n = int.Parse(Console.ReadLine()); Airport[] copy1 = new Airport[num_d - 1]; int d = 0; for (int j = 0; j < departures.Length; j++) { if (j != (n - 1)) { copy1[d] = departures[j]; d++; } } de--; departures = new Airport[--num_d]; departures = copy1; break; } break; case 4: Search1(arrivals, departures); Console.WriteLine(""); break; case 5: Search2(arrivals, departures); Console.WriteLine(""); break; case 6: emergency(); Console.WriteLine(""); break; case 7: break; } Console.WriteLine("Press Spacebar to exit; press any key to continue"); } while (Console.ReadKey().Key != ConsoleKey.Spacebar); }
static void Search1(Airport[] ob1, Airport[] ob2) { int j = 0; Airport[] sum = new Airport[ob1.Length + ob2.Length]; for (int i = 0; i < sum.Length; i++) { if (i < ob1.Length) sum[i] = ob1[i]; else { sum[i] = ob2[j]; j++; } } Console.WriteLine(@"Choose the search parametrs: 1. Search by the flight number; 2. Search by the time of arrival; 3. Search by the arrival/departure port;"); int number = int.Parse(Console.ReadLine()); switch (number) { case 1: Console.WriteLine("Enter flight number: "); int f_n = int.Parse(Console.ReadLine()); int ii = 1; int k = 0; for (int i = 0; i < sum.Length; i++) { Console.ForegroundColor = (ConsoleColor)ii; if (f_n == sum[i].flight_number) { sum[i].show(); k++; } ii++; if (ii == 15) ii = 1; } Console.ResetColor(); if (k == 0) Console.WriteLine("Not found"); break; case 2: Console.WriteLine("Enter time arrivel in the format hour:minute "); DateTime time = Convert.ToDateTime(Console.ReadLine()); int iiii = 1; int t = 0; for (int i = 0; i < ob1.Length; i++) { Console.ForegroundColor = (ConsoleColor)iiii; if (time.Hour == ob1[i].dt.Hour & time.Minute == ob1[i].dt.Minute) { ob1[i].show(); t++; } iiii++; if (iiii == 15) iiii = 1; } Console.ResetColor(); if (t == 0) Console.WriteLine("Not found"); break; case 3: Console.WriteLine("Enter arrival/departure port: "); int f_p = int.Parse(Console.ReadLine()); int iii = 1; int k1 = 0; for (int i = 0; i < sum.Length; i++) { Console.ForegroundColor = (ConsoleColor)iii; if (f_p == sum[i].port) { sum[i].show(); k1++; } iii++; if (iii == 15) iii = 1; } Console.ResetColor(); if (k1 == 0) Console.WriteLine("Not found"); break; } }