Question: Implementation of a Linker List You will build a C language program that reads student information from a file, populates each student as a record

Implementation of a Linker List

You will build a C language program that reads student information from a file, populates each student as a record in a linked list, and has some code to read/report values from the linked list data structure.

Starter Code: You should use this following starter code to begin this assignment. Test cases are included in the starter code.

You just need to fill the " TO DO" spaces of the code :

#include  #include  #include  typedef struct student_struct { char name[16]; int age; float gpa; struct student_struct *next; } Student; Student head; //The head of the linked list /* Given the student values, initialize a structure, and return a pointer to the struct */ Student *makeStudent(char name[16], int age, double gpa) { //TO DO: Implement this function return NULL; //Change return value.... } /* Inserts an element to the front of the linkedList */ void push(Student *student) { //TO DO: Implement this function } /* Traverses the linked list and returns the student with the best GPA */ Student *findTopStudent() { //TO DO: Implement this function return NULL; //Change return value } /* Traverses the linked list and returns the average GPA across all students */ float getAverageGPA() { //TO DO: Implement this function return 0.0; //Change return value } int main(int argc, char **argv) { if(argc != 2){ perror("ERROR: Wrong number of command line args! "); return -1; } head.next = NULL; //initialize that the linked list is empty. FILE * file; file = fopen(argv[1] , "r"); if (!file){ perror("ERROR opening file! "); return -1; } //-------------------------------------------------  // TO DO: Change main method code BELOW  char s1[16]; char s2[16]; char s3[16]; while (fscanf(file, "%s %s %s", s1,s2,s3)!=EOF) { printf("READING FILE LINE: %s %s %s ",s1, s2, s3); } fclose(file); // TO DO: Change main method code ABOVE //------------------------------------------------- Student *topStudent = findTopStudent(); printf("The Student with the best GPA is: %s ", topStudent->name); printf("The average GPA is: %.2f ", getAverageGPA()); return 0; }

The starter code is designed to run with a single command line argument that corresponds to the test file. If the file is not in the same directory, you will get an error message that the file is not found.

Implementation of a Linker List You will build a C language program

Implement the following functions (found in the starter code):

Student *makeStudent(char name[16], int age, double gpa);

void push(Student *student);

Student *findTopStudent();

float getAvergeGPA();

Each function should perform the following tasks

makeStudent: Given the student values, initialize a structure, and return a pointer to the struct

push: Inserts an element into the linkedList

findTopStudent: Traverses the linked list and returns the student with the best GPA

getAverageGPA: Traverses the linked list and returns the average GPA across all students

main: Change the main appropriately to call each function and obtain the desired results.

For this assignment, do not change the function prototypes to get your code to work.

Test Cases: If you implemented your assignment correctly, you should get the following results :

Test Case #1 (data1.txt):

that reads student information from a file, populates each student as a

Test Case #2 (data2.txt):

record in a linked list, and has some code to read/report values

Test Case #3 (data3.txt):

from the linked list data structure. Starter Code: You should use this

user@a5c9a98fcd15:/projects/Hw4$ gcc -o hw4 hw4.c user@a5c9a88fcd15:/projects/HW4$ ./hw4 data1.txt READING FILE LINE: Mary 23 3.5 READING FILE LINE: Jane 34 3.6 READING FILE LINE: Mark 23 3.3 READING FILE LINE: Joe 23 2.5 READING FILE LINE: Bill 23 1.3 READING FILE LINE: Sam 23 2.1 READING FILE LINE: Rebecca 23 3.9 READING FILE LINE:Lowie 23 2.8 READING FILE LINE: Will 23 3.1 READING FILE LINE: John 23 2.2 READING FILE LINE: Bonnie 23 3.2 The Student with the best GPA is: (null) The average GPA is: 0.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!