重载实例源代码
来源:互联网 发布:微信商城分销源码下载 编辑:程序博客网 时间:2024/06/11 06:55
using System;
using System.Collections.Generic;
using System.Text;
namespace CPLR
{
class Program
{
static void Main(string[] args)
{
CPoint a = new CPoint(4, 5);
a--;
CPoint a1=new CPoint (1,2);
Console.WriteLine("点的坐标:({0},{1})",a.x ,a.y);
CLine b= new CLine(new CPoint(1,1),new CPoint (1,2));
CLine obj2 = new CLine(new CPoint (1,1),new CPoint (3,1));
CPoint p=a+a1;
Console.WriteLine("新的点:{0},{1}",p.x ,p.y);
p = a1 % 3;
Console.WriteLine("P点坐标:{0},{1}", p.x, p.y);
Console.WriteLine("l1的边长:{0}",b.Leagth ());
Console.WriteLine("l2的边长:{0}",obj2.Leagth ());
CRect A=new CRect (b ,obj2 );
Console.WriteLine("周长:{0}",A.C());
Console.WriteLine("面积:{0}",A.S());
Console.Read();
}
}
class CPoint
{
public int x;
public int y;
public CPoint(int X, int Y)
{
x = X;
y = Y;
}
public static CPoint operator --(CPoint a)
{
a.x = a.x - 1;
a.y = a.y - 1;
return a;
}
public static CPoint operator +(CPoint a,CPoint a1)
{
CPoint p = new CPoint ( a.x + a1.x,a.y + a1.y);
return p;
}
public static CPoint operator %(CPoint b,int n)
{
CPoint p=new CPoint (Convert.ToInt32(Math.Pow(b.x,n)),Convert.ToInt32(Math.Pow(b.y,n)));
return p;
}
}
class CLine
{
public CPoint p1;
public CPoint p2;
public CLine (CPoint P1, CPoint P2)
{
p1 = P1;
p2 = P2;
}
public double Leagth()
{
return Math.Sqrt(Math.Pow(p1.x - p2.x,2) + Math.Pow(p1.y - p2.y,2));
}
public static CLine operator ++(CLine b)
{
b.p1.x =b.p1.x + b.p2.x ;
b.p1.y = b.p1.y + b.p2.y;
return b;
}
}
class CRect
{
public CLine l1;
public CLine l2;
public CRect(CLine L1, CLine L2)
{
l1 = L1;
l2 = L2;
}
public double C()
{
return (l1.Leagth () +l2.Leagth()) * 2;
}
public double S()
{
return l1.Leagth() *l2.Leagth() ;
}
}
}
希望大家看完贴多说说意见!大家共同学习!
谢谢!
- 重载实例源代码
- 源代码实例
- c# 重载实例
- java的重载实例
- 运算符重载实例
- 运算符重载实例
- 重载运算实例
- 操作符重载实例
- 运算符重载实例
- struts 2.0 实例源代码
- jsp留言板实例源代码
- java源代码实例网站
- jQuery效果实例源代码
- javascript源代码(实例60)
- Netconsole实例源代码分析
- html5 简单实例源代码
- JQuerymobile实例源代码
- (zz)对cout << 重载的源代码
- AWK教程
- 非递归背包算法
- vb6内嵌汇编实现图像快速对比
- COM原理与应用中关于聚合实现的纪要
- 通过URL从Temporary Internet Files得到本地文件路径的函数
- 重载实例源代码
- 前三天的试用期啊
- VB6中使用32位图标(第二版)
- 关于二维数组和指向指针的指针
- VB6中使用32位图标
- 成功修复2G金士顿U盘
- ActiveXDLL免注册调用的方法(改良自阿国哥的源码)
- 支持多曲线的历史曲线控件源码
- CLSID与ProgID彼此间相互转换