C#编程基础 实验(4)
来源:互联网 发布:结婚照幻灯片制作软件 编辑:程序博客网 时间:2024/05/16 18:12
把定义平面直角坐标系上的一个点的类CPoint作为基类,派生出描述一条直线的类Cline,再派生出一个矩形类CRect。
代码如下:
using System;namespace Program0{ class CPoint { public double x { get; set; } public double y { get; set; } public CPoint() { } public CPoint(double x, double y) { this.x = x; this.y = y; } } class CLine : CPoint { public CPoint EPoint{get;set;} public double x2{get{return EPoint.x;}set{EPoint.x=value;}} public double y2{get{return EPoint.y;}set{EPoint.y=value;}} public CLine() { EPoint=new CPoint(); } public CLine(CPoint p1,CPoint p2) { base.x=p1.x; base.y=p1.y; EPoint=p2; } public double LineLength{ get{ return Math.Sqrt((x2-x)*(x2-x)+(y2-y)*(y2-y)); } } } class CRect :CLine { public double Perimeter { get { return 2 * (Math.Abs(x2 - x) + Math.Abs(y2 - y)); } } public double Area { get { return Math.Abs((x2 - x) * (y2 - y)); } } } class Program { static void Main(string[] args) { CRect rect = new CRect() {x = 1, y = 2, x2 = 0, y2 = 1 }; Console.WriteLine(rect.LineLength); Console.WriteLine(rect.Perimeter); Console.WriteLine(rect.Area); Console.ReadKey(); } } }
1 0
- C#编程基础 实验(4)
- C#编程基础 实验(8) (4)
- C#编程基础 实验(6) (4-7)
- C#编程基础 实验(1)
- C#编程基础 实验(2)
- C#编程基础 实验(3),
- C#编程基础 实验(7) (3)
- C#编程基础 实验(10) (5)
- C#编程基础 实验(6) (1-3)
- C#编程基础 实验(7) (1-2)
- C#基础实验
- C#编程基础(一)
- C#编程基础(二)
- c#编程基础(三)
- C#编程基础(四)
- C#编程基础(五)
- C#编程基础(六)
- C#编程基础(七)
- 尚硅谷·网上书城项目(三)
- S5PV210中断处理的主要寄存器
- 关于非阻塞IO函数的学习
- Android EditText自定义密文符号
- Class.forName()用法及与new区别 详解
- C#编程基础 实验(4)
- 利用栈实现加减乘除幂功能
- Android随笔
- 矩阵求导
- 2016.4.09Test:problem1:绕口令:脑洞+hash
- NKOI 1011 锁妖塔
- tmux 安装及使用
- MyBatis批量操作_MySql
- 数据结构-二叉树的前序、中序、后序、层次遍历