using System;
class Vector
{
private double XVector;
private double YVector;
//构造函数
public Vector(double x, double y )
{
XVector = x;
YVector = y;
}
//获取向量的长度
public double GetLength( )
{
double Length = Math.Sqrt( XVector*XVector + YVector*YVector );
return Length;
}
//重载运算符==
public static bool operator == ( Vector a, Vector b )
{
return ( (a.XVector == b.XVector) && (a.YVector == b.YVector) );
}
//重载运算符!=
public static bool operator != ( Vector a, Vector b )
{
return !( a == b );
}
//重载运算符>:以向量长度判断是否为真
public static bool operator > ( Vector a, Vector b )
{
return a.GetLength( ) > b.GetLength( );
}
//重载运算符<
public static bool operator < ( Vector a, Vector b )
{
return a.GetLength( ) < b.GetLength( );
}
//重载运算符>=
public static bool operator >= ( Vector a, Vector b )
{
return ( a == b ) || ( a > b );
}
//重载运算符<=
public static bool operator <= ( Vector a, Vector b )
{
return ( a == b ) || ( a < b );
}
}
class Test
{
static public void Main( )
{
Vector vector1 = new Vector( 3, 4 );
Vector vector2 = new Vector( 0, 5 );
Vector vector3 = new Vector( 2, 2 );
Console.WriteLine("向量1为( 3, 4 ) \t 向量2为( 0, 5 ) \t 向量3为( 2, 2 )");
Console.WriteLine("向量1 == 向量2 为:{0}", vector1 == vector2 );
Console.WriteLine("向量1 != 向量2 为:{0}", vector1 != vector2 );
Console.WriteLine("向量1 > 向量3 为:{0}", vector1 > vector3 );
Console.WriteLine("向量2 < 向量3 为:{0}", vector2 < vector3 );
Console.WriteLine("向量1 >= 向量2 为:{0}", vector1 != vector2 );
Console.WriteLine("向量1 <= 向量2 为:{0}", vector1 != vector2 );
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有