Example #1
0
        public void Lab3Test()
        {
            var bytes = File.ReadAllBytes(@"C:\Repos\Simple_compression_algorithms\Simple_compression_algorithms\Simple_compression_algorithms\Resources\house_1.ppm");
            var ci    = new CustomImage(bytes);

            new CustomImage(Lab3.Encode(ci.Image)).Save(@"C:\Users\q1\Desktop\FreeSpace\Test\testLab3EncodeResult.ppm");
            new CustomImage(Lab3.Decode(ci.Image)).Save(@"C:\Users\q1\Desktop\FreeSpace\Test\testLab3DecodeResult.ppm");
        }
Example #2
0
        private void okButton_Click(object sender, EventArgs e)
        {
            /*scalingMethod*/
            if (scalingMethod1RadioButton.Checked)
            {
                scalingMethod = "ScalingMethod1";
            }

            if (scalingMethod2RadioButton.Checked)
            {
                scalingMethod = "ScalingMethod2";
            }

            if (ScalingMethod3RadioButton.Checked)
            {
                scalingMethod = "ScalingMethod3";
            }
            /*ExtremePixel*/
            if (duplicationRadioButton.Checked)
            {
                name = "Duplication";
            }
            if (unchangedRadioButton.Checked)
            {
                name = "Unchanged";
            }

            if (existingRadioButton.Checked)
            {
                name = "Existing";
            }
            /*Own method*/
            if (ballRadioButton.Checked)
            {
                name = "Ball";
            }
            k[1]         = Convert.ToInt32(k1TextBox.Text);
            k[2]         = Convert.ToInt32(k2TextBox.Text);
            k[3]         = Convert.ToInt32(k3TextBox.Text);
            k[4]         = Convert.ToInt32(k4TextBox.Text);
            k[5]         = Convert.ToInt32(k5TextBox.Text);
            k[6]         = Convert.ToInt32(k6TextBox.Text);
            k[7]         = Convert.ToInt32(k7TextBox.Text);
            k[8]         = Convert.ToInt32(k8TextBox.Text);
            k[9]         = Convert.ToInt32(k9TextBox.Text);
            k[0]         = k[1] + k[2] + k[3] + k[4] + k[5] + k[6] + k[7] + k[8] + k[9];
            int[,] histo = Lab3.UniversalPointOperations(openImage, name, scalingMethod, k);
            ShowResult(histo);
        }
Example #3
0
        private void okButton_Click(object sender, EventArgs e)
        {
            /*scalingMethod*/
            if (x3x3RadioButton.Checked)
            {
                maskSize = "3x3";
            }

            if (x3x5RadioButton.Checked)
            {
                maskSize = "3x5";
            }

            if (x5x3RadioButton.Checked)
            {
                maskSize = "5x3";
            }

            if (x5x5RadioButton.Checked)
            {
                maskSize = "5x5";
            }

            if (x7x7RadioButton.Checked)
            {
                maskSize = "7x7";
            }
            /*ExtremePixel*/
            if (duplicationRadioButton.Checked)
            {
                extremeName = "Duplication";
            }
            if (unchangedRadioButton.Checked)
            {
                extremeName = "Unchanged";
            }

            if (existingRadioButton.Checked)
            {
                extremeName = "Existing";
            }
            /*Own method*/
            if (ballRadioButton.Checked)
            {
                extremeName = "Ball";
            }
            int[,] histo = Lab3.UniversalMedianOperation(openImage, extremeName, maskSize);
            ShowResult(histo);
        }
Example #4
0
        static void Main(string[] args)
        {
            //Lab1
            Console.WriteLine("LAB 1");
            Lab1.RunLab1();
            Console.WriteLine("-------------------------------------------------\n");

            //Lab2
            Console.WriteLine("LAB 2");
            Lab2.RunLab2();
            Console.WriteLine("-------------------------------------------------\n");

            //Lab3
            Console.WriteLine("LAB 3");
            Lab3.RunLab3();
            Console.WriteLine("-------------------------------------------------\n");
        }
Example #5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Dock the PictureBox to the form and set its background to white.
            ModelView.Dock      = DockStyle.Fill;
            ModelView.BackColor = Color.White;
            // Connect the Paint event of the PictureBox to the event handler method.
            //System.Windows.Forms.PaintEventHandler paintEvent = new System.Windows.Forms.PaintEventHandler(ModelView_Paint);
            //ModelView.Paint += paintEvent;

            // Add the PictureBox control to the Form.
            panel1.Controls.Add(ModelView);
            ModelView.Image = new Bitmap(ModelView.Width, ModelView.Height);

            GetAxisAndGrid();
            DrawAxisAndGrid();

            lab3 = new Lab3(ModelView);
        }
Example #6
0
        private void okButton_Click(object sender, EventArgs e)
        {
            /*Mask*/
            if (k9RadioButton.Checked)
            {
                method = "1/9";
            }

            if (k10RadioButton.Checked)
            {
                method = "1/10";
            }

            if (k16RadioButton.Checked)
            {
                method = "1/16";
            }
            /*ExtremePixel*/
            if (duplicationRadioButton.Checked)
            {
                name = "Duplication";
            }
            if (unchangedRadioButton.Checked)
            {
                name = "Unchanged";
            }

            if (existingRadioButton.Checked)
            {
                name = "Existing";
            }
            /*Own method*/
            if (ballRadioButton.Checked)
            {
                name = "Ball";
            }
            int[,] histo = Lab3.LinearFiltration3x3(openImage, name, method);
            ShowResult(histo);
        }
Example #7
0
            static private Lab3[][] PassOrFail(Lab3[] data)
            {
                Lab3[][] divided = new Lab3[2][];
                var      pass    = new List <Lab3>();
                var      fail    = new List <Lab3>();

                foreach (Lab3 obj in data)
                {
                    //pass if data.res_avg >= 5.0
                    if (obj.result >= 5.0)
                    {
                        pass.Add(obj);
                    }
                    //fail res < 5.0
                    else
                    {
                        fail.Add(obj);
                    }
                }
                divided[0] = pass.ToArray();
                divided[1] = fail.ToArray();
                return(divided);
            }
Example #8
0
        public async Task <ActionResult <string> > FindResult([FromBody] Lab3 model)
        {
            try
            {
                var automat = _mapper.GetAutomatDTO(model.Automat);

                var result = await _worker.GetResultAsync(automat, model.Length);

                var key = KeyGenerator.RandomString();

                while (_tempValues.ContainsKey(key))
                {
                    key = KeyGenerator.RandomString();
                }

                _tempValues.Add(key, result);

                return(Ok("\"" + key + "\""));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #9
0
        public Vector Start()
        {
            int k = 1;

            Vector X1 = _X0;

            List <Vector> P = new List <Vector>(); // Направления

            for (int i = 0; i < count; i++)
            {
                Vector tempV = new Vector(this.count);
                tempV.NullInit();
                tempV.ch[i] = 1;
                P.Add(tempV);
            }
            P.Add(P[0]); // Теперь имеем {e1, e2...e1};


            double alpha;
            Lab3   labs;

            Vector curX = X1; Vector X2 = X1;


            while (true)
            {
                Console.WriteLine("X1: " + X1.printVector());
                curX = X1; X2 = X1;


                // Совершаем n поисков
                for (int i = 0; i < P.Count; i++)
                {
                    labs = new Lab3();

                    alpha = labs.Start(this._func, curX, P[i], this._eps); // Находим вектор


                    curX = labs.Point(curX, alpha); // Перходим в новую точку

                    if (i == 0)
                    {
                        X2 = curX;         // Если точка X2
                    }
                }


                Vector dk = curX - X2; // Находим вектор
                //curX = X4;

                if (k >= this.count - 1)
                {
                    labs  = new Lab3();
                    alpha = labs.Start(this._func, curX, dk, this._eps);

                    curX = labs.Point(curX, alpha);

                    return(curX);
                }
                else
                {
                    P.RemoveAt(0); // Первый сдвигается
                    P[0] = dk;
                    P.Add(dk);

                    X1 = curX;
                    k++;
                }
            }
        }
Example #10
0
 private void btnDecode_Click(object sender, EventArgs e)
 {
     pcbResult.Image       = Lab3.Decode(pcbOriginal.Image as Bitmap);
     btnChange.Visible     = true;
     btnSaveResult.Visible = true;
 }
Example #11
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            double interval = 0;
            double a = 0;
            double b = 0;
            try{
                a = Double.Parse(aTextBox.Text);
                b = Double.Parse(bTextBox.Text);
                interval = Double.Parse(intervalLab3TextBox.Text);

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            Lab3 lab3 = new Lab3(a, b, interval);
            var solution = lab3.Solve();
            var result = solution.Select(s => new { X = s.Key, Y = s.Value });
            lab3ResultDataGrid.ItemsSource = result;
        }
Example #12
0
        public void Run()
        {
            Position = new List <Vector>();


            Vector[] A = new Vector[this._count];
            Vector[] B = new Vector[this._count];
            Vector[] d = new Vector[this._count];


            Vector[] P = new Vector[this._count];
            for (int i = 0; i < this._count; i++)
            {
                P[i] = new Vector(this._count);
                P[i].NullInit();
                P[i].ch[i] = 1;
            }

            int  iter = 0;
            Lab3 lab3;

            do
            {
                Vector curX = _X0;
                Position.Add(_X0);

                Vector alpha = new Vector(this._count); alpha.NullInit();

                Vector tempX = curX;

                for (int i = 0; i < this._count; i++)
                {
                    lab3        = null;
                    lab3        = new Lab3();
                    alpha.ch[i] = lab3.Start(this._func, tempX, P[i], _eps);
                    tempX       = lab3.Point(tempX, alpha.ch[i]);
                    Position.Add(tempX);
                }

                curX = tempX;

                if (alpha.Norm() <= this._eps)
                {
                    break;
                }
                else
                {
                    for (int i = 0; i < this._count; i++)
                    {
                        if (Math.Abs(alpha.ch[i]) <= this._eps)
                        {
                            A[i] = P[i];
                        }
                        else
                        {
                            Vector tempV = new Vector(this._count);
                            tempV.NullInit();

                            for (int k = i; k < this._count; k++)
                            {
                                tempV += alpha.ch[k] * P[k];
                            }
                            A[i] = tempV;
                        }



                        if (i == 0)
                        {
                            B[i] = A[i];
                        }
                        else
                        {
                            Vector tempV = new Vector(this._count); tempV.NullInit();
                            for (int k = 0; k < i; k++)
                            {
                                tempV += (A[i] * d[k]) * d[k];
                            }
                            B[i] = A[i] - tempV;
                        }

                        d[i] = B[i];
                        d[i].Normilize();

                        P[i] = d[i];
                    }

                    _X0 = curX;

                    iter++; if (iter >= 30)
                    {
                        break;
                    }
                }
            } while (true);

            ResultVector = this._X0;
            _count       = iter;
        }
Example #13
0
        private void okButton_Click(object sender, EventArgs e)
        {
            /*scalingMethod*/
            if (scalingMethod1RadioButton.Checked)
            {
                scalingMethod = "ScalingMethod1";
            }

            if (scalingMethod2RadioButton.Checked)
            {
                scalingMethod = "ScalingMethod2";
            }

            if (ScalingMethod3RadioButton.Checked)
            {
                scalingMethod = "ScalingMethod3";
            }
            /*ExtremePixel*/
            if (duplicationRadioButton.Checked)
            {
                name = "Duplication";
            }
            if (unchangedRadioButton.Checked)
            {
                name = "Unchanged";
            }

            if (existingRadioButton.Checked)
            {
                name = "Existing";
            }
            /*Own method*/
            if (ballRadioButton.Checked)
            {
                name = "Ball";
            }
            /*Sharpering method*/
            if (laplacianMask1RadioButton.Checked)
            {
                sharperingMethod = "LaplacianMask1";
            }
            if (laplacianMask2RadioButton.Checked)
            {
                sharperingMethod = "LaplacianMask2";
            }
            if (laplacianMask3RadioButton.Checked)
            {
                sharperingMethod = "LaplacianMask3";
            }
            if (laplacianMask4RadioButton.Checked)
            {
                sharperingMethod = "LaplacianMask4";
            }
            if (laplacianMask5RadioButton.Checked)
            {
                sharperingMethod = "LaplacianMask5";
            }
            if (edgeDetectionMask1RadioButton.Checked)
            {
                sharperingMethod = "EdgeDetectionMask1";
            }
            if (edgeDetectionMask2RadioButton.Checked)
            {
                sharperingMethod = "EdgeDetectionMask2";
            }
            if (edgeDetectionMask3RadioButton.Checked)
            {
                sharperingMethod = "EdgeDetectionMask3";
            }
            int[,] histo = Lab3.Sharpering(openImage, name, sharperingMethod, scalingMethod);
            ShowResult(histo);
        }
Example #14
0
        public Vector Start()
        {
            Parser temp = new Parser();
            int    k    = 1;

            Vector X1 = _X0;

            List <Vector> P = new List <Vector>(); // Направления

            for (int i = 0; i < count; i++)
            {
                Vector tempV = new Vector(this.count);
                tempV.NullInit();
                tempV.ch[i] = 1;
                P.Add(tempV);
            }

            double alpha = 0;
            Lab3   labs;

            Vector curX  = X1;
            Vector tempX = X1;

            double a, b;

            while (true)
            {
                List <double> A = new List <double>(); // Сохраняет альфы
                List <double> M = new List <double>(); // Сохраняет М
                List <double> Y = new List <double>(); // Значения функции в точке

                curX = X1;

                Y.Add(Convert.ToDouble(temp.Parse(this._func, curX.ch)));

                Position.Add(curX);

                for (int i = 0; i < P.Count; i++)
                {
                    tempX = curX;
                    labs  = new Lab3();
                    alpha = labs.Start(this._func, curX, P[i], this._eps); // Находим вектор
                    curX  = labs.Point(curX, alpha);                       // Перходим в новую точку
                    Position.Add(curX);
                    Y.Add(Convert.ToDouble(temp.Parse(this._func, curX.ch)));

                    A.Add(alpha);

                    a = Convert.ToDouble(temp.Parse(this._func, tempX.ch));
                    b = Convert.ToDouble(temp.Parse(this._func, curX.ch));

                    M.Add(a - b);
                }

                tempX = curX;

                Vector dk = curX - X1; // Находим вектор
                dk.Normilize();

                labs  = new Lab3();
                alpha = labs.Start(this._func, curX, dk, this._eps); // Ищем щё один вектор
                curX  = labs.Point(curX, alpha);                     // Переходим в точку X(n+2);
                Position.Add(curX);


                if ((alpha <= _eps) && ((Math.Abs(Y.Last() - Y[0]) / Y.Last())) <= this._eps)
                {
                    break;
                }
                else
                {
                    X1 = curX;
                    k++;

                    if (k >= 25)
                    {
                        break;
                    }

                    int mmax = GetMaxIndex(M);

                    a = Convert.ToDouble(temp.Parse(this._func, tempX.ch));
                    b = Convert.ToDouble(temp.Parse(this._func, curX.ch));
                    M.Add(a - b);
                    A.Add(alpha);
                    Y.Add(Convert.ToDouble(temp.Parse(this._func, curX.ch)));


                    if (uslzv(M, Y, mmax) == true)
                    {
                        P.RemoveAt(mmax);
                    }
                    else
                    {
                        P.RemoveAt(0);
                    }

                    P.Add(dk);
                }
            }

            this._count    = k;
            this.MinVector = curX;
            return(curX);
        }
Example #15
0
        public Vector Start()
        {
            int k = 1;

            Vector X1 = _X0;

            List <Vector> P = new List <Vector>(); // Направления

            for (int i = 0; i < count; i++)
            {
                Vector tempV = new Vector(this.count);
                tempV.NullInit();
                tempV.ch[i] = 1;
                P.Add(tempV);
            }

            double alpha = 0;
            Lab3   labs;

            Vector curX = X1; Vector X2 = X1;

            while (true)
            {
                curX = X1;
                Console.WriteLine("Итерация: " + k);
                Console.Write("Стартовая точка: " + curX.printVector());
                Console.WriteLine("Векторы P:");
                for (int i = 0; i < P.Count; i++)
                {
                    Console.Write("P" + i + P[i].printVector());
                }
                Console.WriteLine();

                Console.WriteLine("Начинаем поиски");
                // Совершаем n поисков
                for (int i = 0; i < P.Count; i++)
                {
                    labs = new Lab3();

                    Console.Write("X = " + curX.printVector());
                    Console.Write("P = " + P[i].printVector());

                    alpha = labs.Start(this._func, curX, P[i], this._eps); // Находим вектор

                    Console.WriteLine("Alpha = " + alpha);

                    curX = labs.Point(curX, alpha); // Перходим в новую точку

                    Console.Write("Новая точка: " + curX.printVector());
                }
                Console.WriteLine();
                Console.WriteLine("Находим Dk");
                Console.Write("CurX: " + curX.printVector());
                Console.Write("X1 - " + X1.printVector());


                Vector dk = curX - X1; // Находим вектор

                Console.Write("DK = " + dk.printVector());

                //curX = X1;
                Console.WriteLine();
                Console.WriteLine("Переход в точку 4");

                labs = new Lab3();
                Console.Write("CurX - " + curX.printVector());
                Console.Write("P - " + dk.printVector());

                alpha = labs.Start(this._func, curX, dk, this._eps); // Ищем щё один вектор

                Console.WriteLine("Alpha = " + alpha);

                curX = labs.Point(curX, alpha); // Переходим в точку X(n+2);

                Console.WriteLine("Переход в нову точку: " + curX.printVector());

                if (k >= count)
                {
                    break;
                }
                else
                {
                    k++;
                    X1 = curX;

                    P.RemoveAt(0);
                    P.Add(dk);

                    Console.WriteLine();
                    Console.WriteLine("_________________");
                    Console.WriteLine();
                }
            }

            Console.WriteLine("Минимум: " + curX.printVector());
            return(curX);
        }
Example #16
0
        public Vector Start()
        {
            Vector[] A = new Vector[this._count];
            Vector[] B = new Vector[this._count];
            Vector[] d = new Vector[this._count];


            // Задаём вектор направлений
            Vector[] P = new Vector[this._count];
            for (int i = 0; i < this._count; i++)
            {
                P[i] = new Vector(this._count);
                P[i].NullInit();
                P[i].ch[i] = 1;
            }

            int  count = 0;
            Lab3 labs;

            do
            {
                Console.WriteLine("Итерация: " + count);
                Vector curX = _X0;

                /*Console.WriteLine();
                 * Console.WriteLine();
                 * Console.WriteLine("_________________________________");
                 * Console.WriteLine();
                 * Console.WriteLine();
                 *
                 *
                 * Console.WriteLine("Векторы P: ");
                 * for (int i = 0; i < this._count; i++) Console.Write("P" + i + P[i].printVector());*/

                Vector alpha = new Vector(this._count); alpha.NullInit();

                Vector tempX = curX;
                // Console.Write("Вектор X до цпс: " + curX.printVector());

                for (int i = 0; i < this._count; i++)
                {
                    //Console.Write("Func = " + this._func + " TempX = " + tempX.printVector() + "P = " + P[i].printVector());
                    labs        = null;
                    labs        = new Lab3();
                    alpha.ch[i] = labs.Start(this._func, tempX, P[i], _eps); // Запоминаем альфа
                    tempX       = labs.Point(tempX, alpha.ch[i]);            // Переходим в след точку???
                    //Console.WriteLine("    Новый вектор" + i + tempX.printVector());
                }

                curX = tempX;

                /*Console.Write("Вектор X после цпс " + curX.printVector());
                 *
                 * Console.WriteLine();
                 * Console.Write("Alpha: " + alpha.printVector());*/

                //Console.ReadLine();

                if (curX.Norm() <= this._eps)
                {
                    break;
                }
                else
                {
                    for (int i = 0; i < this._count; i++)
                    {
                        if (Math.Abs(alpha.ch[i]) <= this._eps)
                        {
                            A[i] = P[i];
                        }
                        else
                        {
                            Vector tempV = new Vector(this._count);
                            tempV.NullInit();

                            for (int k = i; k < this._count; k++)
                            {
                                tempV += alpha.ch[k] * P[k];
                            }
                            A[i] = tempV;
                        }

                        if (i == 0)
                        {
                            B[i] = A[i];
                        }
                        else
                        {
                            Vector tempV = new Vector(this._count); tempV.NullInit();
                            for (int k = 0; k < i; k++)
                            {
                                tempV += (A[i] * d[k]) * d[k];
                            }
                            B[i] = A[i] - tempV;
                        }

                        d[i] = B[i];
                        d[i].Normilize();
                    }
                }

                for (int i = 0; i < this._count; i++)
                {
                    P[i] = d[i];
                }

                _X0 = curX;

                count++; if (count >= 15)
                {
                    break;
                }
            } while (true);

            return(this._X0);
        }
Example #17
0
            static void Main(string[] args)
            {
                //default size of list
                int sizeOfList = 1000;

                Console.WriteLine("Choose the size of student list from the list below(default is 1000 size)↓");
                Console.WriteLine("\t1 - 1000" +
                                  "\n\t2 - 10000" +
                                  "\n\t3 - 100000" +
                                  "\n\t4 - 1000000" +
                                  "\n\t5 - 10000000");
                Console.Write("Your choice = ");
                try {
                    int choice = Int32.Parse(Console.ReadLine());
                    switch (choice)
                    {
                    case 1:
                        sizeOfList = 1000;
                        break;

                    case 2:
                        sizeOfList = 10000;
                        break;

                    case 3:
                        sizeOfList = 100000;
                        break;

                    case 4:
                        sizeOfList = 1000000;
                        break;

                    case 5:
                        sizeOfList = 10000000;
                        break;

                    default:
                        Console.WriteLine("You input invlid value.");
                        Console.WriteLine("The size will be set 1000");
                        sizeOfList = 1000;
                        break;
                    }
                } catch (FormatException e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("Only integer values accepted");
                    Console.WriteLine("You should choose the integer from the list.");
                }

                Console.WriteLine("The list will contains {0} records", sizeOfList);

                //start timer
                var watch = System.Diagnostics.Stopwatch.StartNew();

                //variables for creating file
                Random random = new Random();

                int    in1, in2, in3, in4, in5, in6;
                String name_ = "name";
                String surname_ = "surname";
                String surname2, name2;
                String path     = @"C:\Users\reiya\OneDrive\デスクトップ\Integrated System Development\lab3\v4-";
                String fullpath = @String.Concat(path, sizeOfList.ToString(), "size.txt");

                //create student list
                using (StreamWriter sw = new StreamWriter(fullpath))
                {
                    //Generate students list;
                    for (int i = 0; i < sizeOfList; i++)
                    {
                        surname2 = string.Format("{0}{1}", surname_, i.ToString());
                        name2    = String.Concat(name_, i.ToString()); //same result with surname2
                        //random integer for 5 hw and 1 exam
                        //min - 0, max - 10
                        in1 = random.Next(11);
                        in2 = random.Next(11);
                        in3 = random.Next(11);
                        in4 = random.Next(11);
                        in5 = random.Next(11);
                        in6 = random.Next(11); //exam
                        sw.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7}", surname2, name2, in1, in2, in3, in4, in5, in6);
                    }
                }
                Console.WriteLine("Created a student file.");

                //here read txt file
                Console.WriteLine("Read student data from txt file");
                Console.WriteLine("--------------------------------------------");
                try {
                    // Read each line of the file into a string array. Each element
                    // of the array is one line of the file.
                    string[] lines = System.IO.File.ReadAllLines(fullpath);
                    //Create Data class object to store each value
                    Student        stu;
                    Student[]      stuArr  = new Student[lines.Length];
                    List <Student> stuList = new List <Student>();
                    //loop for storing splitted data
                    for (int i = 0; i < lines.Length; i++)
                    {
                        string[] words = lines[i].Split(' ');
                        stuArr[i] = new Student(words);
                        stuList.Add(new Student(words));
                    }

                    //final result calculation
                    Lab3[] finalResult = new Lab3[stuArr.Length];
                    double res_avg;
                    //Final_points = 0.3 * average_of_hw + 0.7 * exam
                    for (int i = 0; i < stuArr.Length; i++)
                    {
                        res_avg = Math.Round(0.3 * (CalculateAvg(ReturnArrInt(stuArr[i]))) + 0.7 * stuArr[i].exam, 3);
                        //without final result calculated by using midian
                        //res_mid = Math.Round(0.3 * (CalculateMid(ReturnArrInt(stuArr[i]))) + 0.7 * stuArr[i].exam, 3);

                        //finalResult[i] = new Lab3(stuArr[i].surname, stuArr[i].name, res_avg, res_mid);
                        finalResult[i] = new Lab3(stuArr[i].surname, stuArr[i].name, res_avg);
                    }

                    //pass the sorted result to the func which divides into 2 groups - pass, fail
                    // and it returns lab3[][]
                    // Lab3[0][] - students who passed
                    // Lab3[1][] - stidents who failed
                    Lab3[][] pass_fail       = PassOrFail(SortObjects(finalResult));
                    int      pass_arr_length = pass_fail[0].Length;
                    int      fail_arr_length = pass_fail[1].Length;
                    //declare 2 arrays of Lab3 object with the length of pass_fail[]
                    Lab3[] pass = new Lab3[pass_arr_length];
                    Lab3[] fail = new Lab3 [fail_arr_length];
                    for (int i = 0; i < pass.Length; i++)
                    {
                        pass[i] = pass_fail[0][i];
                    }
                    for (int i = 0; i < fail.Length; i++)
                    {
                        fail[i] = pass_fail[1][i];
                    }
                    //here write the result into 2 separated file.
                    //declare file pass
                    String pass_file = @"C:\Users\reiya\OneDrive\デスクトップ\Integrated System Development\lab3\v4-pass.txt";
                    String fail_file = @"C:\Users\reiya\OneDrive\デスクトップ\Integrated System Development\lab3\v4-fail.txt";
                    //exception handler
                    if (pass.Length == null)
                    {
                        Console.WriteLine("All students failed exam.");
                        Console.WriteLine("Students list is sorted by NAME.");
                        WriteResultToFile(fail, fail_file);
                        Console.WriteLine("FAIL Students list has been published.");
                    }
                    else if (fail.Length == null)
                    {
                        Console.WriteLine("All students passed exam.");
                        Console.WriteLine("Students list is sorted by NAME.");
                        WriteResultToFile(pass, pass_file);
                        Console.WriteLine("PASS Students list has been published.");
                    }
                    else if (pass.Length == null && fail.Length == null)
                    {
                        Console.WriteLine("The program has an error. Please contact the admin");
                    }
                    else
                    {
                        Console.WriteLine("Students list is sorted by NAME.");
                        WriteResultToFile(fail, fail_file);
                        Console.WriteLine("FAIL Students list has been published.");
                        WriteResultToFile(pass, pass_file);
                        Console.WriteLine("PASS Students list has been published.");
                    }
                    Console.WriteLine("Completed Version0.4 !");
                }
                catch (FileNotFoundException e) {
                    Console.WriteLine("Please check the file exist and file name pass is correct.");
                }
                //the code that you want to measure comes here
                watch.Stop();
                String path_time     = @"C:\Users\reiya\OneDrive\デスクトップ\Integrated System Development\lab3\v4-time-";
                String fullpath_time = @String.Concat(path_time, sizeOfList.ToString(), "size.txt");

                using (StreamWriter sw = new StreamWriter(fullpath_time)) {
                    sw.WriteLine("The execution time of {0} size list = {1} ms", sizeOfList, watch.ElapsedMilliseconds);
                }

                Console.WriteLine("Press any key to exit.");
                System.Console.ReadKey();
            }
Example #18
0
        public Vector Start()
        {
            int k = 1;

            Vector X1 = _X0;

            List <Vector> P = new List <Vector>(); // Направления

            for (int i = 0; i < count; i++)
            {
                Vector tempV = new Vector(this.count);
                tempV.NullInit();
                tempV.ch[i] = 1;
                P.Add(tempV);
            }

            double alpha = 0;
            Lab3   labs;

            Vector curX = X1; Vector X2 = X1;

            while (true)
            {
                curX = X1;

                Position.Add(curX);

                for (int i = 0; i < P.Count; i++)
                {
                    Console.Write("P" + i + P[i].printVector());
                }
                for (int i = 0; i < P.Count; i++)
                {
                    labs  = new Lab3();
                    alpha = labs.Start(this._func, curX, P[i], this._eps); // Находим вектор
                    curX  = labs.Point(curX, alpha);                       // Перходим в новую точку
                    Position.Add(curX);
                }


                Vector dk = curX - X1; // Находим вектор

                labs  = new Lab3();
                alpha = labs.Start(this._func, curX, dk, this._eps); // Ищем щё один вектор
                curX  = labs.Point(curX, alpha);                     // Переходим в точку X(n+2);
                Position.Add(curX);

                if (k >= count)
                {
                    break;
                }
                else
                {
                    k++;
                    X1 = curX;

                    P.RemoveAt(0);
                    P.Add(dk);
                }
            }

            this._count    = k;
            this.MinVector = curX;
            return(curX);
        }
Example #19
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Введите номер лабораторной работы (1 - 8, 10; 0 - для выхода из приложения)");
                switch (Console.ReadLine())
                {
                case "0":
                {
                    Console.WriteLine("Завершить работу приложения? (y/n)");
                    while (true)
                    {
                        switch (Console.ReadLine())
                        {
                        case "y":
                            return;

                        case "n":
                            break;

                        default: continue;
                        }
                        break;
                    }
                    break;
                }

                case "1":
                {
                    Console.WriteLine("Лабораторная работа #1\n" +
                                      "Выбор задания:\n" +
                                      "1. Даны x, y, z . Вычислить a, если...\n" +
                                      "2. Вычислить площадь треугольника по всем известным формулам");
                    switch (Console.ReadLine())
                    {
                    case "1": { Lab1.RunTask1(); break; }

                    case "2": { Lab1.RunTask2(); break; }

                    default: break;
                    }
                    break;
                }

                case "2":
                {
                    Console.WriteLine("Лабораторная работа #2");
                    Lab2.RunTask1();
                    break;
                }

                case "3":
                {
                    Console.WriteLine("Лабораторная работа #3\n" +
                                      "Выбор задания:\n" +
                                      "1. Натуральное число p делится нацело на натуральное число q\n" +
                                      "2. Составить программу для вычисления функции");
                    switch (Console.ReadLine())
                    {
                    case "1": { Lab3.RunTask1(); break; }

                    case "2": { Lab3.RunTask2(); break; }
                    }
                    break;
                }

                case "4":
                {
                    Console.WriteLine("Лабораторная работа #4");
                    Lab4.RunTask1();
                    break;
                }

                case "5":
                {
                    Console.WriteLine("Лабораторная работа #5\n" +
                                      "Выбор задания:\n" +
                                      "1. Поиск минимального элемента из трех элементов\n" +
                                      "2. Найти сумму ряда при заданном n\n" +
                                      "3. Найти сумму бесконечного ряда при заданном eps\n" +
                                      "4. Дано натуральное число. Определить сколько раз в нем встречается цифра а");
                    switch (Console.ReadLine())
                    {
                    case "1": { Lab5.RunTask1(); break; }

                    case "2": { Lab5.RunTask2(); break; }

                    case "3": { Lab5.RunTask3(); break; }

                    case "4": { Lab5.RunTask4(); break; }
                    }
                    break;
                }

                case "6":
                {
                    Console.WriteLine("Лабораторная работа #6\n" +
                                      "Выбор задания:\n" +
                                      "1. Нахождение минимального и максимального элементов заданной последователь-ности чисел.\n" +
                                      "Вывести на экран значения и порядковые номера искомых элементов\n" +
                                      "2. Программа для ввода/вывода в массив данных с различной длинной записей");
                    switch (Console.ReadLine())
                    {
                    case "1": { Lab6.RunTask1(); break; }

                    case "2": { Lab6.RunTask2(); break; }
                    }
                    break;
                }

                case "7":
                {
                    Console.WriteLine("Лабораторная работа #7\n" +
                                      "Выбор задания:\n" +
                                      "1. Подсчет суммарного числа букв 'а' и букв 'b' в заданной строковой переменной. Вывести на экран каких букв больше\n" +
                                      "2. Поиск подстроки в заданной строке. В случае нахождения заданной подстроки необходимо удалить ее.");
                    switch (Console.ReadLine())
                    {
                    case "1": { Lab7.RunTask1(); break; }

                    case "2": { Lab7.RunTask2(); break; }
                    }
                    break;
                }

                case "8":
                {
                    Console.WriteLine("Лабораторная работа #8\n" +
                                      "Даны действительные числа a, b. Получить u = min(a, b-a), y = min(ab, a+b), k = min(u + v2, 3.14)");
                    Lab8.RunTask1();
                    break;
                }

                case "10":
                {
                    Console.WriteLine("Лабораторная работа #10");
                    Lab10.RunTask();
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
        }