作者Ageis (Ageis)
看板C_Sharp
标题Re: [问题] 写程式码问题
时间Sun Jun 10 15:33:46 2012
无聊来写一下…
http://0rz.tw/DETMP
class Point
{
public double X { get; private set; }
public double Y { get; private set; }
public Point(double x, double y)
{
this.X = x;
this.Y = y;
}
}
class Line
{
public Point StartPoint { get; private set; }
public Point DestPoint { get; private set; }
public Line(Point startPoint, Point destPoint)
{
this.StartPoint = startPoint;
this.DestPoint = destPoint;
}
public double Length
{
get
{
return Math.Sqrt(Math.Pow(Math.Abs(this.DestPoint.X -
this.StartPoint.X), 2) + Math.Pow(Math.Abs(this.DestPoint.Y -
this.StartPoint.Y), 2));
}
}
}
abstract class AbstractShape
{
public abstract double GetArea();
public abstract double GetPerimeter();
}
class Parallelogram : AbstractShape
{
public Line Width { get; private set; }
public Line Height { get; private set; }
public Parallelogram(Line width, Line height)
{
this.Width = width;
this.Height = height;
}
public override double GetArea()
{
return this.Width.Length * this.Height.Length;
}
public override double GetPerimeter()
{
return this.Width.Length * this.Height.Length * 2;
}
}
class Program
{
static void Main(string[] args)
{
CalcShape();
Console.ReadKey();
}
private static void CalcShape()
{
Line width = new Line(new Point(0, 0), new Point(5, 0));
Line height = new Line(new Point(0, 0), new Point(0, 5));
Parallelogram parallelogram = new Parallelogram(width, height);
Console.WriteLine(parallelogram.GetArea().ToString());
Console.WriteLine(parallelogram.GetPerimeter().ToString());
}
}
其它的大同小异,你拿Class Parallelogram再改一下吧
--
◢██◣ ╮ ╭══◢◆═◢◆ ╮ ╭ ███◣════theanswer◢█ ◣
█◤ ◥ ╰══╯◆ █ █ ╰═════╯ ████ ╴◤ ◥ █▌ █
█ █◣ ◢◢◣ ◢ ◥█◣◥█◣◢█◣ ◢ ◢ █ ◢◢◣ ╱ ̄ ▄ ◢ ◤
█◣ █ █◤ █ █ █ █◢◤ █◢█ ◢ █ █◤  ̄ 3╲ ◥ ◣
◥██◤ █ ◤ █ █ ◥█◤ ◥◤█ █◣█ █ ● ∕〈
╲ █▌ █
╰═════════ ◆◤═◆◤═════◢◤═◥█◤ ═════════◥█ ◤
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.25.13.164
1F:→ advance760:你也太好心了吧...不过他会不会看不懂= = 06/12 14:20
2F:→ Ageis:没事就当练打字罗,看不懂我也没办法 :p 06/14 13:08
3F:→ susty:整个就是大好人~~~ 帅气! 06/15 10:51