Re: [問題] 寫程式碼問題
無聊來寫一下…
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
→
06/12 14:20, , 1F
06/12 14:20, 1F
→
06/14 13:08, , 2F
06/14 13:08, 2F
→
06/15 10:51, , 3F
06/15 10:51, 3F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
0
3
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章