把定义平面直角坐标系上的一个点的类CPoint作为基类,派生出描述一条直线的类Cline,再派生出一个矩形类。要求成员函数能求出两点间的距离,矩形的周长和面积。设计一个测试程序,并构造完整的程序。
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { double x1,y1,x2,y2,x3,y3; string s1, s2, s3, s4, s5, s6; Console.WriteLine("请输入两点的坐标:"); s1 = Console.ReadLine(); s2 = Console.ReadLine(); s3 = Console.ReadLine(); s4 = Console.ReadLine(); x1 = int.Parse(s1); y1 = int.Parse(s2); x2 = int.Parse(s3); y2 = int.Parse(s4); CPoint c1 = new CPoint(x1, y1); CPoint c2 = new CPoint(x2, y2); double sum; Cline l = new Cline(); sum=l.getdis(c1, c2); Console.WriteLine("两点间的距离为:" + sum); Console.WriteLine("请输入第三个点的坐标:"); s5 = Console.ReadLine(); s6 = Console.ReadLine(); x3 = int.Parse(s5); y3 = int.Parse(s6); CPoint c3=new CPoint(x3,y3); CRect cr = new CRect(); double zc = cr.getzc(c1, c2, c3); Console.WriteLine("矩形的周长为:"+zc); double area = cr.getarea(c1, c2, c3); Console.WriteLine("矩形的面积为:" + area); Console.ReadKey(); } } class CPoint { public double x, y; public CPoint() { } public CPoint(double xx, double yy) { x = xx; y = yy; } } class Cline : CPoint { public Cline() { } public Cline(CPoint c1, CPoint c2) { } public double getdis(CPoint c1, CPoint c2) { double sum; return sum = Math.Sqrt((c1.x - c2.x)*(c1.x-c2.x) + (c1.y -c2.y)*(c1.y-c2.y)); } } class CRect : Cline { public CRect() { } public double getzc(CPoint c1,CPoint c2,CPoint c3) { return 2 * (getdis(c1, c2) + getdis(c2,c3)); } public double getarea(CPoint c1, CPoint c2, CPoint c3) { return getdis(c1, c2) * getdis(c2, c3); } } }