Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace LangProgKT3
- {
- class Base
- {
- protected internal double n1;
- protected internal double n2;
- protected internal double n3;
- protected internal double n4;
- protected internal double n5;
- protected internal double n6;
- protected internal Base()
- {
- Random rnd = new Random();
- this.n1 = rnd.Next(-10, 10);
- this.n2 = rnd.Next(-10, 10);
- this.n3 = rnd.Next(-10, 10);
- this.n4 = rnd.Next(-10, 10);
- this.n5 = rnd.Next(-10, 10);
- this.n6 = rnd.Next(-10, 10);
- }
- protected internal Base(double n1, double n2, double n3, double n4, double n5, double n6)
- {
- this.n1 = n1;
- this.n2 = n2;
- this.n3 = n3;
- this.n4 = n4;
- this.n5 = n5;
- this.n6 = n6;
- }
- public override string ToString()
- {
- return n1.ToString() + " " + n2.ToString() + " " + n3.ToString() + " "+ n4.ToString() + " "+ n5.ToString() + " "+ n6.ToString() + " ";
- }
- }
- class TwoLinearRelations : Base
- {
- // return 0 - no solve
- // return 1 - one solve
- // return 2 - inf solve
- protected internal int classification()
- {
- if (this.n1 / this.n4 != this.n2 / this.n5)
- {
- return 1;
- }
- if (this.n1 / this.n4 == this.n2 / this.n5 && this.n1 / this.n4 != this.n3 / this.n6)
- {
- return 0;
- }
- if (this.n1 / this.n4 == this.n2 / this.n5 && this.n1 / this.n4 == this.n3 / this.n6)
- {
- return 2;
- }
- return 2;
- }
- protected internal void solve(ref double x, ref double y)
- {
- if(this.classification() != 1)
- {
- Console.WriteLine("no solve or inf solve");
- return;
- }
- double del = this.n1 * this.n5 - this.n4 * this.n2;
- double delX = (-this.n3) * this.n5 - (-this.n6)* this.n2;
- double delY = this.n1 *( -this.n6) - this.n4 * (-this.n3);
- x = delX / del;
- y = delY / del;
- }
- public override string ToString()
- {
- return this.n1.ToString() + "x + (" + this.n2.ToString() + ")y +(" + this.n3.ToString()+ ")=0 , " +
- this.n4.ToString() + "x + (" + this.n5.ToString() + ")y +(" + this.n6.ToString() + ")=0 ,";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- TwoLinearRelations s = new TwoLinearRelations();
- Console.Write(s);
- double x =0, y=0;
- s.solve(ref x, ref y);
- Console.WriteLine();
- Console.WriteLine("x= "+x+" y= "+y);
- Console.WriteLine();
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement