Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef enum {
- NEPTUNE_LIKE,
- GAS_GIANT,
- TERRESTRIAL,
- SUPER_EARTH,
- UNKNOWN
- }PlanetType;
- typedef struct {
- char name[30];
- PlanetType type;
- float distanceToEarth;
- }Planet;
- Planet createPlanet(char name[], PlanetType type, double distance) {
- Planet pl;
- strcpy(pl.name, name);
- pl.distanceToEarth = distance;
- pl.type = type;
- return pl;
- }
- typedef struct
- {
- Planet* elems; /** dynamic array containing the planets */
- int length; /** actual length of the array */
- int capacity; /** maximum capacity of the array */
- } PlanetRepo;
- PlanetRepo createPlanetRepo(int capacity) {
- /// create a new planet repo; the elems field must be dynamically allocated (malloc)
- PlanetRepo r;
- r.capacity = capacity;
- r.length = 0;
- r.elems = (Planet*) malloc(sizeof(Planet)*capacity);
- return r;
- }
- bool add (PlanetRepo* repo, Planet pl) // adding a planet pl in the Repository
- {
- int pos = repo->length;
- repo->elems[pos] = pl;
- repo->length++;
- return true; }
- bool remove (PlanetRepo* repo, Planet pl) // can't figure out the implementation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement