How to resolve the algorithm Vector step by step in the 11l programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Vector step by step in the 11l programming language

Table of Contents

Problem Statement

Implement a Vector class (or a set of functions) that models a Physical Vector. The four basic operations and a pretty print function should be implemented.

The Vector may be initialized in any reasonable way.

The four operations to be implemented are:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Vector step by step in the 11l programming language

Source code in the 11l programming language

T Vector
   Float x, y

   F (x, y)
      .x = x
      .y = y

   F +(vector)
      R Vector(.x + vector.x, .y + vector.y)

   F -(vector)
      R Vector(.x - vector.x, .y - vector.y)

   F *(mult)
      R Vector(.x * mult, .y * mult)

   F /(denom)
      R Vector(.x / denom, .y / denom)

   F String()
      R ‘(#., #.)’.format(.x, .y)

print(Vector(5, 7) + Vector(2, 3))
print(Vector(5, 7) - Vector(2, 3))
print(Vector(5, 7) * 11)
print(Vector(5, 7) / 2)

  

You may also check:How to resolve the algorithm Check input device is a terminal step by step in the Jsish programming language
You may also check:How to resolve the algorithm Pierpont primes step by step in the Perl programming language
You may also check:How to resolve the algorithm Function composition step by step in the PHP programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the Python programming language
You may also check:How to resolve the algorithm Loops/Break step by step in the Suneido programming language