Sprawdzenie czy poprawnie napisane C#

0

Czy mógłby mi ktoś sprawdzić czy dobrze napisałem wzory na pola i obwody figur:prostokąt,trójkąt i elipsa.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{

    //**************************************************************************************************************

    class Punkt
    {
        // deklaracja pól
        private int x, y;
        // deklaracja właciwoci
        public int X
        {
            set { x = value; }
            get { return x; }
        }

        public int Y
        {
            set { y = value; }
            get { return y; }
        }
        // deklaracja metod
        public void Przesun(int xp, int yp)
        {
            x = +xp;
            y = +yp;
        }
        // deklaracja konstruktorów
        public Punkt()
        {
            x = 1;
            y = 1;
        }

        public Punkt(int x, int y)
        {
            this.x = x;
            this.y = y;
        }

    }

    //**************************************************************************************************************

    class Trojkat
    {
        private Punkt pA;
        private Punkt pC;
        private int gLinii;

        public Trojkat()
        {
            pA = new Punkt(10, 10);
            pC = new Punkt(100, 100);
            gLinii = 1;
        }

        public Trojkat(Punkt pA, Punkt pC, int gLinii)
        {
            this.pA = pA;
            this.pC = pC;
            this.gLinii = gLinii;
        }

        public Punkt PA
        {
            set { this.pA = value; }
            get { return this.pA; }
        }

        public Punkt PC
        {
            set { this.pC = value; }
            get { return this.pC; }
        }

        public Punkt Glinii
        {
            set { this.Glinii = value; }
            get { return this.Glinii; }
        }

        public void Przesun(int xp, int yp)
        {
            pA.Przesun(xp, yp);
            pC.Przesun(xp, yp);
        }

        public double ObliczPole()
        {
            return (Math.Abs(pC.X - pA.X) * Math.Abs(pC.Y - pA.Y)) / 2;
        }

        public double ObliczObwod()
        {
            return 2 * (Math.Sqrt(Math.Pow(Math.Abs(pC.X - pA.X) / 2, 2) + Math.Pow(Math.Abs(pC.Y - pA.Y), 2)) + Math.Abs(pC.X - pA.X) / 2 + Math.Abs(pC.Y - pA.Y));
        }
    }

    //**************************************************************************************************************


    class Elipsa
    {
        private Punkt pA;
        private Punkt pC;
        private int gLinii;

        public Elipsa()
        {
            pA = new Punkt(10, 10);
            pC = new Punkt(100, 100);
            gLinii = 1;
        }

        public Elipsa(Punkt pA, Punkt pC, int gLinii)
        {
            this.pA = pA;
            this.pC = pC;
            this.gLinii = gLinii;
        }

        public Punkt PA
        {
            set { this.pA = value; }
            get { return this.pA; }
        }

        public Punkt PC
        {
            set { this.pC = value; }
            get { return this.pC; }
        }

        public Punkt Glinii
        {
            set { this.Glinii = value; }
            get { return this.Glinii; }
        }

        public void Przesun(int xp, int yp)
        {
            pA.Przesun(xp, yp);
            pC.Przesun(xp, yp);
        }

        public double ObliczPole()
        {
            return Math.PI * Math.Abs((pC.X - pA.X) / 2) * Math.Abs((pC.Y - pA.Y) / 2);
        }

        public double ObliczObwod()
        {
            return Math.PI * (3 / 2 * (Math.Abs((pC.X - pA.X) / 2) + Math.Abs((pC.Y - pA.Y) / 2) - Math.Sqrt(Math.Abs((pC.X - pA.X) / 2) * Math.Abs((pC.Y - pA.Y) / 2))));
        }
    }

    //**************************************************************************************************************

    class Prostokat
    {
        private Punkt pA;
        private Punkt pC;
        private int gLinii;

        public Prostokat()
        {
            pA = new Punkt(10, 10);
            pC = new Punkt(100, 100);
            gLinii = 1;
        }

        public Prostokat(Punkt pA, Punkt pC, int gLinii)
        {
            this.pA = pA;
            this.pC = pC;
            this.gLinii = gLinii;
        }

        public Punkt PA
        {
            set { this.pA = value; }
            get { return this.pA; }
        }

        public Punkt PC
        {
            set { this.pC = value; }
            get { return this.pC; }
        }

        public Punkt Glinii
        {
            set { this.Glinii = value; }
            get { return this.Glinii; }
        }


        //metody
        public void Przesun(int xp, int yp)
        {
            pA.Przesun(xp, yp);
            pC.Przesun(xp, yp);
        }

        public double ObliczPole()
        {
            return Math.Abs(pC.X - pA.X) * Math.Abs(pC.Y - pA.Y);
        }

        public double ObliczObwod()
        {
            return (Math.Abs(pC.X - pA.X) * Math.Abs(pA.Y - pC.Y)) / 2;
        }
    }

    //**************************************************************************************************************

    class Program
    {
        static void Main(string[] args)
        {


            Console.ReadLine();
        }
    }
}
3

9 lat temu byłby może dobry, ale teraz mamy C# 5.0, a nie 2.0, więc nie ma potrzeby pisania pól do każdej właściwości.

0

Zastanów się które elementy są wspólne dla każdej figury. Następnie stwórz klasę np. Obiekt/Figura etc. która będzie posiadać te pola. Następnie jak masz taką figurę np. trójkąt to użyj dziedziczenia z tej klasy bazowej i zrób odpowiednie implementacje (np. wzoru na obwód)

0

Cały szkielet programu był już wcześniej zrobiony.Wykładowca kazał nam tylko w domu powstawiać funkcje liczące pola i obwody figur.

1 użytkowników online, w tym zalogowanych: 0, gości: 1