static void Main(string[] args) { Product num1 = new Product(1.99, "Синия ручка", 100); Console.WriteLine(num1.ToString()); Flowers num2 = new Flowers(50.99, "Rose", 15, 3000); Console.WriteLine(num2.ToString()); num2.Message(); Console.WriteLine(); Clock num3 = new Clock(15.99, "Настенные часы", "Серебрянный", 3500); Console.WriteLine(num3.ToString()); num3.Message(); Console.WriteLine(); Pastry num4 = new Pastry(34, "Макарон", 200); Console.WriteLine(num4.ToString()); num4.Show(); ((ISeeAll)num4).Show(); Console.WriteLine(); Candy num5 = new Candy("Roshen", 500, 12.87); Console.WriteLine(num5.ToString()); Console.WriteLine(); Cake num6 = new Cake(20, "Наполеон", "Сгущёнка", 2000); Console.WriteLine(num6.ToString()); Console.WriteLine(num6.GetHashCode()); Console.WriteLine(num6.Equals(num5)); Console.WriteLine(); Printer Printer = new Printer(); Object[] mas = new Object[] { num1, num2, num3, num4, num5, num6 }; for (int i = 0; i < mas.Length; i++) { Console.WriteLine(Printer.IAmPrinting(mas[i])); } Console.WriteLine(); if (num6 is Cake) { Console.WriteLine("Это мой любимый торт!"); } else { Console.WriteLine("Это не торт!"); } //---------------------------6 лабораторная работа----------------------------- Console.WriteLine(); Console.WriteLine("__________________6 лабораторная__________________"); Console.WriteLine("Подарок состоит из "); foreach (object i in Podarok.GetNames(typeof(Podarok))) { Console.WriteLine(i + " "); } Console.WriteLine(); Owner owner1 = new Owner(9, "Valeria Kosilo", "BSTU"); owner1.Show(); Console.WriteLine(); Present.AddElem(num1); Present.AddElem(num2); Present.AddElem(num3); Present.AddElem(num5); Present.ShowElem(); Console.WriteLine(); Controller.CostOfPresent(); Console.WriteLine(); Controller.LessNumbOfMass(); Console.WriteLine(); Console.WriteLine("Сортировка по весу:"); Controller.Sort(); // ---------------------------7 лабораторная работа----------------------------- Console.WriteLine(); Console.WriteLine("__________________7 лабораторная__________________"); try { Product num7 = new Product(1.99, null, 100); //!!!!!!! } catch (NameException ex) { Console.WriteLine(ex.Message + "\n " + ex.TargetSite + "\n " + ex.StackTrace + "\t"); } try { Flowers num8 = new Flowers(-50.99, "Rose", 15, 3000); //!!!!!!!! } catch (PriceException ex) { Console.WriteLine(ex.Message + "\n " + ex.TargetSite + "\n " + ex.StackTrace + "\n\n"); } try { Cake num9 = new Cake(12, "Наполеон", "Сгущёнка", 1000);//!!!!!!! } catch (SaleException ex) { Console.WriteLine(ex.Message + "\n " + ex.TargetSite + "\n " + ex.StackTrace + "\n\n"); } try { int y = 6; int z = y / 0;//!!!!!!! int[] d = new int[3]; d[4] = 14;//!!!!!!! int[] aa = null; Debug.Assert(aa != null, "Массив значений не может быть null"); } catch (DivideByZeroException ex) { Console.WriteLine(ex); } catch (IndexOutOfRangeException ex) { Console.WriteLine(ex); } finally { Console.WriteLine("Конец!"); } Console.ReadKey(); }
static void Main(string[] args) { //---------------------------5 лабораторная работа----------------------------- Console.WriteLine("__________________5 лабораторная__________________"); Product num1 = new Product(1.99, "Синия ручка", 100); Console.WriteLine(num1.ToString()); Console.WriteLine(); Flowers num2 = new Flowers(50.99, "Rose", 15, 3000); Console.WriteLine(num2.ToString()); num2.Message(); Console.WriteLine(); Clock num3 = new Clock(15.99, "Настенные часы", "Серебрянный", 3500); Console.WriteLine(num3.ToString()); num3.Message(); Console.WriteLine(); Pastry num4 = new Pastry(34, "Макарон", 200); Console.WriteLine(num4.ToString()); num4.Show(); ((ISeeAll)num4).Show(); Console.WriteLine(); Candy num5 = new Candy("Roshen", 500, 12.87); Console.WriteLine(num5.ToString()); Console.WriteLine(); Cake num6 = new Cake(12, "Наполеон", "Сгущёнка", 2000); Console.WriteLine(num6.ToString()); Console.WriteLine(num6.GetHashCode()); Console.WriteLine(num6.Equals(num5)); Console.WriteLine(); Printer Printer = new Printer(); Object[] mas = new Object[] { num1, num2, num3, num4, num5, num6 }; for (int i = 0; i < mas.Length; i++) { Console.WriteLine(Printer.IAmPrinting(mas[i])); } if (num6 is Cake) { Console.WriteLine("Это мой любимый торт!"); } else { Console.WriteLine("Это не торт!"); } //---------------------------6 лабораторная работа----------------------------- Console.WriteLine(); Console.WriteLine("__________________6 лабораторная__________________"); Console.WriteLine("Подарок состоит из "); foreach (object i in Podarok.GetNames(typeof(Podarok))) { Console.WriteLine(i + " "); } Console.WriteLine(); Owner owner1 = new Owner(9, "Valeria Kosilo", "BSTU"); owner1.Show(); Console.WriteLine(); Present.AddElem(num1); Present.AddElem(num2); Present.AddElem(num3); Present.AddElem(num5); Present.ShowElem(); Console.WriteLine(); Controller.CostOfPresent(); Console.WriteLine(); Controller.LessNumbOfMass(); Console.WriteLine(); Console.WriteLine("Сортировка по весу:"); Controller.Sort(); Console.ReadKey(); }