Task
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.

 Start and end points, and direction
 Angular coefficient and value (length)


The four operations to be implemented are:

 Vector  +  Vector addition
 Vector  -  Vector subtraction
 Vector  *  scalar multiplication
 Vector  /  scalar division


INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
 
DEFINE X_="+0"
DEFINE Y_="+6"
 
TYPE Vector=[CARD x1,x2,x3,y1,y2,y3]
 
PROC PrintVec(Vector POINTER v)
  Print("[") PrintR(v X_)
  Print(",") PrintR(v Y_) Print("]")
RETURN
 
PROC VecIntInit(Vector POINTER v INT ix,iy)
  IntToReal(ix,v X_)
  IntToReal(iy,v Y_)
RETURN
 
PROC VecRealInit(Vector POINTER v REAL POINTER rx,ry)
  RealAssign(rx,v X_)
  RealAssign(ry,v Y_)
RETURN
 
PROC VecStringInit(Vector POINTER v CHAR ARRAY sx,sy)
  ValR(sx,v X_)
  ValR(sy,v Y_)
RETURN
 
PROC VecAdd(Vector POINTER v1,v2,res)
  RealAdd(v1 X_,v2 X_,res X_) ;res.x=v1.x+v2.x
  RealAdd(v1 Y_,v2 Y_,res Y_) ;res.y=v1.y+v2.y
RETURN
 
PROC VecSub(Vector POINTER v1,v2,res)
  RealSub(v1 X_,v2 X_,res X_) ;res.x=v1.x-v2.x
  RealSub(v1 Y_,v2 Y_,res Y_) ;res.y=v1.y-v2.y
RETURN
 
PROC VecMult(Vector POINTER v REAL POINTER a Vector POINTER res)
  RealMult(v X_,a,res X_) ;res.x=v.x*a
  RealMult(v Y_,a,res Y_) ;res.y=v.y*a
RETURN
 
PROC VecDiv(Vector POINTER v REAL POINTER a Vector POINTER res)
  RealDiv(v X_,a,res X_) ;res.x=v.x/a
  RealDiv(v Y_,a,res Y_) ;res.y=v.y/a
RETURN
 
PROC Main()
  Vector v1,v2,res
  REAL s
 
  Put(125) PutE() ;clear the screen
  VecStringInit(v1,"12.3","-4.56")
  VecStringInit(v2,"9.87","654.3")
  ValR("0.1",s)
 
  VecAdd(v1,v2,res)
  PrintVec(v1) Print(" + ") PrintVec(v2)
  Print(" =") PutE() PrintVec(res) PutE() PutE()
 
  VecSub(v1,v2,res)
  PrintVec(v1) Print(" - ") PrintVec(v2)
  Print(" =") PutE() PrintVec(res) PutE() PutE()
 
  VecMult(v1,s,res)
  PrintVec(v1) Print(" * ") PrintR(s)
  Print(" = ") PrintVec(res) PutE() PutE()
 
  VecDiv(v1,s,res)
  PrintVec(v1) Print(" / ") PrintR(s)
  Print(" = ") PrintVec(res)
RETURN