예제 #1
0
 /// <summary>Write ArithmeticProgression to DataOutput</summary>
 /// <exception cref="System.IO.IOException"/>
 private static void Write(ArithmeticProgression ap, DataOutput @out)
 {
     @out.WriteChar(ap.symbol);
     @out.WriteLong(ap.value);
     @out.WriteLong(ap.delta);
     @out.WriteLong(ap.limit);
 }
예제 #2
0
파일: Program.cs 프로젝트: JabJabovich/labs
        static void Main(string[] args)
        {
            Console.WriteLine("Введите первый член арифметической прогрессии и ее разность: ");
            Console.Write("a = ");
            int a = int.Parse(Console.ReadLine());

            Console.Write("d = ");
            int d = int.Parse(Console.ReadLine());

            Console.WriteLine("Введите номер желаемого члена прогрессии:");
            int k = int.Parse(Console.ReadLine());
            ArithmeticProgression arith = new ArithmeticProgression(a, d);

            Console.WriteLine("Желаемый член прогрессии равен {0}", arith.GetElement(k));

            Console.WriteLine("Введите первый член геометрической прогрессии и ее делитель: ");
            Console.Write("b = ");
            int b = int.Parse(Console.ReadLine());

            Console.Write("q = ");
            int q = int.Parse(Console.ReadLine());

            Console.WriteLine("Введите номер желаемого члена прогрессии:");
            k = int.Parse(Console.ReadLine());
            GeometricProgression geom = new GeometricProgression(b, q);

            Console.WriteLine("Желаемый член прогрессии равен {0}", geom.GetElement(k));
        }
예제 #3
0
파일: Program.cs 프로젝트: xviksos/ICS-8
        // Шаблонный метод — это поведенческий паттерн проектирования, который определяет скелет алгоритма,
        // перекладывая ответственность за некоторые его шаги на подклассы. Паттерн позволяет подклассам переопределять шаги алгоритма, не меняя его общей структуры.
        private static void Main(string[] args)
        {
            Console.Write("First = ");
            var first = int.Parse(Console.ReadLine());

            Console.Write("Last = ");
            var last = int.Parse(Console.ReadLine());

            Console.Write("Delta = ");
            var delta = int.Parse(Console.ReadLine());

            var arithmetic = new ArithmeticProgression(first, last, delta);

            arithmetic.TemplateMethod();

            var geom = new GeometricProgression(first, last, delta);

            geom.TemplateMethod();

            Console.WriteLine();

            //Drink
            var maj = new beautiful();

            maj.Make();

            Console.WriteLine();

            var poc = new bald();

            poc.Make();
        }
예제 #4
0
        static void Main(string[] args)
        {
            Progression val = new ArithmeticProgression(1, 20, 3);

            val.TemplateMethod();
            Progression geom = new GeometricProgression(1, 100, 3);

            geom.TemplateMethod();
        }
예제 #5
0
        public void ArithmeticProgression()
        {
            var ap = new ArithmeticProgression
            {
                CommonDifference = 4,
                InitialTerm      = 2
            };

            Assert.AreEqual(ap.NTerm(5), 18);
        }
예제 #6
0
        static void Main(string[] args)
        {
            Publisher publ1 = new Publisher("Издательство 1", "*****@*****.**", 123, new DateTime(2015, 10, 17));
            Book      b1    = new Book("Пушкин А.С.", "Капитанская дочка", publ1, 123, 2018, 567, true);

            Publisher publ2 = new Publisher("Наука и жизнь", "*****@*****.**", 1234, new DateTime(2014, 12, 14));
            Book      b2    = new Book("Толстой Л.Н.", "Война и мир", publ2, 1234, 2013, 101, true);

            Publisher publ3 = new Publisher("Издательство 3", "*****@*****.**", 12345, new DateTime(2016, 09, 13));
            Book      b3    = new Book("Ф.М.Достоевский", "Преступление и наказание", publ3, 400, 2012, 444, false);

            Audit.RunAudit();
            Magazine mag1 = new Magazine("О природе", 5, "Земля и мы", 2014, 1235, true);

            //mag1.TakeItem();
            //mag1.Print();
            mag1.Subs();
            //mag1.Print();
            Magazine mag2 = new Magazine("О науке", 7, "Под микроскопом", 2012, 3000, true);

            Audit.StopAudit();
            mag2.Subs();

            List <Item> itlist = new List <Item>();

            itlist.AddRange(new Item[] { b1, b2, b3, mag1, mag2 });
            itlist.Sort();
            Console.WriteLine("\nСортировка по инвентарному номеру");
            foreach (Item x in itlist)
            {
                x.Print();
            }
            //it = mag1;
            //it.TakeItem();
            //it.Return();
            //it.Print();

            //Item item1 = new Item();
            //item1.Print();


            Console.WriteLine("Вычисление элемента прогрессий:\n");
            ArithmeticProgression ap = new ArithmeticProgression(5, 10);
            GeometricProgression  gp = new GeometricProgression(2, 2);

            Console.WriteLine("Введите индекс:");
            int    k   = int.Parse(Console.ReadLine());
            double ap1 = ap.GetElement(k);
            double gp1 = gp.GetElement(k);

            Console.WriteLine("Элемент арифметической прогрессии с индексом {0} равен {1}\n" +
                              "Элемент геометрической прогрессии с индексом {2} равен {3}", k, ap1, k, gp1);
        }
예제 #7
0
        /// <summary>
        /// <inheritDoc/>
        ///
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        public void ReadFields(DataInput @in)
        {
            ArithmeticProgression N = SummationWritable.ArithmeticProgressionWritable.Read(@in
                                                                                           );
            ArithmeticProgression E = SummationWritable.ArithmeticProgressionWritable.Read(@in
                                                                                           );

            sigma = new Summation(N, E);
            if (@in.ReadBoolean())
            {
                sigma.SetValue(@in.ReadDouble());
            }
        }
예제 #8
0
        public void TestMethod1()
        {
            int[,,] arraySequence = new int[2, 2, 3] {
                { { 1, 3, 3 }, { 2, 1, 2 } },
                { { 1, 2, 3 }, { 4, 3, 2 } }
            };

            int[] expected = new int [] { 12, 5, 9, 11 };
            ArithmeticProgression CalculateProgression = new ArithmeticProgression();

            int[] result = CalculateProgression.progression(arraySequence);

            CollectionAssert.AreEqual(expected, result);
        }
예제 #9
0
        private static void RunArithmeticProgression()
        {
            PrintHeader("Arithmetic Progression Operations");
            var startPoint       = ReadDoubleParameterFromConsole("startPoint");
            var step             = ReadDoubleParameterFromConsole("step");
            var numberOfElements = ReadDoubleParameterFromConsole("n");
            var progression      = new ArithmeticProgression(startPoint, step);
            var certainElement   = progression.FindNElementOfProgression(numberOfElements);

            Console.WriteLine($"N element of progression is: {certainElement}");
            var sumOfFirstNElements = progression.FindSumOfFirstNElements(numberOfElements);

            Console.WriteLine($"Sum of first n elements is: {sumOfFirstNElements}");
            var averageOfFirstNElements = progression.FindAverageOfFirstNElements(numberOfElements);

            Console.WriteLine($"Average of first n elements is: {averageOfFirstNElements}");
            PrintWait();
        }
예제 #10
0
파일: Program.cs 프로젝트: mvngr/lab
        static void Main(string[] args)
        {/*
          * Gamer g1 = new Gamer("Niko");
          * for (int i = 1; i <= 6; i++)
          *     Console.WriteLine("Выпало количество очков {0} для игрока {1}", g1.SeansGame(), g1.ToString());
          */
            ArithmeticProgression ap = new ArithmeticProgression();

            Console.WriteLine("{0}", ap.GetElement(3));
            Console.WriteLine("{0}", ap.GetElement(3, 2, 2));

            GeometricProgression gp = new GeometricProgression();

            Console.WriteLine("{0}", gp.GetElement(8));
            Console.WriteLine("{0}", gp.GetElement(1, 10, 2));

            Console.ReadKey();
        }
예제 #11
0
    static void Main()
    {
        int a1, d, n;

        int[] a;
        int   num, sum, n1, n2;

        Console.Write("Enter a first number: a1 = ");
        a1 = int.Parse(Console.ReadLine());
        Console.Write("Enter a difference: d = ");
        d = int.Parse(Console.ReadLine());
        Console.Write("Enter an amount: n = ");
        n = int.Parse(Console.ReadLine());

        // 1
        //ArithmeticProgression.PrintAmountElements(a1, d, n);

        // 2
        //num = ArithmeticProgression.NumberOf_an(a1, d, n);
        //Console.WriteLine("The num is: a[" + n + "] = " + num );

        // 3
        //sum = ArithmeticProgression.SumOfProgression(a1, d, n);
        //Console.WriteLine("The sum of arithmetic progression is: " + sum);

        // 4
        //Console.Write("Enter n1: ");
        //n1 = int.Parse(Console.ReadLine());
        //Console.Write("Enter n2: ");
        //n2 = int.Parse(Console.ReadLine());
        //Console.WriteLine("Numbers of between n1-n2 is:");
        //ArithmeticProgression.NumbersIsBetween(a1, d, n1, n2);

        // 5
        //Console.Write("Enter a number of arithmetic progression: ");
        //num = int.Parse(Console.ReadLine());
        //Console.WriteLine("The index number of: " + num + " is: " + ArithmeticProgression.IndexOfNuber(a1, d, num));

        // 6
        Console.WriteLine("num " + n + " is: " + ArithmeticProgression.IsFind(a1, d, n));

        Console.ReadKey();
    }
예제 #12
0
 public Iterator(ArithmeticProgression arithmeticProgression)
 {
     this.arithmeticProgression = arithmeticProgression;
     Current = arithmeticProgression.begin;
 }
        private int[] GetResultFromFindTheMissing(int[] input)
        {
            ArithmeticProgression prog = new ArithmeticProgression();

            return(prog.FindTheMissing(input));
        }
        public void AListWithNotEnoughValues_ThrowsProgressionTooSmallException()
        {
            ArithmeticProgression prog = new ArithmeticProgression();

            Assert.Throws <ArithmeticProgressionTooSmallException>(() => prog.FindTheMissing(new int[] { 1, 2 }));
        }