using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Triunghi
{
class punct
{
private double x, y; //campuri private, vor fi accesate prin proprietati
public double X //proprietate de acces la data privata x
{
get
{
return x;
}
set
{
x = value;
}
}
public double Y //proprietate de acces la data privata y
{
get
{
return y;
}
set
{
y = value;
}
}
public punct() //constructor
{
x = 0; y = 0;
}
public punct(double a, double b) //constructor de initializare
{
x = a; y = b;
}
public punct(punct p) //constructor de copiere
{
x = p.x; y = p.y;
}
public void citire()//citire de la tastatura
{
Console.Write("x=");
x = Int32.Parse(Console.ReadLine());
Console.Write("y=");
y = Int32.Parse(Console.ReadLine());
}
public void afis()//afisare pe ecran
{
Console.WriteLine("(" + x + "," + y+")");
}
public double dinst_la(punct b)
{
return Math.Sqrt((x - b.x) * (x - b.x) + (y - b.x) * (y - b.x));//folosesc date membru, nu proprietati
}
}
class triunghi
{
public punct a, b, c; //3 puncte
public triunghi()//constructor care foloseste constructorul de la clasa punct
{
a = new punct();
b = new punct();
c = new punct();
}
public triunghi(double x1, double y1, double x2, double y2, double x3, double y3)
{//cosntructor de initializare
a = new punct(x1,y1);
b = new punct(x2, y2);
c = new punct(x3, y3);
}
public triunghi(punct x, punct y, punct z)
{// constructor de initializare care foloseste constructorul de copiere de la clasa punct
a = new punct(x);
b = new punct(y);
c = new punct(z);
}
public void citire()// citire de la tastatura
{
a.citire(); b.citire();c.citire();
}
public void afis()// afisare pe ecran
{
a.afis(); b.afis(); c.afis();
}
private double dist(punct a, punct b)//distanta dintre 2 puncte, foloseste proprietatiel X si Y
{//privata
return Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y));
}
public double perimetru()//petrimetrul triunghiului
{
return dist(a, b) + dist(b, c) + dist(c, a);
}
public double aria()// aria triunghiului
{
double p = perimetru() / 2;
double B = dist(a, c);
double A = dist(b, c);
double C = dist(a, b);
return Math.Sqrt(p*(p-A)*(p-B)*(p-C));
}
}
class Program
{
static void Main(string[] args)
{
triunghi t = new triunghi();// apel constructor triunghi
triunghi t2 = new triunghi(1, 1, 3, 4, 0, 6);//apel constructor triunghi cu 6 valori reale
punct x, y, z;
x = new punct(0, 0);// apel constructor punct pt initializare
y = new punct(3, 6);
z = new punct(2, 1);
triunghi t3 = new triunghi(x, y, z);//apel constructor de initializare cu 3 puncte
t.citire();
t.afis();
t2.afis();
t3.afis();
Console.WriteLine(t2.perimetru());
Console.WriteLine(t2.aria());
Console.WriteLine(t3.perimetru());
Console.WriteLine(t3.aria());
Console.WriteLine(x.dinst_la(y));
Console.ReadLine();
}
}
}
|