Created
March 26, 2019 08:52
-
-
Save jasongorman/fe45bc7c29d5b269c74e73a466c5341f 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 width; | |
float length; | |
}; | |
Room* new_rectangular_room(float width, float length){ | |
Dimensions* dimensions = malloc(sizeof(Dimensions)); | |
Room* room = malloc(sizeof(Room)); | |
dimensions->width = width; | |
dimensions->length = length; | |
room->dimensions = dimensions; | |
room->area = &rectangular_area; | |
return room; | |
} | |
float rectangular_area(struct Room *room) { | |
Dimensions *dimensions = room->dimensions; | |
return dimensions->length * dimensions->width; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment