using System;
namespace OperatorOvApplication
{
class Box
{
private double length;
private double breadth;
private double height;
public double getVolume()
{
return length*breadth*height;
}
public void setLength(double len)
{
length = len;
}
public void setBreadth(double bre)
{
breadth = bre;
}
public void steHeight(double hei)
{
height = hei;
}
public static Box operator+(Box b,Box c)
{
Box box = new Box();
box.length = b.length + c.length;
box.breadth = b.breadth + c.breadth;
box.height = b.height + c.height;
return box;
}
public static bool operator==(Box lhs,Box rhs)
{
bool status = false;
if(lhs.length == rhs.length && lhs.breadth == rhs.breadth && lhs.height == rhs.height)
{
status = true;
}
return status;
}
public static bool operator!=(Box lhs,Box rhs)
{
bool status = false;
if(lhs.length != rhs.length || lhs.breadth != rhs.breadth || lhs.height != rhs.height)
{
status = true;
}
return status;
}
public static bool operator<(Box lhs,Box rhs)
{
bool status = false;
if(lhs.length < rhs.length && lhs.breadth < rhs.breadth && lhs.height < rhs.height)
{
status = true;
}
return status;
}
public static bool operator>(Box lhs,Box rhs)
{
bool status = false;
if(lhs.length > rhs.length && lhs.breadth > rhs.breadth && lhs.height > rhs.height)
{
status = true;
}
return status;
}
public static bool operator<=(Box lhs,Box rhs)
{
bool status = false;
if(lhs.length <= rhs.length && lhs.breadth <= rhs.breadth && lhs.height <= rhs.height)
{
status = true;
}
return status;
}
public static bool operator>=(Box lhs,Box rhs)
{
bool status = false;
if(lhs.length >= rhs.length && lhs.breadth >= rhs.breadth && lhs.height >= rhs.height)
{
status = true;
}
return status;
}
public override string ToString()
{
return String.Format("({0},{1},{2})",length,breadth,height);
}
}
class Tester
{
static void Main(string[] args)
{
Box Box1 = new Box();
Box Box2 = new Box();
Box Box3 = new Box();
Box Box4 = new Box();
double volume = 0.0;
Box1.setLength(6.0);
Box1.setBreadth(7.0);
Box1.steHeight(5.0);
Box2.setLength(12.0);
Box2.setBreadth(13.0);
Box2.steHeight(10.0);
Console.WriteLine("Box1:{0}",Box1.ToString());
Console.WriteLine("Box2:{0}",Box2.ToString());
volume = Box1.getVolume();
Console.WriteLine("Box1的体积:{0}",volume);
volume = Box2.getVolume();
Console.WriteLine("Box2的体积:{0}",volume);
Box3 = Box1 + Box2;
Console.WriteLine("Box3:{0}",Box3.ToString());
volume = Box3.getVolume();
Console.WriteLine("Box3的体积:{0}",volume);
if(Box1 > Box2)
Console.WriteLine("Box1大于Box2");
else
Console.WriteLine("Box1不大于Box2");
if(Box1 < Box2)
Console.WriteLine("Box1小于Box2");
else
Console.WriteLine("Box1不小于Box2");
if(Box1 >= Box2)
Console.WriteLine("Box1大于等于Box2");
else
Console.WriteLine("Box1不大于等于Box2");
if(Box1 <= Box2)
Console.WriteLine("Box1小于等于Box2");
else
Console.WriteLine("Box1不小于等于Box2");
if(Box1 != Box2)
Console.WriteLine("Box1不等于Box2");
else
Console.WriteLine("Box1等于Box2");
Box4 = Box3;
if(Box3 == Box4)
Console.WriteLine("Box3等于Box4");
else
Console.WriteLine("Box3不等于Box4");
Console.ReadKey();
}
}
}