コード例 #1
0
        public static Halmaz <T> operator +(Halmaz <T> a, Halmaz <T> b)
        {
            Halmaz <T> c = new Halmaz <T>();
            int        i = 0;
            int        j = 0;

            while (i < a.n && j < b.n)
            {
                int x = a.elemek[i].CompareTo(b.elemek[j]);
                if (x < 0)
                {
                    c.elemek[c.n] = a.elemek[i++];
                }
                else if (x > 0)
                {
                    c.elemek[c.n] = b.elemek[j++];
                }
                else
                {
                    c.elemek[c.n] = a.elemek[i++]; j++;
                }
                c.n++;
            }
            while (i < a.n)
            {
                c.elemek[c.n++] = a.elemek[i++];
            }
            while (j < b.n)
            {
                c.elemek[c.n++] = b.elemek[j++];
            }
            return(c);
        }
コード例 #2
0
        private void btn_rajz_Click(object sender, EventArgs e)
        {
            Bitmap   bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics g   = Graphics.FromImage(bmp);

            g.Clear(Color.CornflowerBlue);
            Pen p = new Pen(Color.Black, 2);

            g.DrawEllipse(p, 1, 1, 298, 298);
            g.DrawEllipse(p, 200, 1, 298, 298);
            g.DrawEllipse(p, 100, 150, 298, 298);
            int          maxA = (int)num_A.Value;
            int          maxB = (int)num_B.Value;
            int          maxC = (int)num_B.Value;
            Random       R    = new Random();
            Halmaz <int> A    = new Halmaz <int>();
            int          x;

            for (int i = 1; i <= maxA; i++)
            {
                do
                {
                    x = R.Next(1, 41);
                } while (A.ElemeE(x));
                A += new Halmaz <int>(x);
            }
            Halmaz <int> B = new Halmaz <int>();

            for (int i = 1; i <= maxB; i++)
            {
                do
                {
                    x = R.Next(1, 21);
                } while (B.ElemeE(x));
                B += new Halmaz <int>(x);
            }
            Halmaz <int> C = new Halmaz <int>();

            for (int i = 1; i <= maxC; i++)
            {
                do
                {
                    x = R.Next(1, 21);
                } while (C.ElemeE(x));
                C += new Halmaz <int>(x);
            }
            l_A.Text = "A = " + A.Kiir();
            l_B.Text = "B = " + B.Kiir();
            l_C.Text = "C = " + C.Kiir();
            Halmaz <int> AminuszBC  = A - B - C;
            Halmaz <int> BminuszAC  = B - A - C;
            Halmaz <int> CminuszAB  = C - B - A;
            Halmaz <int> AmetszetB  = A * B;
            Halmaz <int> BmetszetC  = B * C;
            Halmaz <int> AmetszetC  = A * C;
            Halmaz <int> AmetszetBC = A * B * C;

            SolidBrush br = new SolidBrush(Color.Black);

            g.DrawString(AminuszBC.Kiir(), l_A.Font, br, 13, 150);
            g.DrawString(AmetszetB.Kiir(), l_A.Font, br, 213, 100);
            g.DrawString(BminuszAC.Kiir(), l_A.Font, br, 323, 150);
            g.DrawString(CminuszAB.Kiir(), l_A.Font, br, 213, 350);
            g.DrawString(AmetszetC.Kiir(), l_A.Font, br, 130, 240);
            g.DrawString(BmetszetC.Kiir(), l_A.Font, br, 313, 250);
            g.DrawString(AmetszetBC.Kiir(), l_A.Font, br, 230, 200);
            pictureBox1.Image = bmp;
        }