2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1 +1,3 @@
|
|||
Create two classes Point(x,y) and Circle(x,y,r) with a polymorphic function print, accessors for (x,y,r), copy constructor, assignment and destructor and every possible default constructors
|
||||
;Task:
|
||||
Create two classes Point(x,y) and Circle(x,y,r) with a polymorphic function print, accessors for (x,y,r), copy constructor, assignment and destructor and every possible default constructors
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
type Point = Point x y
|
||||
|
||||
instance Show Point where
|
||||
showf _ (Point x y) = "Point " ++ (show x) ++ " " ++ (show y)
|
||||
show (Point x y) = "Point " ++ (show x) ++ " " ++ (show y)
|
||||
|
||||
instance Name Point where
|
||||
getField nm (Point x y)
|
||||
| nm == "x" = x
|
||||
| nm == "y" = y
|
||||
| else = fail "Undefined name."
|
||||
isField nm _ = nm == "x" or nm == "y"
|
||||
isField nm _ = nm == "x" || nm == "y"
|
||||
|
||||
pointX = flip Point 0
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ pointEmpty = Point 0 0
|
|||
type Circle = Circle x y z
|
||||
|
||||
instance Show Circle where
|
||||
showf _ (Circle x y z) =
|
||||
show (Circle x y z) =
|
||||
"Circle " ++ (show x) ++ " " ++ (show y) ++ " " ++ (show z)
|
||||
|
||||
instance Name Circle where
|
||||
|
|
@ -28,7 +28,7 @@ instance Name Circle where
|
|||
| nm == "y" = y
|
||||
| nm == "z" = z
|
||||
| else = fail "Undefined name."
|
||||
isField nm _ = nm == "x" or nm == "y" or nm == "z"
|
||||
isField nm _ = nm == "x" || nm == "y" || nm == "z"
|
||||
|
||||
circleXZ = flip Circle 0
|
||||
|
||||
|
|
@ -41,5 +41,3 @@ circleY y = Circle 0 y 0
|
|||
circleZ = Circle 0 0
|
||||
|
||||
circleEmpty = Circle 0 0 0
|
||||
|
||||
circleX 1 2
|
||||
|
|
|
|||
|
|
@ -1,33 +1,35 @@
|
|||
class Point {
|
||||
protected int x, y;
|
||||
public Point() { this(0); }
|
||||
public Point(int x0) { this(x0, 0); }
|
||||
public Point(int x0, int y0) { x = x0; y = y0; }
|
||||
public Point(int x) { this(x, 0); }
|
||||
public Point(int x, int y) { this.x = x; this.y = y; }
|
||||
public Point(Point p) { this(p.x, p.y); }
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int setX(int x0) { x = x0; }
|
||||
public int setY(int y0) { y = y0; }
|
||||
public void print() { System.out.println("Point"); }
|
||||
public int getX() { return this.x; }
|
||||
public int getY() { return this.y; }
|
||||
public void setX(int x) { this.x = x; }
|
||||
public void setY(int y) { this.y = y; }
|
||||
public void print() { System.out.println("Point x: " + this.x + " y: " + this.y); }
|
||||
}
|
||||
|
||||
public class Circle extends Point {
|
||||
class Circle extends Point {
|
||||
private int r;
|
||||
public Circle(Point p) { this(p, 0); }
|
||||
public Circle(Point p, int r0) { super(p); r = r0; }
|
||||
public Circle(Point p, int r) { super(p); this.r = r; }
|
||||
public Circle() { this(0); }
|
||||
public Circle(int x0) { this(x0, 0); }
|
||||
public Circle(int x0, int y0) { this(x0, y0, 0); }
|
||||
public Circle(int x0, int y0, int r0) { super(x0, y0); r = r0; }
|
||||
public Circle(int x) { this(x, 0); }
|
||||
public Circle(int x, int y) { this(x, y, 0); }
|
||||
public Circle(int x, int y, int r) { super(x, y); this.r = r; }
|
||||
public Circle(Circle c) { this(c.x, c.y, c.r); }
|
||||
public int getR() { return r; }
|
||||
public int setR(int r0) { r = r0; }
|
||||
public void print() { System.out.println("Circle"); }
|
||||
|
||||
public static void main(String args[]) {
|
||||
Point p = new Point();
|
||||
Point c = new Circle();
|
||||
p.print();
|
||||
c.print();
|
||||
}
|
||||
public int getR() { return this.r; }
|
||||
public void setR(int r) { this.r = r; }
|
||||
public void print() { System.out.println("Circle x: " + this.x + " y: " + this.y + " r: " + this.r); }
|
||||
}
|
||||
|
||||
public class test {
|
||||
public static void main(String args[]) {
|
||||
Point p = new Point();
|
||||
Point c = new Circle();
|
||||
p.print();
|
||||
c.print();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
class Point {
|
||||
has Num $.x is rw = 0;
|
||||
has Num $.y is rw = 0;
|
||||
has Real $.x is rw = 0;
|
||||
has Real $.y is rw = 0;
|
||||
method Str { $.perl }
|
||||
}
|
||||
|
||||
class Circle {
|
||||
has Point $.p is rw = Point.new;
|
||||
has Num $.r is rw = 0;
|
||||
has Real $.r is rw = 0;
|
||||
method Str { $.perl }
|
||||
}
|
||||
|
||||
my $c = Circle.new(Point.new(x => 1, y => 2), r => 3);
|
||||
my $c = Circle.new(p => Point.new(x => 1, y => 2), r => 3);
|
||||
say $c;
|
||||
$c.p.x = (-10..10).pick;
|
||||
$c.p.y = (-10..10).pick;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue