看板 C_Sharp 關於我們 聯絡資訊
無聊來寫一下… 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
advance760:你也太好心了吧...不過他會不會看不懂= = 06/12 14:20
Ageis:沒事就當練打字囉,看不懂我也沒辦法 :p 06/14 13:08
susty:整個就是大好人~~~ 帥氣! 06/15 10:51