Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / / = = = = = = = = = = = = PART 1 : FIXED code = = = = =
PART : FIXED code
DON'T CHANGE THIS PART
#include
#include
#define MAXWORDCHAR
#define GPA "GPA"
#define DATE "DATE"
struct Date
int year;
int month;
int day;
;
typedef struct Date Date;
struct Node
Date dob;
float gpa;
struct Node next;
;
typedef struct Node Node;
void readDataFILE char float Node Node ;
Node mergeListNode Node ;
Node filterListNode char float;
Node reverseListNode ;
void printListNode ;
int main
FILE fp fopenDATAINr;
Node headL NULL;
Node headL NULL;
char controlString;
float targetGPA;
readDatafp &controlString, &targetGPA, &headL &headL;
printListheadL;
printf
;
printListheadL;
printf
;
Node head mergeListheadL headL;
head filterListhead controlString, targetGPA;
head reverseListhead;
printListhead;
fclosefp;
PART : Student works
Define supported functions here.
int strLenchar word
int i ;
while word i
i;
return i;
Node swapNode ptr Node ptr
Node tmp ptrnext;
ptrnext ptr;
ptrnext tmp;
return ptr;
Node readOneLineFILE fp
TODO: read data of student date of birth and GPA in 'one line'
The new node will be inserted at the end of list
return the head of this list.
Node head NULL;
Node pre NULL;
while
int month, day, year;
float gpa;
int res fscanffpdddf
&month, &day, &year, &gpa;
if res
res EOF break;
Node newnode Node mallocsizeofNode;
newnodedob.year year;
newnodedob.month month;
newnodedob.day day;
newnodegpa gpa;
newnodenext NULL;
if head NULL
head newnode;
else
prenext newnode;
pre newnode;
return head;
void readDataFILE fp char controlString float targetGPA Node headL Node headL
TODO: read data with file pointer fp:
LINE: controlString targetGPA
LT or GTfloat number
LINE: headL is the head of list
LINE: headL is the head of list
controlString malloc;
Read controlString and targetGPA from the first line of the file
fscanffps fcontrolString targetGPA;
fgetcfp;
headL readOneLinefp;
headL readOneLinefp;
Node mergeListNode headL Node headL
TODO: add list into the end of list return the head of result list
if headL NULL return headL;
Node cur headL;
while curnext NULL
cur curnext;
curnext headL;
return headL;
Node filterListNode head char controlString float targetGPA
TODO: Filter the third list based on GPA criteria.
If controlString is LT filter the students with a GPA less than targetGPA.
If controlString is GT filter the students with a GPA greater than targetGPA.
return head of filtered list
Node cur head;
Node pre NULL;
while cur NULL
if controlStringG && curgpa targetGPAcontrolStringL && curgpa targetGPA
if pre NULL
head curnext;
else
prenext curnext;
Node temp cur;
cur curnext;
freetemp;
else
pre cur;
cur curnext;
return head;
Node reverseListNode head
TODO: reverse the list
return the new head
Node pre NULL;
Node cur head;
Node next NULL;
while cur NULL
next curnext;
curnext pre;
pre cur;
cur next;
return pre;
void printListNode head
TODO: print the linked list to stdout
Node cur head;
while cur NULL
if cur head
printfdddf curdob.month, curdob.day, curdob.year, curgpa;
else
printfdddf curdob.month, curdob.day, curdob.year, curgpa;
cur curnext;
SAMPLE INPUT
GT
abcdkkdsdaa dfgrg
afd xekdldw
SAMPLE OUTPUT
I didn't get the same output, can you fix my code?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started