Re: [問題] 寫程式碼問題

看板C_Sharp (C#)作者 (Ageis)時間13年前 (2012/06/10 15:33), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串2/2 (看更多)
無聊來寫一下… 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
沒事就當練打字囉,看不懂我也沒辦法 :p
06/14 13:08, 2F

06/15 10:51, , 3F
整個就是大好人~~~ 帥氣!
06/15 10:51, 3F
文章代碼(AID): #1Fr4taQe (C_Sharp)
文章代碼(AID): #1Fr4taQe (C_Sharp)