Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

INSTRUCTOR SUPPLIED DRIVER FILE: #define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE #include #include #define Elements(array) (sizeof(array)/sizeof((array)[0])) int Compare(const void *elemA, const void *elemB); void SortStudents(const char *studentList[], size_t

image text in transcribed

image text in transcribed

INSTRUCTOR SUPPLIED DRIVER FILE:

#define INSTRUCTOR_FILE #ifdef INSTRUCTOR_FILE

#include #include

#define Elements(array) (sizeof(array)/sizeof((array)[0]))

int Compare(const void *elemA, const void *elemB); void SortStudents(const char *studentList[], size_t studentCount); void DisplayClassStatus(const char *registrants[], size_t registrantCount, const char *attendees[], size_t attendeeCount);

int main(void) { const char *registrants0[] = { "Xenon Man", "Wonder Woman", "The Green Lantern", "The Flash" }; const char *attendees0[] = { "The Flash", "The Green Lantern", "Wonder Woman", "Xenon Man" }; const char *registrants1[] = { "Al", "Tough Guy", "Mae East", "Bill", "Avenger", "Jo", "Mary", "Agitation King", "Elvis", "Zabo The Great", "Slim Jim", "Stinky The Clown", "Carl Crumb", "What's On Second", "Aces Wild", "Night Flyer" }; const char *attendees1[] = { "Al", "Tough Guy", "Mae East", "Bill", "Jo", "Mary", "Petty Patty", "Elmer Fudd", "Elvis", "Slim Jim", "Stinky The Clown", "Carl Crumb", "Ned Nasty", "Who's On First", "Aces Wild", "Night Flyer", "Carl Clean" };

// Initial test of comparison function if (Compare(®istrants0[1], ®istrants0[0]) >= 0 || Compare(®istrants0[0], ®istrants0[0]) != 0 || Compare(®istrants0[0], ®istrants0[1])

// Display status of class #0 before sorting registrants and attendees. printf("Class #0 before sorting: "); DisplayClassStatus(registrants0, Elements(registrants0), attendees0, Elements(attendees0)); printf(" "); SortStudents(registrants0, Elements(registrants0)); SortStudents(attendees0, Elements(attendees0));

// Display status of class #0 after sorting registrants and attendees. printf("Class #0 after sorting: "); DisplayClassStatus(registrants0, Elements(registrants0), attendees0, Elements(attendees0)); printf(" ");

// Display status of class #1 before sorting registrants and attendees. printf("Class #1 before sorting: "); DisplayClassStatus(registrants1, Elements(registrants1), attendees1, Elements(attendees1)); printf(" "); SortStudents(registrants1, Elements(registrants1)); SortStudents(attendees1, Elements(attendees1));

// Display status of class #1 after sorting registrants and attendees. printf("Class #1 after sorting: "); DisplayClassStatus(registrants1, Elements(registrants1), attendees1, Elements(attendees1)); printf(" End of Class Reports ");

return EXIT_SUCCESS; } #endif

C2A6E3 (6 points - Program) Exclude any existing source code files that may already be in your IDE project and add a new one, naming it C2AE3 DisplayClassStatus.c. Also add instructor supplied source code C2A6E3_main-Driver.c. Do not write a main function! main already exists in the instructor supplied file and it will use the code you write. A certain school keeps two sets of student names for every class taught. One set is for individuals who have registered (registrants) and the other is for individuals registered or not) who have attended the first class meeting attendees). Each set is kept in an appropriately-named ragged amay as follows: const char *names[] = { "1", "Ned Nasty", "Sweet L. Sally", etc. }; File C2AE3 DisplayClassStatus.c must contain functions named Compare, SortStudents, and DisplayClassStatus. Compare syntax int Compare (const void *elena, const void elem); Parameters: elemA-a pointer to an element of a names array elemB-a pointer to an element of a names array Synopsis: Compares the names represented by elen Aandelen using the standard library function strump- Return: O if the name reprezented by elemA is less than the name represented by elemB: O if the name represented by elemA is equal to the name represented by elemB: > if the name represented by elemA is greater than the name represented by elen. Sort Students syntax void SortStudents (const char *studentList[], size_t student Count); Parameters: student List - A pointer to the first element of a names array student Count - The number of elements in the array Synopsis: Use: the standard library sort function and the Compare function above to sort the amay in student List into alphabetical order. No variable: other than the two parameters may be declared Return: vold DisplayClassStatus syntax void DisplayClassStatus( const char *registrant:[], size_t registrant Count, const char attendees[], size_t attendeeCount); Parameters: registrants-pointer to the first element of a registrants names arrey registrant Count - the number of elements in the registrants names array attendees-pointer to the first element of an attendees names array attendeeCount - the number of elements in the attendees names array Synopsis: 1. Determines and displays which of the registrants did not attend the first meeting by repeatedly calling the standard library bsearch function to search the attendees array for each name in the registrants array 2. Determines and displays which of the attendees were not registered by repeatedly calling bsearch to search the registrants amay for each name in the attendee: array. 2. Do not sort any arrays. Simply search them "as is". 4. Results must be displayed in the following format, using the phrase: "Not present," and "Not registered:" as shown to differentiate the two groupings. Not present : Orphan Annie Toto The Dog Madonna Not registered: Little Mary Big John Tiny Tim Return: vold The same comparison function must be used for both qsort and bsearch. IMPORTANT: One purpose of this exercise is to illustrate the erroneous results that are usually obtained when bsearch is used on an unsored array. My driver code wil accomplish this by calling your DisplayClassStatus function both before and after coling your SortStudents function. For this reason your DisplayClassStatus function must do no sorting Submitting your solution Send both source code files to the assignment checker with the subject line C2A6E3_ID, where ID is your 9-character UCSD student ID. See the course dooument titled "How to Prepare and Submit Assignments for additional exercise formatting, submission, and assignment cheoker requirements. Hints: The first argument of bsearch must always be the address of le pointer to) the object to be searched for, not the value of that object

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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions