Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.93 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 Zadania1z1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void button1_Click(object sender, EventArgs e)
  21.         {
  22.             Random rnd = new Random();
  23.             double liczbaM = double.Parse(textBox1.Text);
  24.             double liczbaZ = double.Parse(textBox2.Text);
  25.             double pomylka = 333333.333333*(liczbaZ/(double)100);
  26.             double dolnaGranica, gornaGranica;
  27.  
  28.             dolnaGranica = 333333.333333 - pomylka;
  29.             gornaGranica = 333333.333333 + pomylka;
  30.  
  31.             // metoda prostokatow
  32.             for (int j = 0; j < liczbaM; j++)
  33.             {                
  34.                 int liczbaN = rnd.Next(10, 100000);
  35.  
  36.                 double dx, calka_p, wysokosc_p = 0 , calka_t, wartosc_a = 0 , wartosc_b = 0;
  37.  
  38.                 dx = liczbaN / (double)10000;
  39.  
  40.                 calka_p = 0;
  41.                 for (double i = 0; i <= 100; i += dx)
  42.                 {
  43.                     wysokosc_p = i * i;
  44.                     calka_p += wysokosc_p * dx;
  45.                 }
  46.                 calka_p += wysokosc_p * dx;
  47.  
  48.                 if (calka_p >= dolnaGranica && calka_p <= gornaGranica)
  49.                 {
  50.                     listBox1.Items.Add(calka_p.ToString());
  51.                 }
  52.  
  53.                 calka_t = 0;                
  54.                 for (double i = 0; i <= 100; i += dx)
  55.                 {
  56.                     wartosc_b = i * i;
  57.                     calka_t += ((wartosc_a + wartosc_b) * dx) / (double)2;
  58.                     wartosc_a = wartosc_b;
  59.                 }
  60.                 calka_t += wysokosc_p * dx;
  61.  
  62.               //  if (calka_t >= dolnaGranica && calka_t <= gornaGranica)
  63.               //  {
  64.                     listBox2.Items.Add(calka_t.ToString());
  65.               //  }
  66.  
  67.  
  68.  
  69.                 //  listBox2.Items.Add(dx.ToString());                
  70.             }
  71.         }
  72.  
  73.         private void Form1_Load(object sender, EventArgs e)
  74.         {
  75.  
  76.         }
  77.     }
  78. }
  79.  
  80.  
  81.  
  82. ////////// model cs
  83.  
  84. using System;
  85. using System.Collections.Generic;
  86. using System.Linq;
  87. using System.Text;
  88. using System.Threading.Tasks;
  89.  
  90. namespace Zadania1z1
  91. {
  92.     public enum AreaType
  93.     {
  94.         Rectangle,
  95.         Trapezoid        
  96.     }
  97.  
  98.     public class SingleCount
  99.     {
  100.         public double X1 { get; set; }
  101.         public double X2 { get; set; }
  102.         public int N { get; set; }
  103.         public AreaType AreaType { get; set; }
  104.         public double Area { get; set; }
  105.         public int CalculationNumber { get; set; }
  106.         public int LowestN { get; set; }
  107.         public double MinSquareError { get; set; }
  108.  
  109.         public SingleCount() { }
  110.         public SingleCount(double x1, double x2, int n, AreaType areaType, double area, int calculationNumber)
  111.         {
  112.             this.X1 = x1;
  113.             this.X2 = x2;
  114.             this.N = n;
  115.             this.AreaType = areaType;
  116.             this.Area = area;
  117.             this.CalculationNumber = calculationNumber;
  118.  
  119.         }
  120.         public SingleCount(double x1, double x2, int n, AreaType areaType, double area, int calculationNumber, int lowestN)
  121.         {
  122.             this.X1 = x1;
  123.             this.X2 = x2;
  124.             this.N = n;
  125.             this.AreaType = areaType;
  126.             this.Area = area;
  127.             this.CalculationNumber = calculationNumber;
  128.             this.LowestN = lowestN;
  129.  
  130.         }
  131.     }
  132.  
  133.     public class Global
  134.     {
  135.         public List<SingleCount> ListOfSingleCounts { get; set; }
  136.  
  137.         public Global() { }
  138.         public Global(List<SingleCount> listOfSingleCounts)
  139.         {
  140.             this.ListOfSingleCounts = listOfSingleCounts;
  141.         }
  142.  
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement