class PhysicsVector(name,x,y,z) method add(n,b) c := PhysicsVector(n, x + b.x, y + b.y, z + b.z) return c end method subtract(n,b) c := PhysicsVector(n, x - b.x, y - b.y, z - b.z) return c end method write_vector() write(name || " = " || x || "i + " || y || "j + " || z || "k") end method dot_vector(b) return x* b.x + y* b.y + z* b.z end method cross_vector(n,b) c := PhysicsVector(n, y * b.z - b.y * z, -(x * b.z - b.x * z), x * b.y - b.x * y) return c end method magnitude_vector() return sqrt(x*x + y*y + z*z) end method direction_vector_r() return atan(y,x) end method direction_vector_d() return atan(y,x) * 90.0 / asin(1.0) end method write_magnitude() write("magnitude of " || name || " = " || self.magnitude_vector()) end method write_direction_r() write("direction of " || name || " in radians = " || self.direction_vector_r()) end method write_direction_d() write("direction of " || name || " in degrees = " || self.direction_vector_d()) end method write_dot(name, b ) write("dot of " || self.name || " and " || b.name || " = " || self.dot_vector(b)) end method write_cross(name, b ) local ret write("cross of " || self.name || " and " || b.name || " = :") ret := self.cross_vector(name, b) ret.write_vector() end end procedure main() write("Unicon output") write("Chapter 2") write("Problem 5") a := PhysicsVector("a", 4.0, -3.0, 0.0) b := PhysicsVector("b", 6.0, 8.0, 0.0) c := a.add("c", b) d := b.subtract("d", a) e := a.subtract("e", b) f := PhysicsVector("f", 2.0, -3.0, 7.0) g := PhysicsVector("g", 12.0, 45.0, -8.0) h := PhysicsVector("h", -5.0, -3.0, 42.0) a.write_vector() b.write_vector() c.write_vector() d.write_vector() e.write_vector() a.write_magnitude() b.write_magnitude() c.write_magnitude() d.write_magnitude() e.write_magnitude() a.write_direction_r() b.write_direction_r() c.write_direction_r() d.write_direction_r() e.write_direction_r() a.write_direction_d() b.write_direction_d() c.write_direction_d() d.write_direction_d() e.write_direction_d() a.write_dot("a.a",a) a.write_dot("a.b",b) b.write_dot("b.a",a) a.write_dot("a.c",c) d.write_dot("d.a",a) a.write_dot("a.e",e) e.write_dot("e.a",a) a.write_cross("axa",a) a.write_cross("axb",b) b.write_cross("bxa",a) a.write_cross("axc",c) d.write_cross("dxa",a) a.write_cross("axe",e) e.write_cross("exa",a) f.write_cross("fxg",g) f.write_cross("fxh",h) g.write_cross("gxh",h) g.write_cross("gxf",f) h.write_cross("hxf",f) h.write_cross("hxg",g) end