Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

using System;

namespace domMat
{
class Program
{
static void Main(string[] args)
{
Triangle1 t = new Triangle1(3, 4, 5);
Console.WriteLine("Perimeter: {0}\nFace: {1}\n", t.Perimeter(),
t.Face());

Triangle2 t1 = new Triangle2(5, 10, 0.5);


Console.WriteLine("Perimeter: {0}\nFace: {1}\n", t1.Perimeter(),
t1.Face());
}
}
}
***********************************************************************************
*******
using System;
using System.Collections.Generic;
using System.Text;

namespace domMat
{
interface ITriangle
{
double Perimeter();
double Face();
}
}
***********************************************************************************
*******
using System;
using System.Collections.Generic;
using System.Text;

namespace domMat
{
class Triangle1 : ITriangle
{
private double a;
private double b;
private double c;
public Triangle1(int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}
public double Perimeter()
{
return a + b + c;
}
public double Face()
{
double p = this.Perimeter() / 2;
return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
}
}
}
***********************************************************************************
*******
using System;
using System.Collections.Generic;
using System.Text;

namespace domMat
{
class Triangle2 : ITriangle
{
private double a;
private double b;
private double BACangle;
public Triangle2(double a, double b,double BACangle)
{
this.a = a;
this.b = b;
this.BACangle = BACangle;
}
public double Face()
{
return a * b * Math.Sin(BACangle) / 2;
}
public double Perimeter()
{
double h = b * Math.Sin(BACangle);
double a1 = Math.Sqrt(Math.Pow(b, 2) - Math.Pow(h, 2));
double a2 = a - a1;
double c = Math.Sqrt(Math.Pow(a2, 2) + Math.Pow(h, 2));
return a + b + c;
}
}
}

You might also like