Class "Vector" with operator overloading
C#
Medium
classes
Task «Class "Vector" with operator overloading»
Create a class `Vector3D` representing a three-dimensional vector. The class must contain fields X, Y, Z (integers). Implement a constructor that takes three coordinates. Overload the operators: + (vector addition), - (subtraction), * (dot product), and unary minus. In `Main`, read two vectors from the input data (three numbers each separated by a space) and output the result of addition, subtraction, dot product, and also the second vector with unary minus. Each result is printed on a separate line. It is guaranteed that the coordinates are integers from -100 to 100.
Input Format
Two strings. Each string contains three integers separated by spaces — the coordinates of a vector.
Output Format
Four lines: 1) coordinates of the sum of vectors (space-separated); 2) coordinates of the difference (first minus second); 3) dot product (integer); 4) coordinates of the second vector with a unary minus.
Examples
Example 1
INPUT
1 2 3
4 5 6
OUTPUT
5 7 9
-3 -3 -3
32
-4 -5 -6
Example 2
INPUT
5
3 -1 4 -2 6
OUTPUT
Invalid input
Example 3
INPUT
0 0 0
-1 2 5
OUTPUT
-1 2 5
1 -2 -5
0
1 -2 -5
Example 4
INPUT
[{"category":"A","value":10,"active":true},{"category":"B","value":20,"active":true},{"category":"A","value":30,"active":false},{"category":"B","value":25,"active":true}] 15 30
OUTPUT
Invalid input
Example 5
INPUT
3
-5 -10 -15
OUTPUT
Invalid input
main.cs