



Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!




typedef struct { int color, speed; } Car; typedef struct { int color, speed; } Plane; typedef struct { int color, speed; } Bicycle; Car *newCar(int color); Plane *newPlane(int color); Bicycle *newBicycle(int color); void setCarColor(Car *car, int color); void setPlaneColor(Plane *plane, int color); void setBicycleColor(Bicycle *bike, int color); void increaseCarSpeed(Car *car, int more); void decreaseCarSpeed(Car *car, int less); void increasePlaneSpeed(Plane *plane, int more); void decreasePlaneSpeed(Plane *plane, int less); void increaseBicycleSpeed(Bicycle *bike, int more); void decreaseBicycleSpeed(Bicycle *bike, int less); void landPlain(Plane *plane); void parkCar(Car *car); public abstract class Vehicle { protected int color; protected int speed; public void setColor(int color) { ... } public void increaseSpeed(int more) { ... } public void decreaseSpeed(int less) { ... } } public class Bicycle extends Vehicle { } public class Car extends Vehicle { public void park() { ... } } public class Plane extends Vehicle { public void land() { ... } }
Shape[] shapes = ...
public abstract class Shape { protected int color; public Shape(int color) { ... } public void setColor(int color) { ... } public int getColor() { ... } public abstract float area(); public abstract void draw(); } public class Triangle extends Shape { private Point pt1, pt2, pt3; public Triangle(int color, Point pt1, Point pt2, Point pt3) { ... } public float area() { ... } public void draw() { ... } public void move(Point pt1, Point pt2, Point pt3) { ... } } public class Rectangle extends Shape { private Point pt1, pt2; public Rectangle(int color, Point pt1, Point pt2) { ... } public float area() { ... } public void draw() { ... } public void move(Point pt1, Point pt2) { ... } } int sum = 0; for (Shape shp: shapes) sum += shp.area(); Point pt1 = … Point pt2 = … Point pt3 = … for (Shape shp: shapes) { if (shp instanceof Triangle) { Triangle tr = (Triangle)shp; tr.move(pt1,pt2,pt3); } else if (shp instanceof Rectangle) { Rectangle rect = (Rectangle)shp; rect.move(pt1,pt2); } }
fun [1..]
fun (<5) [1..]
fun :: (a > Bool) > [a] > [a] fun _ [] = [] fun p (x:xs) | p x = x : fun p xs | otherwise = [] fun :: [a] > a fun [] = 1 fun (x:_) = x public class Canvas
def fun(p, lst): if not lst: return [] else: if p(lst[0]): return [x] + fun(p, lst[1:]) else: return []