// pottery_studio.c // // Written by YOUR-NAME (YOUR-ZID) // on TODAYS-DATE // // Simulates pieces of pottery moving through the stages of firing in a // pottery studio. #include #include #include #define MAX_NAME_LENGTH 64 #define NUM_FIRINGS 5 enum stage { GREENWARE, LEATHER_HARD, BISQUE_FIRED, GLAZE_FIRED }; struct ceramic_piece { char name[MAX_NAME_LENGTH]; enum stage stage; struct ceramic_piece *next; }; struct studio { struct ceramic_piece *progress_pieces; struct ceramic_piece *pieces_for_sale; }; // Student functions void add_piece(struct studio *studio, char *name); void fire_pieces(struct studio *studio); void free_studio(struct studio *studio); // Helper functions struct ceramic_piece *create_piece(char *name); void print_studio(struct studio *studio); void print_pieces(struct ceramic_piece *head); const char *stage_to_string(enum stage stage); // ----------------------------------------------------------------------------- //////////////// DO NOT CHANGE THE MAIN FUNCTION /////////////////////////////// int main(void) { struct studio *studio = malloc(sizeof(struct studio)); studio->pieces_for_sale = NULL; studio->progress_pieces = NULL; add_piece(studio, "Tea Bowl"); add_piece(studio, "Coffee Mug"); printf("=== Initial Studio ===\n"); print_studio(studio); for (int i = 1; i <= NUM_FIRINGS; i++) { printf("\n=== After Firing %d ===\n", i); fire_pieces(studio); print_studio(studio); // Add new pieces partway through, so not everything progresses // through the stages together if (i == 1) { add_piece(studio, "Vase"); } if (i == 2) { add_piece(studio, "Bowl"); } } free_studio(studio); return 0; } // ----------------------------------------------------------------------------- // YOUR FUNCTIONS // ----------------------------------------------------------------------------- // Creates a new ceramic piece by allocating and initialising memory struct ceramic_piece *create_piece(char *name) { // TODO: Implement this function printf("create_piece() not implemented yet!\n"); return NULL; } // Creates and appends a new piece with the given name to the // studio's progress pieces. void add_piece(struct studio *studio, char *name) { // TODO: Implement this function printf("add_piece() not implemented yet!\n"); } // Fires all progress pieces to the next stage void fire_pieces(struct studio *studio) { // TODO: Implement this function printf("fire_pieces() not implemented yet!\n"); } // Frees all memory associated with the studio void free_studio(struct studio *studio) { // TODO: Implement this function printf("free_studio() not implemented yet!\n"); } // ----------------------------------------------------------------------------- // PROVIDED FUNCTIONS // ----------------------------------------------------------------------------- //////////////// DO NOT CHANGE ANY OF THE CODE BELOW HERE ////////////////////// const char *stage_to_string(enum stage stage) { if (stage == GREENWARE) { return "GREENWARE"; } if (stage == LEATHER_HARD) { return "LEATHER_HARD"; } if (stage == BISQUE_FIRED) { return "BISQUE_FIRED"; } return "GLAZE_FIRED"; } void print_pieces(struct ceramic_piece *head) { if (head == NULL) { printf(" (none)\n"); return; } while (head != NULL) { printf(" %-15s %s\n", head->name, stage_to_string(head->stage)); head = head->next; } } void print_studio(struct studio *studio) { printf("Pieces in progress:\n"); print_pieces(studio->progress_pieces); printf("\nPieces for sale:\n"); print_pieces(studio->pieces_for_sale); }