public object Clone() //клонирование { book_store book = new book_store(title, author, genre, price, num_stock, popularity, spec_offer2, cash.get_access()); cash = (payment_cash)cash.Clone(); return(book); }
static void Main(string[] args) { int x = 0, y = 0, z = 0, n, m, profit, popularity = 1; //переменные int x2, y2; String x1, y1, z1; String s1, s2, s3; //строки int res1, res2; limited_special lim_offer1 = new limited_special(5, 6, 2); special sp_offer1 = new special(8, 4); Console.WriteLine("\nWorking with a derivative class"); Console.WriteLine("\nlim_offer1"); Console.WriteLine(lim_offer1); Console.WriteLine("\nsp_offer1\n"); Console.WriteLine(sp_offer1); Console.WriteLine("\nOverload without basic method (reducing bonus num)"); //перегрузка без вызова базового метода lim_offer1.reduce_bonus_on_num(2, 1); Console.WriteLine("\nlim_offer1\n"); Console.WriteLine(lim_offer1); Console.WriteLine("\nOverload with basic method (setting default val)"); //перегрузка с вызовом базового метода lim_offer1.set_default(); Console.WriteLine("\nlim_offer1\n"); Console.WriteLine(lim_offer1); Console.WriteLine("Working with an abstract class\n"); payment_cash cash1 = new payment_cash(1); payment_card card1 = new payment_card(2); res1 = cash1.is_accessible(); //вызов перегруженной абстрактной функции if (res1 > 0) { Console.WriteLine("Cash pay for cash1 is accessible\n"); } else { Console.WriteLine("Cash pay for cash1 is not accessible\n"); } res2 = card1.is_accessible(); //вызов перегруженной абстрактной функции if (res2 > 0) { Console.WriteLine("Card pay for card1 is accessible\n"); } else { Console.WriteLine("Card pay for card1 is not accessible\n"); } Console.WriteLine("Working with an interface (bonus num expansion)"); sp_offer1.expand_bonus_num(); //вызов метода интерфейса Console.WriteLine("\nsp_offer1\n"); Console.WriteLine(sp_offer1); lim_offer1.expand_bonus_num(); //вызов метода интерфейса Console.WriteLine("\nlim_offer1\n"); Console.WriteLine(lim_offer1); s1 = "qqq"; s2 = "aaa"; s3 = "zzz"; special spec_offer6 = new special(3, 4); book_store book6 = new book_store(s1, s2, s3, 100, 10, 15, spec_offer6, 2); s1 = "www"; s2 = "sss"; s3 = "xxx"; special spec_offer7 = new special(5, 6); book_store book7 = new book_store(s1, s2, s3, 200, 20, 25, spec_offer7, 1); Console.WriteLine("\nShallow cloning (spec_offer.bonus_num) and deep cloning (cash.is_succeed)\n"); Console.WriteLine("book6"); Console.WriteLine(book6); Console.WriteLine("book7"); Console.WriteLine(book7); book6 = (book_store)book7.Clone(); Console.WriteLine("book6"); Console.WriteLine(book6); book7.spec_offer2.change_bonus_num(10); //мелкое клонирование spec_offer (для book6 bonus_num = 10) book7.cash.change_val(3); //глубокое клонирование cash (для book6 is_succeed = 1) Console.WriteLine("book6"); Console.WriteLine(book6); Console.WriteLine("book7"); Console.WriteLine(book7); }
public int summarize(book_store book) //сложение количества двух книг { return(this.num_stock + book.num_stock); }
public static int space_left; //статическое поле отавшееся в магазине место static public int title_len(book_store book) //статический метод вычисления длины названия { return(book.title.Length); }