Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c++ COSC 1550 - Computer Programming I Program Assignment # 15 PURPOSE The purpose of this assignment is to give you the opportunity to
in c++
COSC 1550 - Computer Programming I Program Assignment \# 15 PURPOSE The purpose of this assignment is to give you the opportunity to write a program that requires two different sorting methods. PROGRAM REQUIREMENTS Use the program name listed below when creating your program .cpp file(s). Failure to do so will result in point deductions. Also be sure to include in a comment in each program the assignment number, the program name, your name, and the due date. Again, failure to do so will result in point deductions. Program PGM-08-02.cpp Sorting (50 points) This program will read a file of numbers (number.txt) and place the numbers into an array. Then it will sort the array in ascending sequence using the bubble sort algorithm. In doing that, it will also count the number of swaps that were made to get the data sorted. The array will be printed before sorting and again after sorting. Also, the swap count will be displayed. Then the program will sort the data into ascending sequence using the selection sort algorithm. Since it must use the original out of sequence array, the program will have to create a copy of the original array before it is sorted. This array will be printed before sorting and again after sorting. Also, the swap count will be displayed. The final step is to display a summary of the number of swaps for each sorting algorithm. The program must include the following four functions: 1. void swap(int \&, int \&) - This function swaps two adjacent elements of an array. 2. int bubblesort(int [], int) - This function sorts an array in ascending order using the bubble sort algorithm and returns the number of swaps required. 3. void displayArray(int[], int) - This function displays the contents of an array. The display must include the index of each element and the value of each element. 4. int selectionsort(int[], int) - This function sorts an array in ascending order using the insertion sort algorithm and returns the number of swaps required. Additional Requirement: Use the following to declare the size of the arrays: constintSIZE=200; The following is the program using a much smaller number of values in the input file (aFewNumbers.txt). The array before sorting with the bubble sort follows Element 0=42 Element 1=4 Element 2=465 Element 3=903 Element 4=154 Element 5=293 Element 6=383 Element 7=668 Element 8=300 Element 9=36 Element 10=895 The array after sorting with the bubble sort follows Element 0=4 Element 1=36 Element 2=42 Element 3=154 Element 4=293 Element 5=300 Element 6=383 Element 7=465 Element 8=668 Element 9=895 Element 10=903 The bubble sort required 21 swaps The array before sorting with the selection sort follows Element 0=42 COSC 1550 - Computer Programming I Page 3 Element 1=4 Element 2=465 Element 3=903 Element 4=154 Element 5=293 Element 6=383 Element 7=668 Element 8=300 Element 9=36 Element 10=895 The array after sorting with the selection sort follows Element 0=4 Element 1=36 Element 2=42 Element 3=154 Element 4=293 Element 5=300 Element 6=383 Element 7=465 Element 8=668 Element 9=895 Element 10=903 The selection sort required 10 swaps In summary, the bubble sort required 21 swaps and the selection sort required 10 swapsStep 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