作者rn940111 (派大星)
看板C_Sharp
标题[问题] 写程式码问题
时间Sat Jun 9 01:27:50 2012
小弟这学期开始学C#
这是某一次的作业
但是我想了很久想不出来QQ
写一支 console 程式将梯形、平行四边形、矩形与正方形实体化,并印出:
梯形的高、平行边之和(即上底+下底)、面积;
平行四边形的底、高、面积;
矩形的长、宽、面积;
正方形的边长、面积。
Quadrilateral
public class Point
{
public double X { get; private set; }
public double Y { get; private set; }
public Point( double xCoordinate, double yCoordinate )
{
X = xCoordinate;
Y = yCoordinate;
}
public override string ToString()
{
return string.Format( "( {0:F1}, {1:F1} )", X, Y );
}
}
public class Quadrilateral
{
public Point Point1 { get; private set; }
public Point Point2 { get; private set; }
public Point Point3 { get; private set; }
public Point Point4 { get; private set; }
public Quadrilateral( double x1, double y1, double x2, double y2, double x3,
double y3,
double x4, double y4 )
{
Point1 = new Point( x1, y1 );
Point2 = new Point( x2, y2 );
Point3 = new Point( x3, y3 );
Point4 = new Point( x4, y4 );
}
public override string ToString()
{
return string.Format( "Coordinates of Quadrilateral are:\n{0}",
GetCoordinatesAsString() );
}
public string GetCoordinatesAsString()
{
return string.Format( "{0}, {1}, {2}, {3}\n", Point1, Point2, Point3, Point4
);
}
}
Subclasses
public class Trapezoid : Quadrilateral
{
public double GetHeight()
{}
public double GetArea()
{}
public double GetSumOfTwoSides()
{}
}
public class Parallelogram : Trapezoid
{
public double GetWidth()
{}
}
public class Rectangle : Parallelogram
{}
public class Square : Parallelogram
{}
可以帮解的话感激不尽
--
1F:推 jacksunexe:乾!你们有没有把我说的听进去啦O______Q|||我想说的是 05/31 00:45
2F:推 Alisonmanson:やらないか? 05/31 00:46
3F:→ jacksunexe:不要把这件事变成系与系之间的斗争…谁都不想遇到这种 05/31 00:46
4F:推 ijd:花电信 05/31 00:46
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.119.194.5