C#-—点类,直线类,矩形类之间的继承

/*烟台大学计算机学院学生      
*All right reserved.      
*文件名称:C#-—点类,直线类,矩形类之间的继承
*作者:杨飞      
*完成日期:2014年9月2日      
*版本号:v1.0      
*对任务及求解方法的描述部分:C#-—点类,直线类,矩形类之间的继承
*我的程序:*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class CPoint
    {
        private double x;
        private double y;

       public  CPoint()
        {

        }
        public CPoint(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
        public double getx()
        {
            return x;
        }
        public double gety()
        {
            return y;
        }

    
    }
    class Cline : CPoint
    {
        private CPoint p;
        public Cline()
        { 
        
        }
        public Cline(double x,double y,CPoint p1 ):base(x,y)
        {
            this.p = p1;
        }
        public double  distance()
        {

            double l;
            l = Math.Sqrt(Math.Pow(p.getx()-getx(),2)+Math.Pow(p.gety()-gety(),2));
            return l;
        }

    }
    class CRect:Cline 
   {
        private  Cline m;
        private Cline n;
        public CRect(Cline m, Cline n)
        {
            this.m = m;
            this.n = n;
        }
        public CRect()
        { 
        
        }
        public double zhouchang()
        {
            return (m.distance() + n.distance() * 2);
        
        }

        public double tiji()
        {
            return (m.distance() + n.distance());
        
        }

  }
    class Program
    {
        static void Main(string[] args)
        {
            CPoint a = new CPoint(5,2);
            CPoint b = new CPoint(1,1);
            Cline c = new Cline(3,0,a);
            Cline d = new Cline(0,0,b);
            Console.WriteLine("两点之间的距离是{0}",c.distance());
            CRect f = new CRect(c,d);
            Console.WriteLine("矩形的周长是{0}",f.zhouchang());
            Console.WriteLine("矩形的体积是{0}", f.tiji());
            Console.ReadKey();

        }
    }
}


运行结果:

心得体会:呵呵

你可能感兴趣的:(C#-—点类,直线类,矩形类之间的继承)