The goal of this assignment is to build a software library that manages an array of structures. The library contains functions for managing an array of students. Each structure represents a student with the following attributes defined in the students.h header file:
typedef struct student_struct
{
char name[16];
float gpa;
int age;
} Student;
The library that you are building contains the following the following functions. Some of the functions are already implemented for you to give you a significant starting point.
You will need to implement the following three functions.
1) push: Adds a student as the very last item in the students array.
void push(Student s){
//FIXME: Implement function
}
For example, the following code should result in the students array to have 3 students (size = 3) with the following students in indexes 0, 1, 2 respectively {Adam, Beth, and Chris}.
Student a = createStudent("Adam", 3.1, 21);
Student b = createStudent("Beth", 3.0, 20);
Student c = createStudent("Chris", 2.9, 19);
push(a);
push(b);
push(c);
2) findStudent: Searches the current students array and searches for a student with a specific name. If the name is found, the index of that student in the array is returned. If the student's name does not exist in the array, -1 should be returned.
int findStudent(char *name){
//FIXME: Implement function
return -1;
}
For example, the following code should result in the findStudent function return index 1, since the student Beth stored in index 1
Student a = createStudent("Adam", 3.1, 21);
Student b = createStudent("Beth", 3.0, 20);
Student c = createStudent("Chris", 2.9, 19);
push(a);
push(b);
push(c);
int index = findStudent("Beth");
3) insert: The insert function places a new student into that students array at a specific index.
void insert(Student s, int idx)
{
//FIXME: Implement function
}
For example, the following code should result in the students array to have 4 students (size = 4) with the following students in indexes 0, 1, 2, 3 respectively {Adam, Beth, Daphney, and Chris}.
Student a = createStudent("Adam", 3.1, 21);
Student b = createStudent("Beth", 3.0, 20);
Student c = createStudent("Chris", 2.9, 19);
push(a);
push(b);
push(c);
Student d = createStudent("Daphney", 3.7, 20);
insert(d, 2);
If you implement the functions above successfully, you should get the following output using the existing main function. Note, many of the functions have been implemented for you already such as the destroy and get functions..
--- TESTING PUSH: Displaying Array Contents ---
Adam, 3.100000, 21
Beth, 3.000000, 20
Chris, 2.900000, 19
Daphney, 3.700000, 20
Erin, 3.500000, 18
Fred, 2.800000, 19
--- TESTING FINDSTUDENT ---
Student Daphney is located in array index: 3
--- TESTING GET ---
Student Daphney information: Daphney, 3.700000, 20
Inserting Student Greg at index 3
--- TESTING INSERT: Displaying Array Contents ---
Adam, 3.100000, 21
Beth, 3.000000, 20
Chris, 2.900000, 19
Greg, 2.800000, 18
Daphney, 3.700000, 20
Erin, 3.500000, 18
Fred, 2.800000, 19
Deleting Student Located at index 3
--- TESTING DELETE: Displaying Array Contents ---
Adam, 3.100000, 21
Beth, 3.000000, 20
Chris, 2.900000, 19
Daphney, 3.700000, 20
Erin, 3.500000, 18
Fred, 2.800000, 19