Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
72
Task/Vector/Oberon/vector.oberon
Normal file
72
Task/Vector/Oberon/vector.oberon
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
MODULE Vector;
|
||||
|
||||
IMPORT Out;
|
||||
|
||||
TYPE
|
||||
Vector = POINTER TO VectorDesc;
|
||||
VectorDesc = RECORD
|
||||
x,y:REAL;
|
||||
END;
|
||||
|
||||
VAR
|
||||
a,b:Vector;
|
||||
|
||||
PROCEDURE Add*(a,b:Vector):Vector;
|
||||
VAR res:Vector;
|
||||
BEGIN
|
||||
NEW(res);
|
||||
res.x := a.x+b.x;
|
||||
res.y := a.y+b.y;
|
||||
RETURN res;
|
||||
END Add;
|
||||
|
||||
PROCEDURE Sub*(a,b:Vector):Vector;
|
||||
VAR res:Vector;
|
||||
BEGIN
|
||||
NEW(res);
|
||||
res.x := a.x-b.x;
|
||||
res.y := a.y-b.y;
|
||||
RETURN res;
|
||||
END Sub;
|
||||
|
||||
PROCEDURE Mul*(v:Vector;r:REAL):Vector;
|
||||
VAR res:Vector;
|
||||
BEGIN
|
||||
NEW(res);
|
||||
res.x := v.x*r;
|
||||
res.y := v.y*r;
|
||||
RETURN res;
|
||||
END Mul;
|
||||
|
||||
PROCEDURE Div*(v:Vector;r:REAL):Vector;
|
||||
VAR res:Vector;
|
||||
BEGIN
|
||||
NEW(res);
|
||||
res.x := v.x/r;
|
||||
res.y := v.y/r;
|
||||
RETURN res;
|
||||
END Div;
|
||||
|
||||
PROCEDURE Print*(op:ARRAY OF CHAR;v:Vector);
|
||||
BEGIN
|
||||
Out.String(op);
|
||||
Out.String("(");
|
||||
Out.Real(v.x,0);
|
||||
Out.String(", ");
|
||||
Out.Real(v.y,0);
|
||||
Out.String(")");
|
||||
END Print;
|
||||
|
||||
BEGIN
|
||||
NEW(a); NEW(b);
|
||||
a.x := 5.0; a.y := 7.0;
|
||||
b.x := 2.0; b.y := 3.0;
|
||||
Print("Add: ",Add(a,b));
|
||||
Out.Ln;
|
||||
Print("Sub: ",Sub(a,b));
|
||||
Out.Ln;
|
||||
Print("Mul: ",Mul(a,11.0));
|
||||
Out.Ln;
|
||||
Print("Div: ",Div(a,2.0));
|
||||
Out.Ln
|
||||
END Vector.
|
||||
Loading…
Add table
Add a link
Reference in a new issue