1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace Myproject
8 {
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 Box b1 = new Box(1, 1, 1);
14 Box b2 = new Box(2, 2, 2);
15 Box b3 = new Box(3, 3, 3);
16
17 Console.WriteLine("Check: b1 + b2 " + (b1 + b2));
18 Console.WriteLine("Check: -b1 " + b1);
19 Console.WriteLine("Check: > , < , == , != ");
20 if (b2 > b1) Console.WriteLine("b2 > b1");
21 if (b1 < b2) Console.WriteLine("b1 < b2");
22
23 if (b1 + b2 == b3) Console.WriteLine("b1 + b2 == b3 ");
24 if (b1 + b2 != b1) Console.WriteLine("b1 + b2 != b1 ");
25 }
26 }
27 class Box
28 {
29 private int length, width, height;
30
31 public Box(int length, int width, int height)
32 {
33 this.length = length;
34 this.width = width;
35 this.height = height;
36 }
37
38 public Box() : this(0, 0, 0) { }
39 public int Length { get { return length; } set { length = value; } }
40 public int Width { get { return width; } set { width = value; } }
41 public int Height { get { return height; } set { height = value; } }
42
43 public override string ToString()
44 {
45 return string.Format("( {0} , {1} , {2} )",length,width,height);
46 }
47 public static Box operator +(Box rhs)
48 {
49 Box res = new Box();
50 res.height = - rhs.height;
51 res.length = - rhs.length;
52 res.width = - rhs.width;
53 return res;
54 }
55
56 public static Box operator + (Box lhs , Box rhs)
57 {
58 Box res = new Box();
59 res.height = lhs.height + rhs.height;
60 res.length = lhs.length + rhs.length;
61 res.width = lhs.width + rhs.width;
62 return res;
63 }
64
65 public static Box operator - (Box lhs, Box rhs)
66 {
67 Box res = new Box();
68 res.height = lhs.height - rhs.height;
69 res.length = lhs.length - rhs.length;
70 res.width = lhs.width - rhs.width;
71 return res;
72 }
73
74 public static bool operator >(Box lhs, Box rhs)
75 {
76 bool status = false;
77 if (lhs.length > rhs.length &&
78 lhs.width > rhs.width &&
79 lhs.height > rhs.height)
80 {
81 status = true;
82 }
83 return status;
84 }
85
86 public static bool operator <(Box lhs, Box rhs)
87 {
88 bool status = false;
89 if (lhs.length < rhs.length &&
90 lhs.width < rhs.width &&
91 lhs.height < rhs.height)
92 {
93 status = true;
94 }
95 return status;
96 }
97
98 public static bool operator == (Box lhs, Box rhs)
99 {
100 bool status = false;
101 if (lhs.length == rhs.length &&
102 lhs.width == rhs.width &&
103 lhs.height == rhs.height)
104 {
105 status = true;
106 }
107 return status;
108 }
109
110 public static bool operator !=(Box lhs, Box rhs)
111 {
112 bool status = false;
113 if (lhs.length != rhs.length ||
114 lhs.width != rhs.width ||
115 lhs.height != rhs.height)
116 {
117 status = true;
118 }
119 return status;
120 }
121 }
122 }