这个C#程序怎么写(修改)给三个点,构成三角形,求周长和面积
这是求三角形周长和面积的先建项目再建类usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;using...
这是求三角形周长和面积的
先建项目再建类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Line theLine = new Line();
theLine.Point = new Point();
thetrangle.Trangle = new Trangle ();
Console.WriteLine("请输入pointA的坐标:");
Point pointA = new Point();
string input = Console.ReadLine();
pointA.x = double.Parse(input);
input = Console.ReadLine();
pointA.y = double.Parse(input);
Console.WriteLine("请输入pointB的坐标:");
Point pointB = new Point();
string input = Console.ReadLine();
pointB.x = double.Parse(input);
input = Console.ReadLine();
pointB.y = double.Parse(input);
Console.WriteLine("请输入pointC的坐标:");
Point pointC = new Point();
string input = Console.ReadLine();
pointC.x = double.Parse(input);
input = Console.ReadLine();
pointC.y = double.Parse(input);
Console.Write("该三角形的周长为c={0}\t", theLine.GetLine);
if(Trangle==-1 )
Console.WriteLine("该三条边不能构成三角形。");
else
Console.WriteLine("该三角形面积s={0}", thetrangle.Trangle );
}
}
}这是program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetLine
{
class line
{
public Point x;
public Point y;
public double GetLength()
{
int a = Math.Sqrt(Math.Pow((this.PointC.x - this.PointB.x), 2) + Math.Pow((this.PointC.y - this.PointB.y), 2));
int b = Math.Sqrt(Math.Pow((this.PointC.x - this.PointA.x), 2) + Math.Pow((this.PointC.y - this.PointA.y), 2));
int c = Math.Sqrt(Math.Pow((this.PointB.x - this.PointA.x), 2) + Math.Pow((this.PointB.y - this.PointA.y), 2));
return a+b+c;
}
}
}这是 line.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetPoint
{
class Point
{
public int PointA, PointB, PointC;
}
}这是point.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Trangle
{
class trangle
{
public double p,s;
if ( )
{
p=(1.0/2)/(a+b+c);
s=Math.Sqrt(p*(p-a)*(p-b)*(p-c));
return s;
}
else
return -1;
}
}这是trangle.cs
这是本人写的一个大概,可是在trangle.cs里应该要有返回值,我不知道该怎么跟program.cs联系起来,求高手帮忙,修改
point.cs是要给出三个点,line.cs是要求出三角形的周长,trangle.cs是否能构成三角形,有返回值,program.cs是主函数,line.cs,trangle.cs,program.cs不知道该如何写,能联系起来 展开
先建项目再建类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Line theLine = new Line();
theLine.Point = new Point();
thetrangle.Trangle = new Trangle ();
Console.WriteLine("请输入pointA的坐标:");
Point pointA = new Point();
string input = Console.ReadLine();
pointA.x = double.Parse(input);
input = Console.ReadLine();
pointA.y = double.Parse(input);
Console.WriteLine("请输入pointB的坐标:");
Point pointB = new Point();
string input = Console.ReadLine();
pointB.x = double.Parse(input);
input = Console.ReadLine();
pointB.y = double.Parse(input);
Console.WriteLine("请输入pointC的坐标:");
Point pointC = new Point();
string input = Console.ReadLine();
pointC.x = double.Parse(input);
input = Console.ReadLine();
pointC.y = double.Parse(input);
Console.Write("该三角形的周长为c={0}\t", theLine.GetLine);
if(Trangle==-1 )
Console.WriteLine("该三条边不能构成三角形。");
else
Console.WriteLine("该三角形面积s={0}", thetrangle.Trangle );
}
}
}这是program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetLine
{
class line
{
public Point x;
public Point y;
public double GetLength()
{
int a = Math.Sqrt(Math.Pow((this.PointC.x - this.PointB.x), 2) + Math.Pow((this.PointC.y - this.PointB.y), 2));
int b = Math.Sqrt(Math.Pow((this.PointC.x - this.PointA.x), 2) + Math.Pow((this.PointC.y - this.PointA.y), 2));
int c = Math.Sqrt(Math.Pow((this.PointB.x - this.PointA.x), 2) + Math.Pow((this.PointB.y - this.PointA.y), 2));
return a+b+c;
}
}
}这是 line.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GetPoint
{
class Point
{
public int PointA, PointB, PointC;
}
}这是point.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Trangle
{
class trangle
{
public double p,s;
if ( )
{
p=(1.0/2)/(a+b+c);
s=Math.Sqrt(p*(p-a)*(p-b)*(p-c));
return s;
}
else
return -1;
}
}这是trangle.cs
这是本人写的一个大概,可是在trangle.cs里应该要有返回值,我不知道该怎么跟program.cs联系起来,求高手帮忙,修改
point.cs是要给出三个点,line.cs是要求出三角形的周长,trangle.cs是否能构成三角形,有返回值,program.cs是主函数,line.cs,trangle.cs,program.cs不知道该如何写,能联系起来 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询