Guest User

Untitled

a guest
Dec 9th, 2019
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. delegate void Function(float[] mas);
  2. class Test1
  3. {
  4.  
  5. static void f1(float[] mas)//прямая
  6. {
  7. Random r = new Random();
  8. mas = new float[2];
  9. for (int i = 0; i < 2; i++)
  10. mas[i] = (float)r.Next(10);
  11.  
  12. }
  13. static void f2(float[] mas)
  14. {
  15. Random r = new Random();
  16. mas = new float[3];
  17. for (int i = 0; i < 2; i++)
  18. mas[i] = (float)r.Next(10);
  19. }
  20. static void f3(float[] mas)
  21. {
  22. Random r = new Random();
  23. mas = new float[2];
  24. for (int i = 0; i < 2; i++)
  25. mas[i] = (float)r.Next(10);
  26. }
  27.  
  28.  
  29. }
  30.  
  31. delegate float Solution(float[] mas);
  32. class Test2
  33. {
  34. float a, b;
  35.  
  36.  
  37. public float A
  38. {
  39. set { a = value; }
  40. get
  41. {
  42. return a;
  43. }
  44. }
  45. public float B
  46. {
  47. set { b = value; }
  48. get
  49. {
  50. return b;
  51. }
  52. }
  53. public static float zhaz(float[] mas, float y)
  54. {
  55. float x = 0, p = 1;
  56. for (int i = 0; i < mas.Length; i++)
  57. {
  58. x += mas[i] * p;
  59. p *= y;
  60. }
  61. return x;
  62. }
  63.  
  64. static float f1(float[] mas)
  65. {
  66. float a = 1, b = 2;
  67. while (Math.Abs(a + b) > 0.001)
  68. {
  69. if (zhaz(mas, (b + a) / 2) > 0)
  70. b = zhaz(mas, (b + a) / 2);
  71. else
  72. a = zhaz(mas, (b + a) / 2);
  73. }
  74. return a;
  75. }
  76. static float f2(float[] mas) { return 0; }
  77. static float f3(float[] mas) { return 0; }
  78. }
  79.  
  80. static void Main(string[] args)
  81. {
  82. Function f;
  83. Console.WriteLine("1-ax+b, 2- ax^2+bx+c, 3-ax^3+bx^2+cx+d ");
  84. int a = int.Parse(Console.ReadLine());
  85. switch (a)
  86. {
  87. case 1: f = new Function(Program.Test1.f1()); break;
  88. case 2: f = new Function(Program.Test1.f2()); break;
  89. case 3: f = new Function(Program.Test1.f3()); break;
  90.  
  91. }
  92.  
  93. Solution s;
  94. Console.WriteLine("1- Отрезки, 2- Хорды, 3- Касательные");
  95. a = int.Parse(Console.ReadLine());
  96. switch (a)
  97. {
  98. case 1: f = new Solution(Program.Test1.f1()); break;
  99. case 2: f = new Solution(Program.Test1.f2()); break;
  100. case 3: f = new Solution(Program.Test1.f3()); break;
  101.  
  102. }
  103.  
  104. Console.ReadKey();
  105. }
  106. }
  107. }
RAW Paste Data