You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
1.7 KiB
151 lines
1.7 KiB
|
|
Exercise 2.46: A two-dimensional vector
|
|
v
|
|
|
|
running from the origin to a point can be represented as a pair consisting of
|
|
an
|
|
x
|
|
-coordinate and a
|
|
y
|
|
-coordinate. Implement a data abstraction for
|
|
vectors by giving a constructor make-vect and corresponding selectors
|
|
xcor-vect and ycor-vect. In terms of your selectors and
|
|
constructor, implement procedures add-vect, sub-vect, and
|
|
scale-vect that perform the operations vector addition, vector
|
|
subtraction, and multiplying a vector by a scalar:
|
|
|
|
|
|
|
|
|
|
(
|
|
|
|
x
|
|
1
|
|
|
|
,
|
|
|
|
y
|
|
1
|
|
|
|
)
|
|
+
|
|
(
|
|
|
|
x
|
|
2
|
|
|
|
,
|
|
|
|
y
|
|
2
|
|
|
|
)
|
|
|
|
|
|
=
|
|
|
|
|
|
(
|
|
|
|
x
|
|
1
|
|
|
|
+
|
|
|
|
x
|
|
2
|
|
|
|
,
|
|
|
|
y
|
|
1
|
|
|
|
+
|
|
|
|
y
|
|
2
|
|
|
|
)
|
|
,
|
|
|
|
|
|
|
|
|
|
(
|
|
|
|
x
|
|
1
|
|
|
|
,
|
|
|
|
y
|
|
1
|
|
|
|
)
|
|
−
|
|
(
|
|
|
|
x
|
|
2
|
|
|
|
,
|
|
|
|
y
|
|
2
|
|
|
|
)
|
|
|
|
|
|
=
|
|
|
|
|
|
(
|
|
|
|
x
|
|
1
|
|
|
|
−
|
|
|
|
x
|
|
2
|
|
|
|
,
|
|
|
|
y
|
|
1
|
|
|
|
−
|
|
|
|
y
|
|
2
|
|
|
|
)
|
|
,
|
|
|
|
|
|
|
|
|
|
s
|
|
⋅
|
|
(
|
|
x
|
|
,
|
|
y
|
|
)
|
|
|
|
|
|
=
|
|
|
|
|
|
(
|
|
s
|
|
x
|
|
,
|
|
s
|
|
y
|
|
)
|
|
.
|
|
|
|
|
|
|
|
|
|
|