#include "class.h" #include "teacher.h" #include "student.h" #include #include #include struct Teacher; struct Student; struct Class { char name[50]; int capacity; int size; struct Teacher* t; struct Student** student_arr; }; struct Class* new_class(char* name, int cap, struct Teacher* t) { struct Class* c = (struct Class*) malloc (sizeof(struct Class)); if (c == NULL) return NULL; strncpy(c->name, name, 49); c->name[49] = '\0'; c->capacity = cap; c->t = t; c->size = 0; c->student_arr = NULL; return c; } void change_teacher(struct Class* c, struct Teacher* t) { c->t = t; } void add_student(struct Class* c, struct Student* s) { if (c == NULL || s == NULL) return; int new_size = c->size + 1; struct Student** temp = (struct Student**) realloc(c->student_arr, new_size * sizeof(struct Student*)); if (temp == NULL) { return; } c->student_arr = temp; c->student_arr[c->size] = s; c->size = new_size; } void print(struct Class* c) { int size = c->size; printf("Class Name: %s, Students: %d", c->name, size); }