Created
March 26, 2019 08:53
-
-
Save jasongorman/c89541a172d501827995e3ae14b70703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Dimensions { | |
float radius; | |
}; | |
struct Room* new_circular_room(float radius){ | |
Dimensions* dimensions = malloc(sizeof(Dimensions)); | |
dimensions->radius = radius; | |
Room* room = malloc(sizeof(Room)); | |
room->dimensions = dimensions; | |
room->area = &circular_area; | |
return room; | |
} | |
float circular_area(struct Room *room) { | |
/* a circular room requires cutting a square carpet of length/width 2 * radius */ | |
float radius = room->dimensions->radius; | |
return (2 * radius) * (2 * radius); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment