Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Organize your files into folders by lab assignment. For this assignment, create a folder called Lab3. 2 Create a file named lab3.c. Copy the

image text in transcribed
image text in transcribed
image text in transcribed
1. Organize your files into folders by lab assignment. For this assignment, create a folder called Lab3. 2 Create a file named lab3.c. Copy the following code into your program. This is the outline of your "test program. You will modify this file as you go through the process of wniting and testing the functions in this assignment. You may The comments are there to show examples of what you might do to test your other functions #include $include #include #include "helpe r functions .h" "sorting functions . h" #de fine ARRAYS IZE 60 int main (void) t // declare an array of "ze ARRAYSIZE int array [ARRAYSIZE] // fill the array with random integers in the range of 1 to 999 inclusive // print the array, 10 elements per line, field size 5 /sort the array using selection sort and // print the number of comparisons that are made // print the array, 10 elements per line, field sizes I/ fill the array again with random integers in the range of 10 to 500 inclusive // print the array, 12 elements per line, field size4 // sort the array with insertion sort and // print the number of comparisons that are made // print the array, 12 lements per line, field size 4 )// end function main / sort the array using selection sort and // print the number of comparison that are made // print the arzay, 10 elementa per line, field size 5 // fill the array again with random integers in the range of 10 to 500 inclusive // print the array, 12 elements per line, field size 4 // sort the array with insertion sort and // print the number of comparisons that are made // print the array, 12 elements per line, field size 4 ) 1/ end function main 3. Create a file called helperfunctions.h Place a preprocessor wrapper in the header fileto prevent the code in the header file from being included twice. See Writing a Preprocessor Wrapper document for help. Then, insert the following prototypes. void swap int tnumiPer, int num2Ptr)i void fillArray( int data, size t length, int min, int max void neatPrint int datal1. size t length, int numPertine, int fieldsize 4. Create a file called helperfunctions.c Write the implementation of the three functions void neatprint ( int data[], size-t length, nt numPerLne, int fields ize ); Prints the array elements in nice, neat columns using the parameters numPerLine and fieldSize to control the layout. void fillArray ( int data [], ze-t length, int min, int max ); Fills the array elements with random integers in the range min to max (inclusive). void awap (int "num1Ptr, int num2Ptr) Exchanges the contents of the two memory locations. 5. Create a file called sortingfunctions.h Write a preprocessor wrapper (see Writing a Preprocessor Wrapper document for help) then insert the following prototypes. int selectionSort int const data, size_t length int insertionsort int * const data, size_t length ); Note: selection sort and insertion sort are explained and implemented in Appendix D. You need to modify the code for these functions to meet the specifications for this assignment 6. Create a file called sortingfunctions.c Write the implementation of the following two functions: int selectionsort int data[, size t length) The functions should do the following: 1) Sort the array using the selection sort algorithm. 2) When a swap is needed, you must call your swap function (defined in your helperfunctions.c file). 3) The return value is a count of the number of comparisons that are made. Specifically, you should count the number of times that an if statement compares the value of an array element. int insertionsort ( nt data[], size_t length ); The functions should do the following: 1) Sort the array using the insertion sort algorithm. 2) When a swap is needed, you must call your swap function (defined in your helperfunctions.c file) 3) The return value is a count of the number of comparisons that are made. Specifically, you count the number of times that an it statement compares the value of an array element

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

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

ISBN: 1844804526, 978-1844804528

More Books

Students also viewed these Databases questions