public override void buttonHandler(object sender, EventArgs e) { try { int m = validateInt("m", this.textBoxM); int z = validateInt("z", this.textBoxZ); double targetDiff = validIntegral * (z / 100.0); resultLabel.Text = ""; for (int mi = 0; mi < m; mi++) { sc.n = MarcinWieczorekMain.random.Next(10, 100000); sc.integrate(AreaType.Rectangle); if (Math.Abs(validIntegral - sc.area) < targetDiff) { resultLabel.Text += "Rectangle: " + sc.area + "\n"; } sc.integrate(AreaType.Trapezoid); if (Math.Abs(validIntegral - sc.area) < targetDiff) { resultLabel.Text += "Trapezoid: " + sc.area + "\n"; } } } catch (System.Exception) {} }
public override void buttonHandler(object sender, EventArgs e) { try { int k = validateInt("k", this.textBoxK); int z = validateInt("z", this.textBoxZ); int x1 = validateInt("x1", this.textBoxX1); int x2 = validateInt("x2", this.textBoxX2); sc.n = (int)Math.Pow(10, k); sc.x1 = x1; sc.x2 = x2; // Results will be stored here bool foundRectangle = false; bool foundTrapezoid = true; double rectangleX1 = 0, rectangleX2 = 0; double trapezoidX1 = 0, trapezoidX2 = 0; for (int i = 0; i < sc.n; i++) { sc.integrate(AreaType.Rectangle); if (Math.Truncate(sc.area) % z == 0) { rectangleX1 = sc.x1; rectangleX2 = sc.x2; foundRectangle = true; } // Trapezoid sc.integrate(AreaType.Trapezoid); if (Math.Truncate(sc.area) % z == 0) { trapezoidX1 = sc.x1; trapezoidX2 = sc.x2; foundTrapezoid = true; } if (foundRectangle && foundTrapezoid) { break; } sc.x1 += 1; sc.x2 -= 1; if (sc.x1 > x2 || sc.x2 < x1) { break; } } resultLabel.Text = "Rectangle: " + rectangleX1 + ", " + rectangleX2 + "\nTrapezoid: " + trapezoidX1 + ", " + trapezoidX2; } catch (System.Exception) {} }
public override void buttonHandler(object sender, EventArgs e) { try { int z = validateInt("z", this.textBoxZ); int x1 = validateInt("x1", this.textBoxX1); int x2 = validateInt("x2", this.textBoxX2); sc.x1 = x1; sc.x2 = x2; // Results will be stored here bool foundRectangle = false; bool foundTrapezoid = false; int rectangleN = 0; int trapezoidN = 0; while (true) { sc.n = MarcinWieczorekMain.random.Next(0, 10000); // Rectangle if (!foundRectangle) { sc.integrate(AreaType.Rectangle); if (Math.Truncate(sc.area) % z == 0) { rectangleN = sc.n; foundRectangle = true; } } // Trapezoid if (!foundTrapezoid) { sc.integrate(AreaType.Trapezoid); if (Math.Truncate(sc.area) % z == 0) { trapezoidN = sc.n; foundTrapezoid = true; } } if (foundRectangle && foundTrapezoid) { break; } } resultLabel.Text = "Rectangle: " + rectangleN + "\nTrapezoid: " + trapezoidN; } catch (System.Exception) {} }
public override void buttonHandler(object sender, EventArgs e) { try { int z = validateInt("z", this.textBoxZ); int rectangleN = 0; int trapezoidN = 0; bool foundRectangle = false; bool foundTrapezoid = false; double targetDiff = validIntegral * (z / 100.0); for (int ni = 1; ni < 100000; ni++) { sc.n = ni; if (!foundRectangle) { sc.integrate(AreaType.Rectangle); if (Math.Abs(sc.area - validIntegral) == targetDiff) { foundRectangle = true; rectangleN = sc.n; } } if (!foundTrapezoid) { sc.integrate(AreaType.Trapezoid); if (Math.Abs(sc.area - validIntegral) == targetDiff) { foundTrapezoid = true; trapezoidN = sc.n; } } if (foundRectangle && foundTrapezoid) { break; } } if (foundRectangle && foundTrapezoid) { resultLabel.Text = "Rectangle: " + rectangleN + "\nTrapezoid: " + trapezoidN; } else { resultLabel.Text = "Failed to find the result. Please change your parameters."; } } catch (System.Exception) {} }
public override void buttonHandler(object sender, EventArgs e) { try { int m = validateInt("m", this.textBoxM); int k = validateInt("k", this.textBoxK); int n = (int)Math.Pow(10, k); sc.n = n; sc2.n = n; double resultRectangle = 9999999; double resultTrapezoid = 9999999; for (int i = 0; i < m; i++) { sc.x1 = (int)MarcinWieczorekMain.random.Next(0, 100); sc.x2 = (int)MarcinWieczorekMain.random.Next(0, 100); sc2.x1 = (int)MarcinWieczorekMain.random.Next(0, 100); sc2.x2 = (int)MarcinWieczorekMain.random.Next(0, 100); sc.integrate(AreaType.Rectangle); sc2.integrate(AreaType.Rectangle); double diff = Math.Abs(sc.area - sc2.area); if (diff < resultRectangle) { resultRectangle = diff; } sc.integrate(AreaType.Trapezoid); sc2.integrate(AreaType.Trapezoid); diff = Math.Abs(sc.area - sc2.area); if (diff < resultTrapezoid) { resultTrapezoid = diff; } } resultLabel.Text = "Rectangle: " + resultRectangle + "\nTrapezoid: " + resultTrapezoid; } catch (System.Exception) {} }
public override void buttonHandler(object sender, EventArgs e) { try { int k = validateInt("k", this.textBoxK); int n = (int)Math.Pow(10, k); sc.n = n; sc2.n = n; bool foundRectangle = false; bool foundTrapezoid = false; double rectangleX1F1 = 0, rectangleX2F1 = 0; double rectangleX1F2 = 0, rectangleX2F2 = 0; double trapezoidX1F1 = 0, trapezoidX2F1 = 0; double trapezoidX1F2 = 0, trapezoidX2F2 = 0; while (true) { sc.x1 = MarcinWieczorekMain.random.Next(0, 100); sc.x2 = MarcinWieczorekMain.random.Next(0, 100); sc2.x1 = MarcinWieczorekMain.random.Next(0, 100); sc2.x2 = MarcinWieczorekMain.random.Next(0, 100); if (!foundRectangle) { sc.integrate(AreaType.Rectangle); sc2.integrate(AreaType.Rectangle); if (sc.area == sc2.area && sc.x1 != sc2.x1 && sc.x2 != sc2.x2) { foundRectangle = true; rectangleX1F1 = sc.x1; rectangleX2F1 = sc.x1; rectangleX1F2 = sc2.x2; rectangleX2F2 = sc2.x2; } } if (!foundTrapezoid) { sc.integrate(AreaType.Trapezoid); sc2.integrate(AreaType.Trapezoid); if (sc.area == sc2.area && sc.x1 != sc2.x1 && sc.x2 != sc2.x2) { foundTrapezoid = true; trapezoidX1F1 = sc.x1; trapezoidX2F1 = sc.x1; trapezoidX1F2 = sc2.x2; trapezoidX2F2 = sc2.x2; } } if (foundRectangle && foundTrapezoid) { break; } } if (foundRectangle && foundTrapezoid) { resultLabel.Text = "Rectangle f1: " + rectangleX1F1 + ", " + rectangleX2F1 + "\nRectangle f2: " + rectangleX1F2 + ", " + rectangleX2F2 + "\nTrapezoid f1: " + trapezoidX1F1 + ", " + trapezoidX2F1 + "\nTrapezoid f2: " + trapezoidX1F2 + ", " + trapezoidX2F2; } else { resultLabel.Text = "Failed to find the result. Please change your parameters."; } } catch (System.Exception) {} }