Question
Help! impl.h enum {FALSE=0, TRUE}; typedef enum {NAME, BIRTHDATE, GPA} PersonField; #define MAXBUFF 1024 // maximum size of string buffer for input file typedef struct
Help!
impl.h
enum {FALSE=0, TRUE}; typedef enum {NAME, BIRTHDATE, GPA} PersonField;
#define MAXBUFF 1024 // maximum size of string buffer for input file
typedef struct person_t Person; typedef Person *PersonPtr; typedef char *Cstring;
typedef struct { // basic date structure. Little to no error checking! Beware. int month; // month 1-12 int day; // day 1-31 int year; // year (e.g., 2018) } Date;
struct person_t { Cstring name; Date birthDate; float gpa; PersonPtr next; };
int list_len(PersonPtr a); int list_cmp(PersonPtr a, PersonPtr b); PersonPtr list_clone(PersonPtr src); void list_free(PersonPtr a); PersonPtr list_add(PersonPtr head, Cstring name, int month, int day, int year, float gpa, PersonField field); PersonPtr list_from_file(FILE *fd, PersonField field);
/* FUNCTIONS BELOW ARE PROVIDED by utils.c */
int compare_by_field(PersonPtr a, PersonPtr b, PersonField field); int compare_people (PersonPtr a, PersonPtr b); void print_list(PersonPtr head); Cstring copyCString(Cstring src);
impl.c
#include
int list_len(PersonPtr head) { /* ** Return the number of nodes in a linked list. ** ** Arguments: PersonPtr head (a PersonPtr to the head of the list) ** ** Returns: The number of nodes in the list. */ return -1; }
int list_cmp(PersonPtr a, PersonPtr b) { /* ** compare the contents of two linked Person lists. If every data member (not pointers) of each node of list 'a' is equivalent ** to the corresponding member of the same node of list 'b', then return TRUE. Otherwise, return FALSE. ** ** Arguments: PersonPtr a, PersonPtr b (pointers to the head node of each list) ** ** Returns: TRUE if the lists are equivalent, FALSE if they are not. ** */
return FALSE; }
PersonPtr list_clone(PersonPtr src) { /* ** Make a "clone" of an existing linked list of "people" structures. ** ** Arguments: PersonPtr src (a pointer to the first node in a list) ** ** Returns: a PersonPtr to the newly copied list. ** */ return NULL; }
void list_free(PersonPtr a) { /* ** Free a linked list. ** ** Arguments: PersonPtr a (the linked list to free) ** ** Returns: nothing */ }
PersonPtr list_add(PersonPtr head, Cstring name, int month, int day, int year, float gpa, PersonField field) {
/* ** Add a person to a linked list in "field" order. ** ** Arguments: ** PersonPtr head // the head of the linked list to add a node to. ** Cstring name // the name member of the person struct ** month, day, year // birthdate info for the person struct. We are not worrying about date validation. ** float gpa // the gpa for the person struct ** PersonField field // specifies the order in which the new node should be added ** (e.g., if field==NAME, add node in alpha order by name, and so on). ** ** Returns: ** PersonPtr New head node of list */
return NULL; }
PersonPtr list_from_file(FILE *fd, PersonField field) { /* ** Return a new list based on lines from a file, each with one person record, ** ** Arguments: ** FILE *fd // Pointer to an open file with rows like: Name Month Day Year gpa ** PersonField field // which field to sort by ** ** Returns: ** PersonPtr to head of new linked list, or NULL on error. ** */
return NULL; }
main.c
#include
int tests_run = 0; // global variable used by minunit int main(int argc, char **argv) { char *result = all_tests(); if (result != 0) { printf("%s ", result); } else { printf("ALL TESTS PASSED "); } printf("Tests run: %d ", tests_run); return result != 0; }
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