Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #include #include "impl.h"

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 #include #include "minunit.h" #include "test_simple_linked_list.h"

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

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

Students also viewed these Databases questions

Question

5. If yes, then why?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago