Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task: Write a C++ program which generates two arrays of random numbers, sorts them, one using selection sort and one using bubble sort, and outputs

Task: Write a C++ program which generates two arrays of random numbers, sorts them, one using selection sort and one using bubble sort, and outputs the number of iterations, number of swaps, and total microseconds taken for each sorting algorithm as well as the percentage ratio between the times for both algorithms.
image text in transcribed
image text in transcribed
You must have eight functions in addition to the main function: -svap a void function that takes in two integers and swaps their values -selectionsorta vold function that takes in an integer array, the array size, and two counter variables for the total number of iterations and total number of swaps. This fanction must utlize the selection sort algorithm as discussed earlier in class to sort the array - bubblesort -a void function that takes in an integer array, the array size, and two counter variables for the total mamber of iterations and total mmber of swaps. This function must utilize the improved bubble sort algorithm (to be discussed in class) to sort the array timesort a value returning function that takes in an array, the array size, and an algorithm selection, calls either selection sort or babble sort depending on the algorithm selection, and returns the microseconds that it took to sort the array initArray a void returning function that takes in an array and its size seeds the random umber generator, and then populates the array with random mumbers between 1 and MAX max a value returning function that takes in two integers and returnms the maximum percentRatio a value returning funtion that takes in two integers and calculates the percentage difference between them to within 1 decimal place. Use the formula (a )b 100 -printResults a void function that takes in an algorithm id, number of loops, number of swaps, and microseconds and prints out the results as formatted below in the example You must utilize the following preprocessor and main code #include // atoi, exit, rand, srand #include // clock. CLOCKS.PER-SEC #include // setprecision #include // cout, fixed using nanespace std const int MAX 100000; const int RAND SEED 135; const int HICROSECONDS1000000 const int SELECTIONSORT1 const int BUBBLESORT 2

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

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

Students also viewed these Databases questions

Question

years.

Answered: 1 week ago