/**** * * Definition of the type SolarSystem and associated functions. A SolarSystem * is a structure with a diameter, a collection of Planets, and the name of the * galaxy it's in. A SolarSystem has functions to initialize, add, find, * remove, and print planets in the system. * */ #include "planet.h" /** * Type SolarSystem is a structure that defines the properties of a planetary * system. */ typedef struct { double diameter; /* diameter of the system in km */ Planet** planets; /* array of planets */ int num_planets; /* number of planest in the system */ char galaxy[NAME_SIZE]; /* name of the system */ } SolarSystem; /** * Initialize the given solar system with the given diameter and galaxy name. * Allocate an array of pointers to planents of size num_planets. Assign NULL * to every element in the planets array, "" to its galaxy. */ void init_system(SolarSystem* ss, double diameter, char* galaxy, int num_planets); /** * Add the given planet to the given system. The planet is put in the next * empty position. If there are no empty planets in the given system, do * nothing. NOTE: If planet ordering is important, use the put_planet * function. */ void add_planet(Planet* p, SolarSystem* ss); /** * Put the given planet at the given position in the given system. Any * previous planet at the position is overwritten. If the position is less * than 0 or greater than ss->num_planets - 1, do nothing. */ void put_planet(Planet* p, int pos, SolarSystem* ss); /** * Return the planet of the given name in the given system. If there is no * such planet, return the EMPTY_PLANET. */ Planet* find_planet(char* name, SolarSystem ss); /** * Return the position of the planet of the given name in the given system. If * there is no such planet, return -1. */ int find_planet_position(char* name, SolarSystem ss); /** * Remove the planet with the given name from the given system. The removal is * performed by puttting EMPTY_PLANET at the position of planet with the given * name. The position of all other planets in the system remains unchanged. * If a planet of the given name is not in the system, do nothing. */ void remove_planet(char* name, SolarSystem* ss); /** * Output the given system to stdout. Do not print any of the empty * planet positions. */ void print_system(SolarSystem s);