Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp4
- {
- class Triangle {
- double AB;
- double BC;
- double AC;
- public Triangle(Point p1, Point p2, Point p3) {
- AB = GetDist(p1, p2);
- BC = GetDist(p2, p3);
- AC = GetDist(p1, p3);
- }
- public Triangle()
- {
- AB = 1;
- BC = 1;
- AC = 1;
- }
- public double GetDist(Point p1, Point p2) {
- return Math.Pow(Math.Pow((p1.X - p2.X), 2) + Math.Pow((p1.Y - p2.Y), 2), 0.5);
- }
- public override string ToString()
- {
- return $"AB : {AB:f3}, BC : {BC:f3}, AC : {AC:f3}, периметр : {Per():f3}, площадь : {Sq():f3}";
- }
- public double Per() {
- return AB + BC + AC;
- }
- public double Sq()
- {
- double p = Per() / 2;
- return Math.Pow(((p)* (p - AB) * (p - AC) * (p - AC)), 0.5);
- }
- }
- class Point {
- double x;
- double y;
- public double X {
- get {
- return x;
- }
- }
- public double Y
- {
- get
- {
- return y;
- }
- }
- public Point(double x, double y) {
- this.x = x;
- this.y = y;
- }
- }
- class Program
- {
- static Random rnd = new Random();
- static void Sort(ref Triangle[] arr) {
- for (int i = 0; i < arr.Length; i++) {
- for (int j = i; j < arr.Length; j++) {
- if (arr[i].Sq() < arr[j].Sq()) {
- Triangle t = arr[j];
- arr[j] = arr[i];
- arr[i] = t;
- }
- }
- }
- }
- static void Main()
- {
- do
- {
- int N = rnd.Next(5, 16);
- Console.WriteLine($"Количество элементов в массиве : {N}");
- Triangle[] arr = new Triangle[N];
- double max_Sq = -1;
- for (int i = 0; i < N; i++)
- {
- 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)));
- Console.WriteLine(arr[i]);
- if (arr[i].Sq() > max_Sq)
- max_Sq = arr[i].Sq();
- }
- Console.WriteLine("Отсортированный массив:");
- Sort(ref arr);
- for (int i = 0; i < N; i++) {
- Console.WriteLine(arr[i]);
- }
- } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement