public void Delete(int ind)//удаление объектов { LIBRARY[] buff = new LIBRARY[elem.Length - 1]; for (int i = 0, y = 0; i < elem.Length; i++, y++) { if (ind < 0) { throw new DelExceptions("Удаление несуществующего элемента"); } if (i == ind) { if (i == elem.Length - 1) { break; } buff[y] = elem[i + 1]; i++; } else { buff[y] = elem[i]; } } elem = buff; }
public void Add(LIBRARY elems)//добавление объектов { LIBRARY[] buff = new LIBRARY[elem.Length + 1]; for (int i = 0; i < elem.Length; i++) { buff[i] = elem[i]; } buff[buff.Length - 1] = elems; elem = new LIBRARY[buff.Length]; for (int i = 0; i < elem.Length; i++) { elem[i] = buff[i]; } }
static void Main(string[] args) { Date day; day = Date.day; Console.WriteLine("Day: " + (int)day); Date month; month = Date.month; Console.WriteLine("Month: " + (int)month); Date year; year = Date.year; Console.WriteLine("Year: " + (int)year); Console.WriteLine(); Corporation company; company.name = "Yana"; company.corporation = "Havruchok"; company.Infooo(); Console.WriteLine(); Book book = new Book("black", "BOOOOOOK", 300); book.Name = "NNN"; book.Author = "AAA"; book.Year = 2020; book.Info(); Book book2 = new Book("white", "BOOK", 500); book2.Name = "NN"; book2.Year = 2019; book2.Info(); Journal jou = new Journal("pink", "JOOU", 600); jou.Name = "Star"; jou.Author = "Unknown"; jou.Year = 2020; jou.Info(); Tutorial tutotial = new Tutorial("yellow", "TUTS", 50); tutotial.Name = "Student"; tutotial.Author = "Belstu"; tutotial.Year = 1999; tutotial.Info(); Tutorial tutotial2 = new Tutorial("gray", "OOPs", 70); tutotial2.Name = "Labs"; tutotial2.Year = 1989; tutotial2.Info(); Console.WriteLine(); Console.WriteLine("Array"); LIBRARY[] array = new LIBRARY[] { book, book2, jou, tutotial }; for (int i = 0; i < array.Length; i++) { Console.WriteLine(array[i]); } Console.WriteLine(); Library elemFromLibrary = new Library(array); elemFromLibrary.Print(); Console.WriteLine(); elemFromLibrary.Add(tutotial2); elemFromLibrary.Print(); Console.WriteLine(); elemFromLibrary.Delete(1); elemFromLibrary.Print(); Console.WriteLine(); Controller library1 = new Controller(); library1.FindBook(elemFromLibrary.Elem); library1.Counter(elemFromLibrary.Elem); library1.Сost(elemFromLibrary.Elem); Console.WriteLine(); Console.WriteLine("LAB EXCEPTIONS"); Console.WriteLine(); try { Book bookEX = new Book("black", "BOOOOOOK", -300); } catch (CostExceptions ex) { Console.WriteLine("Error: " + ex.Message); } try { Journal jouEX = new Journal("pinks", "JOOUs", 666); jouEX.Name = "Stars"; jouEX.Author = "Unknowns"; jouEX.Year = -2020; } catch (YearExceptions ex) { Console.WriteLine("Error: " + ex.Message); } try { Tutorial tutotiaEX = new Tutorial("black", "sss", -70); tutotiaEX.Name = "TTTTT"; } catch (CostExceptionsTUT ex) { Console.WriteLine("Error: " + ex.Message); } try { Library elemFromLibrary2 = new Library(array); elemFromLibrary2.Delete(-1); } catch (DelExceptions ex) { Console.WriteLine("Error: " + ex.Message); } try { int a = 10; int b = 0; int result = a / b; } catch (DivideByZeroException ex) { Console.WriteLine("Error: " + ex.Message); } try { object p = "pups"; int pp = (int)p; } catch (InvalidCastException ex) { Console.WriteLine("Error: " + ex.Message); } finally { Console.WriteLine("Finally!"); } }