Essays.club - Получите бесплатные рефераты, курсовые работы и научные статьи
Поиск

Композиція, дженеріки

Автор:   •  Август 31, 2022  •  Лабораторная работа  •  3,132 Слов (13 Страниц)  •  100 Просмотры

Страница 1 из 13

Дисципліна «Об`єктно-орієнтоване программування»

Практика 2.5-2.6

“Композиція, дженеріки”

Київ-2021

[pic 1]

[pic 2]

[pic 3]

Файл Point.cs

using System;

namespace lab6

{

    class Point<T>

    {

        T x;

        T y;

       

        public T X

        {

            get

            {

                return x;

            }

        }

        public T Y

        {

            get

            {

                return y;

            }

        }

        public Point(T x, T y)

        {

            this.x = x;

            this.y = y;

        }

        public Point()

        {

            x = default(T);

            y = default(T);

        }

        public static double SideLength(Point<T> p1, Point<T> p2) => Math.Sqrt(Math.Pow(Convert.ToDouble(p2.x)-Convert.ToDouble(p1.x), 2)+Math.Pow(Convert.ToDouble(p2.y) - Convert.ToDouble(p1.y), 2));

        public static bool IsTriangle(Point<T> p1, Point<T> p2, Point<T> p3)

        {

            if (SideLength(p1, p2) + SideLength(p1, p3) > SideLength(p2, p3)

                && SideLength(p2, p3)+SideLength(p3, p1) > SideLength(p1, p2)

                && SideLength(p2, p1)+SideLength(p2, p3)>SideLength(p1, p3))

                return true;

            else

                return false;

        }

    }

}

Файл Parallelogram.cs

using System;

namespace lab6

{

    class Parallelogram

    {

        readonly Point<int> a_int;

        readonly Point<int> b_int;

        readonly Point<int> c_int;

        readonly Point<int> d_int;

        readonly Point<double> intersection_int; // Точка перетину

        public Point<int> A_int

        {

            get

            {

                return a_int;

            }

        }

        public Point<int> B_int

        {

            get

            {

                return b_int;

            }

        }

        public Point<int> C_int

        {

            get

            {

                return c_int;

            }

        }

        public Point<int> D_int

        {

            get

            {

                return d_int;

            }

        }

        public Point<double> Intersection_int

        {

            get

            {

                return intersection_int;

            }

        }

        public Parallelogram(Point<int> a_int, Point<int> b_int, Point<int> c_int)

        {

            if (Point<int>.IsTriangle(a_int, b_int, c_int))

            {

                this.a_int = a_int;

                this.b_int = b_int;

                this.c_int = c_int;

                d_int = new Point<int>(a_int.X + c_int.X - b_int.X, a_int.Y + c_int.Y - b_int.Y);

                intersection_int = new Point<double>(((double)b_int.X + (double)d_int.X) / 2, ((double)b_int.Y + (double)d_int.Y) / 2);

            }

...

Скачать:   txt (10.2 Kb)   pdf (711.7 Kb)   docx (569.5 Kb)  
Продолжить читать еще 12 страниц(ы) »
Доступно только на Essays.club