Guest User

Untitled

a guest
Mar 15th, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.        
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         public void button1_Click(object sender, EventArgs e)
  22.         {
  23.            
  24.             float a=0, b=0; //благоприятные события а и б
  25.             float p1 = 0, p2 = 0,p3=0; //статистические вероятности
  26.             int[] Sobyt = new int[201];
  27.             Random rand = new Random();
  28.             Font font = new Font("Arial", 7);
  29.             int k = 0;
  30.             int n = 0;
  31.             int j;
  32.             int z = 0;
  33.             Point[] myPoint = new Point[20];
  34.             Point[] g2Point = new Point[20];
  35.             Point[] g3Point = new Point[20];
  36.  
  37.  
  38.             for (int i = 1; i <= 200; i++)
  39.             {
  40.                 Sobyt[i] = rand.Next(1, 12);
  41.                 listBox1.Items.Add(i + ")   " + Sobyt[i]);
  42.                 if ((Sobyt[i] == 1) || (Sobyt[i] == 2) || (Sobyt[i] == 7) || (Sobyt[i] == 8)) //благоприятное событие а
  43.                 {
  44.                     a++;
  45.                 }
  46.                 if (i%10==0)
  47.                 {
  48.                    listBox2.Items.Add(i + ")  " + a);
  49.                    p1 = a /i ;
  50.                    listBox4.Items.Add(i + ")  " + Math.Round(p1, 3));// частота события А
  51.                    p1 = p1 * 100;
  52.                    j = (Int32)p1;
  53.                    myPoint[k] = new Point(i*(3), j*(-1)*(2));
  54.                    k++;
  55.                    
  56.                 }
  57.                 if (Sobyt[i] < 7) // благоприятное событие б
  58.                 {
  59.                     b++;
  60.                 }
  61.                 if (i%10==0)
  62.                 {
  63.                    listBox3.Items.Add(i + ")  " + b);
  64.                    p2 = b / i;
  65.                    listBox5.Items.Add(i + ")  " + Math.Round(p2, 3));// частота события В
  66.                    p2 = p2 * 100;
  67.                    g2Point[n] = new Point(i*3 , (Int32)p2*(-2));
  68.                    n++;
  69.                    p3 = p1 / p2;
  70.                    listBox6.Items.Add(i + ")  " + Math.Round(p3, 2));// частота события А/В
  71.                    p3 = p3 * 100;
  72.                    g3Point[z] = new Point(i * 3, (Int32)p3 * (-2));
  73.                    z++;
  74.                 }
  75.             }
  76.             Pen myPen = new Pen(Color.Black, 1);
  77.             Graphics g = Graphics.FromHwnd(pictureBox1.Handle);
  78.             g.TranslateTransform(20, 400);
  79.             g.DrawLine(myPen, 0, 0, 0, -400);
  80.             g.DrawLine(myPen, 0, 0, 600,0);
  81.             for (int i = 30; i <= 570; i = i + 30)
  82.             {
  83.                 g.DrawLine(myPen, i, 0, i, -5);
  84.  
  85.             }
  86.             for (int i = 20; i <= 400; i = i + 20)
  87.             {
  88.                 g.DrawLine(myPen, 0, i * (-1), 5, i * (-1));
  89.             }
  90.             for (int i = 20; i <= 180; i = i + 20)
  91.             {
  92.                 g.DrawString("0." + i / 20, font, Brushes.Black, -15, i * (-1) - 5);
  93.             }
  94.             for (int i = 220; i <= 380; i = i + 20)
  95.             {
  96.                 g.DrawString("1." + ((i - 200) / 20), font, Brushes.Black, -15, i * (-1) - 5);
  97.             }
  98.             for (int i = 30; i <= 570; i = i + 30)
  99.             {
  100.                 g.DrawString("" + i / 3, font, Brushes.Black, i - 5, 0);
  101.             }
  102.             g.DrawString("1", font, Brushes.Black, -10, -205);
  103.             g.DrawString("2", font, Brushes.Black, -10, -400);
  104.             g.DrawString("200", font, Brushes.Black, 595, 0);
  105.            
  106.  
  107.            
  108.  
  109.          button1.Enabled = false;
  110.          }
  111.         private void button2_Click(object sender, EventArgs e)
  112.         {
  113.             this.Close();
  114.         }
  115.  
  116.         public void button3_Click(object sender, EventArgs e)
  117.         {
  118.  
  119.             if (radioButton1.Checked == true)
  120.             {
  121.                 for (int i = 1; i < myPoint.Count(); i++)
  122.                     g.DrawLine(myPen, myPoint[i - 1], myPoint[i]);
  123.  
  124.             }
  125.             if (radioButton2.Checked == true)
  126.             {
  127.  
  128.                 for (int i = 1; i < g2Point.Count(); i++)
  129.                     g.DrawLine(myPen, g2Point[i - 1], g2Point[i]);
  130.             }
  131.  
  132.             if (radioButton3.Checked == true)
  133.             {
  134.                 for (int i = 1; i < g2Point.Count(); i++)
  135.                     g.DrawLine(myPen, g3Point[i - 1], g3Point[i]);
  136.             }
  137.         }
  138.  
  139.  
  140.        }
  141.  
  142.     }
Advertisement
Add Comment
Please, Sign In to add comment