Ejemplo n.º 1
0
        public static special operator +(special spec_offer, int a)            //перегрузка + постфиксная
        {
            special spec_offer1;

            spec_offer1           = new special();
            spec_offer1.bonus_num = spec_offer.bonus_num + a;
            return(spec_offer1);
        }
Ejemplo n.º 2
0
        public static special operator +(int a, special spec_offer)            //перегрузка + префиксная
        {
            special spec_offer1;

            spec_offer1           = new special();
            spec_offer1.bonus_num = a + spec_offer.bonus_num;
            return(spec_offer1);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            int    x, y, z, n, profit, popularity = 1;                 //переменные
            String s1, s2, s3;                                         //строки

            Console.WriteLine("Input information about the 1 book\n"); //ввод информации о книге
            Console.WriteLine("Input number of specials: ");
            n = Convert.ToInt32(Console.ReadLine());
            special[] spec_offer1 = new special[10];
            special[] spec_offer2 = new special[10];
            for (int i = 0; i < n; i++)
            {
                spec_offer1[i] = new special();
                spec_offer2[i] = new special();
            }
            Console.WriteLine("Input title: ");
            s1 = Console.ReadLine();
            Console.WriteLine("Input author: ");
            s2 = Console.ReadLine();
            Console.WriteLine("Input genre: ");
            s3 = Console.ReadLine();
            Console.WriteLine("Input price: ");
            x = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Input number in stock: ");
            y = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Input popularity: ");
            z = Convert.ToInt32(Console.ReadLine());
            book_store book1 = new book_store(s1, s2, s3, x, y, z, n, spec_offer1);

            book1.output();
            book_store book2 = new book_store(spec_offer2);

            book2.Title      = "www";        //установка значений с помощью сеттера
            book2.Author     = "sss";
            book2.Genre      = "xxx";
            book2.Price      = 200;
            book2.Num_stock  = 20;
            book2.Popularity = 25;
            Console.WriteLine("\nSecond book (setter used)");
            book2.output();
            Console.WriteLine("\nNumber in stock of 1 and 2: {0}", book1.summarize(book2));                          //сложение количетва двух книг
            String book_genre = book1.Genre;                                                                         //получение значения геттером

            Console.WriteLine("First book genre is {0}, str length of genre is {1}", book_genre, book_genre.Length); //вычисление длины строки жанр
            Console.WriteLine("\nFirst book");
            book1.output();                                                                                          //вывод
            book1.sell();                                                                                            //продажа
            book1.output();
            book1.price_rise();                                                                                      //повышение цены
            book1.output();
            book1.rearrange();                                                                                       //перестановка
            book1.output();
            book1.archivate();                                                                                       //отправка на склад
            book1.output();
            book1.reduce_bonus();                                                                                    //уменьшение количества бонусов
            book1.output();
            book1.predictable_profit(out profit);                                                                    //подсчет ожидаемой прибыли через out
            Console.WriteLine("\nPredictable profit: {0}", profit);
            book1.predictable_popularity(ref popularity);                                                            //подсчет ожидаемой популярности через ref
            Console.WriteLine("Predictable popularity: {0}", popularity);
            Console.WriteLine("First book title length is {0}", book_store.title_len(book1));                        //вывод значения длины строки названия
            book_store.space_left = 50;                                                                              //установка значения оставшегося места
            Console.WriteLine("Space left in the store {0}", book_store.space_left);
            special[] spec_offer0 = new special[1];
            special[] spec_offer3 = new special[1];
            spec_offer0[0] = new special();
            spec_offer3[0] = new special();
            Console.WriteLine($"\nDefault value of special offer = {spec_offer0[0].bonus_num}");
            spec_offer3[0] = spec_offer0[0] + 5;            //перегрузка + постфиксная
            Console.WriteLine($"\nSpecial offer + 5 = {spec_offer3[0].bonus_num}");
            spec_offer3[0] = 10 + spec_offer0[0];           //перегрузка + префиксная
            Console.WriteLine($"10 + Special offer = {spec_offer3[0].bonus_num}");
            spec_offer3[0] = spec_offer0[0]++;              //перегрузка ++ постфиксная
            Console.WriteLine($"Special offer ++ = {spec_offer3[0].bonus_num}");
            spec_offer3[0].set_default();
            spec_offer3[0] = ++spec_offer0[0];              //перегрузка ++ префиксная
            Console.WriteLine($"++ Special offer = {spec_offer3[0].bonus_num}");
            Console.WriteLine("\nMassive using constructor with a single parameter");
            special[] spec_offer4 = new special[2];
            for (int i = 0; i < 2; i++)
            {
                spec_offer4[i] = new special(10);                 //вызов конструктора с одним параметром для создания массива
            }
            Console.WriteLine("\nSpecial offers\n");
            for (int i = 0; i < 2; i++)
            {
                spec_offer4[i].output();
            }
        }