Course of Raku / Addendum 🆕 / Types and text machines / Objects and classes / Exercises

Adding vectors

Problem

Write a Vector class with x and y and an add method that returns a new vector — the sum of two. Give it a Str method so it prints as (x, y). Add (1, 2) and (3, 4) and print the result.

Example

The program prints:

(4, 6)

Solution

See the solution

Course navigation

Solution: Which quadrant   |   Solution: Adding vectors