June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
46
Task/Polymorphism/Elena/polymorphism.elena
Normal file
46
Task/Polymorphism/Elena/polymorphism.elena
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import extensions.
|
||||
|
||||
class Point
|
||||
{
|
||||
int prop X :: _x.
|
||||
int prop Y :: _y.
|
||||
|
||||
constructor new(IntNumber x, IntNumber y)
|
||||
[
|
||||
_x := x.
|
||||
_y := y.
|
||||
]
|
||||
|
||||
constructor new
|
||||
<= new(0,0).
|
||||
|
||||
print [ console printLine("Point") ]
|
||||
}
|
||||
|
||||
class Circle :: Point
|
||||
{
|
||||
int prop R :: _r.
|
||||
|
||||
constructor new
|
||||
<= new(0).
|
||||
|
||||
constructor new(IntNumber r)
|
||||
<= new(0, 0, r).
|
||||
|
||||
constructor new(IntNumber x, IntNumber y, IntNumber r)
|
||||
<= new(x, y);
|
||||
[
|
||||
_r := r.
|
||||
]
|
||||
|
||||
print [ console printLine("Circle") ]
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var p := Point new.
|
||||
var c := Circle new.
|
||||
|
||||
p print.
|
||||
c print.
|
||||
].
|
||||
|
|
@ -1,30 +1,28 @@
|
|||
import Base.print
|
||||
|
||||
type Point
|
||||
mutable struct Point
|
||||
x::Float64
|
||||
y::Float64
|
||||
end
|
||||
|
||||
print(p::Point) = println("Point($(p.x), $(p.y))")
|
||||
Base.show(io::IO, p::Point) = print(io, "Point($(p.x), $(p.y))")
|
||||
|
||||
x(p::Point) = p.x
|
||||
y(p::Point) = p.y
|
||||
getx(p::Point) = p.x
|
||||
gety(p::Point) = p.y
|
||||
|
||||
setx(p::Point, x) = (p.x = x)
|
||||
sety(p::Point, y) = (p.y = y)
|
||||
|
||||
type Circle
|
||||
mutable struct Circle
|
||||
x::Float64
|
||||
y::Float64
|
||||
r::Float64
|
||||
end
|
||||
|
||||
x(c::Circle) = c.x
|
||||
y(c::Circle) = c.y
|
||||
r(c::Circle) = c.r
|
||||
getx(c::Circle) = c.x
|
||||
gety(c::Circle) = c.y
|
||||
getr(c::Circle) = c.r
|
||||
|
||||
setx(c::Circle, x) = (c.x = x)
|
||||
sety(c::Circle, y) = (c.y = y)
|
||||
setr(c::Circle, r) = (c.r = r)
|
||||
|
||||
print(c::Circle) = println("Circle($(c.x), $(c.y), $(c.r))")
|
||||
Base.show(io::IO, c::Circle) = print(io, "Circle($(c.x), $(c.y), $(c.r))")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue