int main(void) { Student students[4]; students[0].last = "Tramm"; students[0].first= "John"; students[0].gpa = 1.9; students[1].last = "Siegel"; students[1].first= "Andrew"; students[1].gpa = 1.8; students[2].last = "Tchoua"; students[2].first= "Roselyne"; students[2].gpa = 3.9; students[3].last = "Siegel"; students[3].first= "Robert"; students[3].gpa = 3.95; printf("Unsorted Students:\n"); print_students(students, 4); printf("Students sorted by name:\n"); sort_students_by_name(students, 4); print_students(students, 4); printf("Students sorted by gpa:\n"); sort_students_by_gpa(students, 4); print_students(students, 4); return 0; }
void print_students(student_node *head) { student_node *iterator = head; if (iterator->current != NULL) { //printf("Student number: %d name: %s\n", iterator->current->student_number, iterator->current->firstName); print_student(iterator->current); } if(iterator->next != NULL){ print_students(iterator->next); } }
void print_all_students_for_course(database *myDatabase, int course_number) { course *myCourse = get_course(course_number, myDatabase->courseList); if (myCourse == NULL) { //courses isn't in the database printf("course number: %d isn't in the database", course_number); return; } printf("Printing all students for course number %d:\n", course_number); student_node *myStudentList = get_courses_for_student(myDatabase->enrollmentList, myCourse); print_students(myStudentList); }
void test_queue_students() { queue struct_queue; queue_new(&struct_queue, sizeof(students_group), students_group_free); // ENQUEUE { students_group group_1; group_1.elem = 4; char* names_1[] = {"Al", "Bob", "Carl", "John"}; const int notas_1[] = {3, 4, 5, 3}; group_1.names = malloc(group_1.elem * sizeof(char*)); group_1.cal = malloc(group_1.elem * sizeof(int)); for (int j = 0; j < group_1.elem; ++j) { group_1.names[j] = malloc((strlen(names_1[j]) + 1)*sizeof(char)); strcpy(group_1.names[j], names_1[j]); group_1.cal[j] = notas_1[j]; } queue_enqueue(&struct_queue, &group_1); } // ENQUEUE { students_group group_2; group_2.elem = 6; const char* names_2[] = {"Lou", "David", "Steven", "Logan", "Popi", "Juno"}; const int notas_2[] = {1, 2, 3, 2, 0, 2}; group_2.names = malloc(group_2.elem * sizeof(char*)); group_2.cal = malloc(group_2.elem * sizeof(int)); for (int j = 0; j < group_2.elem; ++j) { group_2.names[j] = malloc((strlen(names_2[j]) + 1)*sizeof(char)); strcpy(group_2.names[j], names_2[j]); group_2.cal[j] = notas_2[j]; } queue_enqueue(&struct_queue, &group_2); } // DEQUEUE students_group aux; queue_dequeue(&struct_queue, &aux); printf("First element\n"); print_students(&aux, NULL); students_group_free(&aux); // DEQUEUE queue_dequeue(&struct_queue, &aux); printf("Second element\n"); print_students(&aux, NULL); students_group_free(&aux); // ENQUEUE { students_group group_2; group_2.elem = 6; const char* names_2[] = {"Lou", "David", "Steven", "Logan", "Popi", "Juno"}; const int notas_2[] = {1, 2, 3, 2, 0, 2}; group_2.names = malloc(group_2.elem * sizeof(char*)); group_2.cal = malloc(group_2.elem * sizeof(int)); for (int j = 0; j < group_2.elem; ++j) { group_2.names[j] = malloc((strlen(names_2[j]) + 1)*sizeof(char)); strcpy(group_2.names[j], names_2[j]); group_2.cal[j] = notas_2[j]; } queue_enqueue(&struct_queue, &group_2); } { students_group group_2; group_2.elem = 6; const char* names_2[] = {"zzzzzz", "xxxxxx", "yyyyyy", "wwwwww", "uuuuuuu", "pppppp"}; const int notas_2[] = {1, 2, 3, 2, 0, 2}; group_2.names = malloc(group_2.elem * sizeof(char*)); group_2.cal = malloc(group_2.elem * sizeof(int)); for (int j = 0; j < group_2.elem; ++j) { group_2.names[j] = malloc((strlen(names_2[j]) + 1)*sizeof(char)); strcpy(group_2.names[j], names_2[j]); group_2.cal[j] = notas_2[j]; } queue_enqueue(&struct_queue, &group_2); } // DEQUEUE queue_dequeue(&struct_queue, &aux); printf("Third element\n"); print_students(&aux, NULL); students_group_free(&aux); // ENQUEUE { students_group group_2; group_2.elem = 6; const char* names_2[] = {"Lou", "David", "Steven", "Logan", "Popi", "Juno"}; const int notas_2[] = {1, 2, 3, 2, 0, 2}; group_2.names = malloc(group_2.elem * sizeof(char*)); group_2.cal = malloc(group_2.elem * sizeof(int)); for (int j = 0; j < group_2.elem; ++j) { group_2.names[j] = malloc((strlen(names_2[j]) + 1)*sizeof(char)); strcpy(group_2.names[j], names_2[j]); group_2.cal[j] = notas_2[j]; } queue_enqueue(&struct_queue, &group_2); } // ENQUEUE { students_group group_2; group_2.elem = 6; const char* names_2[] = {"AAA", "BBB", "CCC", "DDD", "EEE", "FFF"}; const int notas_2[] = {1, 2, 3, 2, 0, 2}; group_2.names = malloc(group_2.elem * sizeof(char*)); group_2.cal = malloc(group_2.elem * sizeof(int)); for (int j = 0; j < group_2.elem; ++j) { group_2.names[j] = malloc((strlen(names_2[j]) + 1)*sizeof(char)); strcpy(group_2.names[j], names_2[j]); group_2.cal[j] = notas_2[j]; } queue_enqueue(&struct_queue, &group_2); } for (int i = 0; i < 3; ++i) { students_group aux; queue_dequeue(&struct_queue, &aux); printf("Inside 'for' element\n"); print_students(&aux, NULL); students_group_free(&aux); } queue_dispose(&struct_queue); }
void print_students_from_database(database *myDatabase) { print_students(myDatabase->studentList); }