Question: Write a program in C (GNU GCC (MinGW)) that initializes two parallel arrays as follows: char * String[] = { Abbie, Oakley, Sylvia, Uwe, Ken,

Write a program in C (GNU GCC (MinGW)) that initializes two parallel arrays as follows:

char * String[] = { "Abbie", "Oakley", "Sylvia", "Uwe", "Ken",

"Aaron", "Fabien" }; double GPA[] = {3.8, 3.0, 3.9, 2.0, 2.5, 4.0, 3.2};

Then the program takes the strings and GPAs from the arrays one by one, starting from element index 0, populates the studentRecord structure below and inserts the structure in a linked list which is initially empty. The structure should be inserted in the right location, to maintain the lexicographic order of the strings. The structures in the linked list are printed after every insertion, with the structures being printed in the order they appear in the list. Finally, after all the array elements are inserted, the program should print again the complete content of the linked list, with the structures being printed in the order they appear in the list. If your program is correct, the order in which the strings and GPAs are printed should be:

Aaron, 4.0, Abbie, 3.8, Fabien, 3.2, Ken, 2.5, Oakley, 3.0, Sylvia, 3.9, Uwe, 2.0.

Additional requirements Make sure you meet all the requirements to avoid losing points

1.Follow the requirements in the Homework Notes.

2.To ensure consistency in the submissions, your program must do the following:

Use this self-referential structure

struct studentRecord // Self-referential structure used in linked list

{

char name[NAME_LENGTH + 1]; // set NAME_LENGTH to 10 double GPA;

struct studentRecord * nextPtr;

};

For convenience, use typedefs:

typedef struct studentRecord Student; // Student is an alias for struct studentRecord

typedef Student * studPtr; // studPtr is a pointer to Student

3.To create the Student self-referential structures, your program must use

4.You must populate the linked list through a loop. You are not allowed to create the 7 Students of the list by writing 7 assignment statements, one for each Student in the list

5.Your program must work for any set of strings used as input, not just the ones given

6.You are allowed to use the and functions from the C library (see section 8.6, 8.7 of textbook or the Internet for details). You are only allowed to use functions and features of C that have already been taught in class, or in the hints provided. You will not get credit if you use existing functions in the C library not taught in class, unless explicitly told you are allowed.

7.Your program should implement the functions whose prototypes are given below

// Function prototypes

/**********************************************************/ /* This function inserts newName and newGpa into the linked list pointed by *sPtr

Walks through the list to find the right location for insertion

Insertion is done in lexicographic order of the student's name Note: sPtr is a pointer to a pointer, and *sPtr

points to the first Student of the list, or is NULL if the list is empty */

/**********************************************************/ void insert(studPtr *sPtr, char * newName, double newGpa);

/**********************************************************/ /* Print the Student pointed by myPtr

/**********************************************************/ void printStudent(studPtr myPtr);

/**********************************************************/

/* Prints the elements of the linked list pointed by myPtr */ /**********************************************************/ void printList(studPtr myPtr);

8. Pseudocode for the program

1- Create a linked list of self referential structures (each self referential structures is called Student) and initialize the list to empty

2- Take the strings from String[] and the GPA from GPA[] one by one, and for each (string, GPA) do the following

Call insert

Call printList

3 Call printList

Reference implementations

You are allowed to use and adapt as needed the example implementations for a linked list (insert, printList, etc.) in the Unit7-1 lecture slides.

Lexicographic order of character strings

Let a and b two strings of characters. Assume first that they have the same number of characters: a1a2...akb1b2 ... bk

Rule 1 - If at the first i where ai and bi differ, the character ai bi, then a

Rule 2 - If at the first i where ai and bi differ, the character ai > bi, then a > b.

Rule 3 - If ai = bi for all i

Now let us consider the case where the strings do not have the same number of characters. Assume a hask characters and b has m characters, where m > k.

Rule 1 - If at the first i where ai and bi differ, the character ai bi, and i k, then a

Rule 2 - If at the first i where ai and bi differ, the character ai > bi, and i k, then a > b. Rule 3 - If ai = bi for all i

For example, consider the strings "Thomas" and "Thompson". The 5th character is the first that is different in the two strings ('a' vs. 'p'). Because 'a'

Another example is Thomas and Thom. Since all the first four characters match and Thom is shorter, Thom

You are allowed to use the strcmp() function from the C library that compares two strings according to the lexicographic order.

Expected Output

Write a program in C (GNU GCC (MinGW)) that initializes two parallel

Bas 1C part Number of elements in string array = 7 Array contents Stringl0]- String[1] = String[2] String[3] = Stringt41 stringLS string Abbie, Oakley, Sylvia: GPA[0] GPA [ 1] GPA [2] = 3.8 = 3 3.9 Ken, Aaron: Fabien, GPA[4] GPA[5] GPA[6] 2.5 4 3.2 = = Linked list after initialization BEGIN -> END Now insert Abbie List after insertion: BEGIN -> CAbbie, 3.81 -> END Now insert Oakle List after insertion BEGIN -> CAbbie, 3.81 -> COakley, 31 -> END Now insert Sylvia List after insertion: BEGIN-CAbbie, 3.81 COakley, 3] -> CSylvia, 3.91 - END Now insert Uwe List after insertion: BEGIN -> LAbbie, 3.81 -> COakley, 3] -> Sylvia, 3.91 -> CUwe, 2] -> END Now insert Ken List after insertion: BEGIN ->CAbbie, 3. 81 -> CKen, 2.5] -> COakley, 31 -> CSylvia, 3.91 -> Uwe, 21 -> END Now insert Aaron List after insertion: BEGIN -> CAaron, 4] -> LAbbie, 3.81 -> CKen, 2.51- COakley, 31 -> Sylvia, 3.91 -> CUwe, 21 -> END Now insert Fabien List after insertion: BEGIN -CAaron,4] -> CAbbie, 3.8] - CFabien, 3.2] -> CKen, 2. 5]X> [Oakley, 3] -> [Sylvia, 3.9] - [Uwe , 2] -) END Linked list after insertions BEGIN-) [Aaron, 4] -> [Abbie. 3.8] -) [Fabien, 3.21-) [Ken, 2.5] -) Oakley, 31 -> ESylvia, 3.91 -> CUwe, 21 -> END

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!