Advertisement
VladSmirN

Untitled

Dec 29th, 2021
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LangProgKT3
  8. {
  9.  
  10. class Base
  11. {
  12.  
  13. protected internal double n1;
  14. protected internal double n2;
  15. protected internal double n3;
  16. protected internal double n4;
  17. protected internal double n5;
  18. protected internal double n6;
  19. protected internal Base()
  20. {
  21. Random rnd = new Random();
  22. this.n1 = rnd.Next(-10, 10);
  23. this.n2 = rnd.Next(-10, 10);
  24. this.n3 = rnd.Next(-10, 10);
  25. this.n4 = rnd.Next(-10, 10);
  26. this.n5 = rnd.Next(-10, 10);
  27. this.n6 = rnd.Next(-10, 10);
  28. }
  29.  
  30. protected internal Base(double n1, double n2, double n3, double n4, double n5, double n6)
  31. {
  32. this.n1 = n1;
  33. this.n2 = n2;
  34. this.n3 = n3;
  35. this.n4 = n4;
  36. this.n5 = n5;
  37. this.n6 = n6;
  38. }
  39. public override string ToString()
  40. {
  41. return n1.ToString() + " " + n2.ToString() + " " + n3.ToString() + " "+ n4.ToString() + " "+ n5.ToString() + " "+ n6.ToString() + " ";
  42.  
  43. }
  44. }
  45.  
  46. class TwoLinearRelations : Base
  47. {
  48.  
  49. // return 0 - no solve
  50. // return 1 - one solve
  51. // return 2 - inf solve
  52. protected internal int classification()
  53. {
  54. if (this.n1 / this.n4 != this.n2 / this.n5)
  55. {
  56. return 1;
  57. }
  58. if (this.n1 / this.n4 == this.n2 / this.n5 && this.n1 / this.n4 != this.n3 / this.n6)
  59. {
  60. return 0;
  61. }
  62. if (this.n1 / this.n4 == this.n2 / this.n5 && this.n1 / this.n4 == this.n3 / this.n6)
  63. {
  64. return 2;
  65. }
  66. return 2;
  67. }
  68.  
  69. protected internal void solve(ref double x, ref double y)
  70. {
  71. if(this.classification() != 1)
  72. {
  73. Console.WriteLine("no solve or inf solve");
  74. return;
  75. }
  76.  
  77. double del = this.n1 * this.n5 - this.n4 * this.n2;
  78. double delX = (-this.n3) * this.n5 - (-this.n6)* this.n2;
  79. double delY = this.n1 *( -this.n6) - this.n4 * (-this.n3);
  80. x = delX / del;
  81. y = delY / del;
  82. }
  83. public override string ToString()
  84. {
  85. return this.n1.ToString() + "x + (" + this.n2.ToString() + ")y +(" + this.n3.ToString()+ ")=0 , " +
  86. this.n4.ToString() + "x + (" + this.n5.ToString() + ")y +(" + this.n6.ToString() + ")=0 ,";
  87.  
  88. }
  89. }
  90. class Program
  91. {
  92. static void Main(string[] args)
  93. {
  94. TwoLinearRelations s = new TwoLinearRelations();
  95. Console.Write(s);
  96. double x =0, y=0;
  97. s.solve(ref x, ref y);
  98. Console.WriteLine();
  99. Console.WriteLine("x= "+x+" y= "+y);
  100. Console.WriteLine();
  101. Console.ReadLine();
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement