Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created March 29, 2019 10:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/8e7afdeaae313638399e38e12e1209b6 to your computer and use it in GitHub Desktop.
Save jasongorman/8e7afdeaae313638399e38e12e1209b6 to your computer and use it in GitHub Desktop.
begin
Real procedure ceiling(number); Real number;
begin
Integer numberAsInt;
numberAsInt := number;
if numberAsInt < number then
numberAsInt := numberAsInt + 1;
ceiling := numberAsInt;
end;
class Carpet;
virtual: procedure price is Real procedure price(area); Real area;;
begin
end;
class Room;
virtual: Real procedure area();
begin
end;
Carpet class StandardCarpet(pricePerSqrMetre, roundUp); Real pricePerSqrMetre; Boolean roundUp;
begin
Real procedure price(area); Real area;
begin
if roundUp then
area := ceiling(area);
price := pricePerSqrMetre * area;
end;
end;
Room class RectangularRoom(width, length); Real width, length;
begin
Real procedure area;
begin
area := width * length;
end;
end;
Room class CircularRoom(radius); Real radius;
begin
Real procedure area;
begin
area := (radius * 2)**2;
end;
end;
class CarpetQuote(r, c); ref(Room) r; ref(Carpet) c;
begin
Real procedure quote;
begin
quote := c.price(r.area);
end;
end;
ref(Carpet) c;
ref(Room) r;
ref(CarpetQuote) q;
r :- new RectangularRoom(2.5, 2.5);
c :- new StandardCarpet(10.0, False);
q :- new CarpetQuote(r, c);
OutText("Quote for rectangular carpet (not rounded) = ");
OutFix(q.quote, 5, 10);
Outimage;
c :- new StandardCarpet(10.0, True);
q :- new CarpetQuote(r, c);
OutText("Quote for rectangular carpet (rounded to nearest sq m) = ");
OutFix(q.quote, 5, 10);
Outimage;
r :- new CircularRoom(2.5);
c :- new StandardCarpet(10.0, True);
q :- new CarpetQuote(r, c);
OutText("Quote for carpet for circular room (rounded to nearest sq m) = ");
OutFix(q.quote, 5, 10);
Outimage;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment