Question: Assignment Description:? ?In this assignment, you will build a program that reads student information from a file, populates each student as a record in a

Assignment Description:? ?In this assignment, you will build a 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.

Learning Objectives: ?This assignment connects to the following course goals: ? Course Goal #5: ?Improve problem-solving and programming competency by building ever complex programs, specifically through analyzing, designing, implementing, testing and debugging C programs using various data types, loops, branches, arrays, and structs. ? Course Goal #6:? Write programs that manage memory using dynamic memory allocation functions and variables that contain a memory address (pointers). Apply these skills to allocate memory at run-time, and to (a) increase performance by passing addresses to functions instead of copying data, and (b) return more than one value from a function.

Starter Code: ?You should use this starter code posted on Blackboard to begin this assignment. Test cases are included in the starter code. 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.

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.

Be Careful!? ? We will check that your code follows these assignment rules: ? Do not hardcode an array of structures for this assignment. The purpose of the assignment is to learn how to manipulate memory dynamically. ? The data must be stored as a linked list. Do not just read the file and calculate the results while you are reading in the values. Once again, this is to ensure that you are learning how to manipulate memory. ? 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. Make sure that you are not avoiding the conditions above when testing your assignment. We will be checking your code and ensure that it is following those rules when grading. Test Case #1 (data1.txt): Assignment Description:? ?In this assignment, you will build a program that reads

Test Case #2 (data2.txt): student information from a file, populates each student as a record in

Test Case #3 (data3.txt): a linked list, and has some code to read/report values from the

Starter code below:

Starter 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) { //TODO: Implement this function return NULL; //Change return value.... } /* Inserts an element to the front of the linkedList */ void push(Student *student) { //TODO: Implement this function } /* Traverses the linked list and returns the student with the best GPA */ Student *findTopStudent() { //TODO: Implement this function return NULL; //Change return value } /* Traverses the linked list and returns the average GPA across all students */ float getAverageGPA() { //TODO: 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; } //------------------------------------------------- // TODO: 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); // TODO: 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; }
data1.txt
Mary 23 3.5 Jane 34 3.6 Mark 23 3.3 Joe 23 2.5 Bill 23 1.3 Sam 23 2.1 Rebecca 23 3.9 Lowie 23 2.8 Will 23 3.1 John 23 2.2 Bonnie 23 3.2
data2.txt
Mary 21 2.5 Jane 32 3.4 Mark 23 3.2 Joe 32 2.5 Bill 23 1.3 Sam 12 2.1 Rebecca 19 2.1 Lowie 18 2.8 Will 18 3.1 John 22 2.2 Bonnie 21 3.2 Gary 18 3.4 Billy 19 1.5 Steve 17 3.7 Jen 18 2.1 Bob 21 3.4
data3.txt
Mary 21 2.5 Jane 32 3.5 Bill 23 1.3 Steve 17 1.5 Jen 18 2.1 Bob 21 3.4

user@a5c9a08fcd15:/projects/Hw4$ ./hw4 datal.txt The Student with the best GPA is: Rebecca The average GPA is: 2.86 user@a5c9a08fcd15:/projects/HW4$

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!