Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Write a C program to implement the following requirement: Input: The program will read data from a text file named DATA.IN which has 3

Write a C program to implement the following requirement:
Input: The program will read data from a text file named "DATA.IN" which has 3 lines:
- The first line consists of a string C (either string LT or string GT) and a float number D
which are separated by a single white space
- The second line contains student data, where each student's information is separated by
white spaces. Each student's data includes their date of birth in the format MM/DD/YYYY
followed by their GPA with a dash ('-') used to separate the date of birth and GPA parts.
The date of birth and GPA are surrounded by non-digit characters.
- The third line also contains student data in the same format as the second line.
For example, given a string S = 'abcd11/11/2004ass-abvc3.43pldl', the extracted date would be
'11/11/2004' and the extracted GPA would be 3.43.
Requirement: Complete the functions provided in the attached template to accomplish the
following tasks:
1. Read student data from DATA.IN. Store each students data as a node in a linked list.
There are 2 linked lists. The first list consists of the data of students on line 2. The
second list consists of the data of students on line 3.
2. Merge two linked lists into a single list (third list).
3. Filter the third list based on GPA criteria.
a. If C is "LT", filter the students with a GPA less than D.
b. If C is "GT", filter the students with a GPA greater than D.
4. Reverse the third list.
5. Print each linked list to stdout, where each node is represented as (MM/DD/YYYY,A.BC)
separated by space ('') and print each linked list on one line.
Template:
///============ PART 1: FIXED code ==========///
///====== DON'T CHANGE THIS PART ============///
#include
#include
#define MAX_WORD_CHAR 100
#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 readData(FILE *, char **, float *, Node **, Node **);
Node *mergeList(Node *, Node *);
Node *filterList(Node *, char *, float);
Node *reverseList(Node *);
void printList(Node *);
int main()
{
FILE *fp = fopen("DATA.IN","r");
Node *headL1= NULL;
Node *headL2= NULL;
char *controlString;
float targetGPA;
readData(fp, &controlString, &targetGPA, &headL1, &headL2);
printList(headL1);
printf("
");
printList(headL2);
printf("
");
Node *head = mergeList(headL1, headL2);
head = filterList(head, controlString, targetGPA);
head = reverseList(head);
printList(head);
fclose(fp);
}
///============ PART 2: Student works ==========///
// Define supported functions here.
//
void readData(FILE *fp, char **controlString, float *targetGPA, Node **headL1, Node **headL2)
{
// TODO: read data with file pointer fp:
// LINE1: controlString targetGPA
//(LT or GT)(float number)
// LINE2: headL1 is the head of list
// LINE3: headL2 is the head of list
}
Node *mergeList(Node *headL1, Node *headL2)
{
// TODO: add list 2 into the end of list 1, return the head of result list
}
Node *filterList(Node *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 *reverseList(Node *head)
{
// TODO: reverse the list
// return the new head
}
void printList(Node *head)
{
// TODO: print the linked list to stdout
}GT 3.00
abcd11/11/2014kkdsd-3.47aa 03/11/2000-dfgr4.00g
07/15/2001a-2.48fd xe01/07/2004kdl-dw4.00
SAMPLE OUTPUT 1
11/11/2014,3.4703/11/2000,4.00
07/15/2001,2.4801/07/2004,4.00
01/07/2004,4.0003/11/2000,4.0011/11/2014,3.47
SAMPLE INPUT 2
LT 3.50
as01/01/2001-bva3.42 cr=f02/02/2002qx-zd3.78sdf
02/02/2002-s2.47d 03/03/2003d-efdcsq3.92de
SAMPLE OUTPUT 2
01/01/2001,3.4202/02/2002,3.78
02/02/2002,2.4703/03/2003,3.92
02/02/2002,2.4701/01/2001,3.42

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions