Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp4
  4. {
  5.     class Triangle {
  6.         double AB;
  7.         double BC;
  8.         double AC;
  9.         public Triangle(Point p1, Point p2, Point p3) {
  10.             AB = GetDist(p1, p2);
  11.             BC = GetDist(p2, p3);
  12.             AC = GetDist(p1, p3);
  13.         }
  14.         public Triangle()
  15.         {
  16.             AB = 1;
  17.             BC = 1;
  18.             AC = 1;
  19.         }
  20.        
  21.         public double GetDist(Point p1, Point p2) {
  22.             return Math.Pow(Math.Pow((p1.X - p2.X), 2) + Math.Pow((p1.Y - p2.Y), 2), 0.5);
  23.         }
  24.         public override string ToString()
  25.         {
  26.             return $"AB : {AB:f3}, BC : {BC:f3}, AC : {AC:f3}, периметр : {Per():f3}, площадь : {Sq():f3}";
  27.         }
  28.         public double Per() {
  29.             return AB + BC + AC;
  30.         }
  31.         public double Sq()
  32.         {
  33.             double p = Per() / 2;
  34.             return Math.Pow(((p)* (p - AB) * (p - AC) * (p - AC)), 0.5);
  35.         }
  36.     }
  37.     class Point {
  38.         double x;
  39.         double y;
  40.         public double X {
  41.             get {
  42.                 return x;
  43.             }
  44.         }
  45.         public double Y
  46.         {
  47.             get
  48.             {
  49.                 return y;
  50.             }
  51.         }
  52.         public Point(double x, double y) {
  53.             this.x = x;
  54.             this.y = y;
  55.         }
  56.        
  57.  
  58.  
  59.     }
  60.     class Program
  61.     {
  62.         static Random rnd = new Random();
  63.         static void Sort(ref Triangle[] arr) {
  64.             for (int i = 0; i < arr.Length; i++) {
  65.                 for (int j = i; j < arr.Length; j++) {
  66.                     if (arr[i].Sq() < arr[j].Sq()) {
  67.                         Triangle t = arr[j];
  68.                         arr[j] = arr[i];
  69.                         arr[i] = t;
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.  
  75.         static void Main()
  76.        
  77.         {
  78.             do
  79.             {
  80.                 int N = rnd.Next(5, 16);
  81.                 Console.WriteLine($"Количество элементов в массиве : {N}");
  82.                 Triangle[] arr = new Triangle[N];
  83.                 double max_Sq = -1;
  84.                 for (int i = 0; i < N; i++)
  85.                 {
  86.                     arr[i] = new Triangle(new Point(rnd.Next(-10, 11), rnd.Next(-10, 11)), new Point(rnd.Next(-10, 11), rnd.Next(-10, 11)), new Point(rnd.Next(-10, 11), rnd.Next(-10, 11)));
  87.                     Console.WriteLine(arr[i]);
  88.                     if (arr[i].Sq() > max_Sq)
  89.                         max_Sq = arr[i].Sq();
  90.                 }
  91.                 Console.WriteLine("Отсортированный массив:");
  92.                 Sort(ref arr);
  93.                 for (int i = 0; i < N; i++) {
  94.                     Console.WriteLine(arr[i]);
  95.                 }
  96.             } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement