C#第6周实验类的继承

/* (程序头部注释开始) 
 * 程序的版权和版本声明部分 
 * Copyright (c) 2011, 烟台大学计算机学院学生  
 * All rights reserved. 
 * 文件名称:定义一个描述坐标点的CPoint类,派生出直线类Cline,在派生出矩形类CRect,求两点之间的距离以及矩形的面积与周长。 
 * 作 者: 姜甜甜  
 * 完成日期: 2016 年 04 月 14 日 
 * 版 本 号: V1.0   
 * 程序头部的注释结束 
 */  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
   
    class CPoint
    {
        double x;
        double y;
        public CPoint(){}        //必须的,不然 public CLine(double ll)出问题
        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
    {
        double l;              //两点间线段的长度
        public CLine() { }
        public CLine(CPoint a, CPoint b)
        {
            l = distance(a,b);
        }
        public double distance(CPoint a,CPoint b)
        {
            l = Math.Sqrt(Math.Pow(a.getx() - b.getx(), 2) + Math.Pow(a.gety() - b.gety(), 2));
            return l;
        }
        public double getl()
        { return l; }
    }
    class CRect:CLine
    {
        double a;
        double b;
        public  CRect(double a,double b)
        {
            this.a=a;
            this.b=b;
        }
        public double CC()
        {
            return 2*(a+b);
        }
        public double BB()
        {
            return a*b;
        }
    }
    class program
    {
        static void Main(string []args)
        {
            CPoint a=new CPoint(1,1);
            CPoint b=new CPoint(4,1);
            CPoint c = new CPoint(4,5);
            CLine m = new CLine(a,b);
            CLine mm = new CLine(b,c);
            Console.WriteLine("the distance of a and b is {0}", m.distance(a,b));
            CRect r = new CRect(m.getl(),mm.getl());
            Console.WriteLine("the c is {0},the s is {1} ",r.BB(),r.CC());
            Console.ReadKey();
        }
    }
        
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值