I need help on building this program It has to be written in

I need help on building this program. It has to be written in language C

Write a program that initializes two parallel arrays as follows: char String [1 \"Abbie\", \"Oakley\", \"Sylvia\", \"Uwe\", \"Ken\", \"Aaron\", \"Fabien\" double GPA 13.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, so as 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.

Solution

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define NAME_LENGTH 15

using namespace std;

struct studentRecord

{

char name[NAME_LENGTH + 1];

struct studentRecord * nextPtr;

};

typedef struct studentRecord Student;

typedef struct studentRecord * studPtr;

//Function prototype

void insert(studPtr *sPtr, char **newName);

int deleteStudent(studPtr *sPtr, Student myStud);

void printStudent(studPtr myPtr);

void printList(studPtr myPtr);

int main(void)

{

char *studentname[] = { \"Abbie\", \"Aaron\", \"Fabien\" ,\"Oakley\", \"Sylvia\", \"Uwe\", \"Ken\"};

studPtr startPtr = NULL;

insert(&startPtr, studentname);

printList(startPtr);

system(\"pause\");

}

void insert(studPtr *sPtr, char **newName)

{

int i;

studPtr newPtr = (studPtr)malloc(sizeof(studPtr));

if (sPtr != NULL)

{

for (i = 0; newName[i] != \'\\0\'; i++)

{

strcpy(newPtr->name, newName[i]);

newPtr->nextPtr = NULL;

studPtr previousPtr = NULL;

studPtr myPtr = *sPtr;

while (myPtr != NULL && strcmp(newPtr->name, newName[i]) > myPtr->name[i])

{

previousPtr = myPtr;

myPtr = myPtr->nextPtr;

}

if (previousPtr == NULL)

{

newPtr->nextPtr = *sPtr;

*sPtr = newPtr;

}

else

{

previousPtr->nextPtr = newPtr;

newPtr->nextPtr = myPtr;

}

}

}

else

{

printf(\"No space.\ \");

}

}

void printList(studPtr myPtr)

{

if (myPtr = NULL)

{

puts(\"List is empty.\ \");

}

else

{

puts(\"The list is: \");

while (myPtr != NULL)

{

printf(\"%s -> \", myPtr->name);

myPtr = myPtr->nextPtr;

}

puts(\"NULL\ \");

}

}

I need help on building this program. It has to be written in language C Write a program that initializes two parallel arrays as follows: char String [1 \
I need help on building this program. It has to be written in language C Write a program that initializes two parallel arrays as follows: char String [1 \
I need help on building this program. It has to be written in language C Write a program that initializes two parallel arrays as follows: char String [1 \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site