Question: C++ Code Earthquake Report Modify the bubble-sort function (Attached below) from last weeks lab exercise to sort the rows of a two dimensional array in

C++ Code

Earthquake Report

Modify the bubble-sort function (Attached below) from last weeks lab exercise to sort the rows of a two dimensional array in descending order of the first element in each row. That is, as it sorts the first element in each row, it should move entire rows so that each row of data stays as a row throughout the sort.

Next, read the earthquake data and store only the magnitude and location in a two dimensional array with n rows and two columns. Now sort the earthquake data in descending order of magnitude, and print out a list of all the earthquake magnitudes and their associated locations in order from the highest to the lowest. Note you will need to store the magnitude data as a string object in the array, but use its equivalent floating-point value for the comparison. Can you describe why? [Hint: you can use the atof() or stod() function in your sort comparison. ]

bubble-sort function:

#include #include #include #include #include #include #include

using namespace std;

void b_sort (int arr[], int n)

{

for (int i = 0; i < n; ++i)

for (int j = 0; j < n - i - 1; ++j)

if (arr[j] > arr[j + 1])

{

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

}

}

//Driver Function

int main()

{

int list[50]; int n; n=100; for(int i=0; i<50; i++){ list[i]=n; n--;} cout << "Input Array : " <

//to print 5 elements per row for (; i < 50;){ /* prints i, i+1 and i+2 */

cout << list[i] << ' ' << list[i+1] << ' ' << list[i+2] << ' ' << list[i+3] << ' ' << list[i+4] << ' '<

i += 5; /* adds 5 to i each time */}} cout<

b_sort (list, 50);

cout << "Sorted Array : " <

for (int i = 0; i < 50; ++i){ for (; i < 50;){ /* prints i, i+1 and i+2 */

cout << list[i] << ' ' << list[i+1] << ' ' << list[i+2] << ' ' << list[i+3] << ' ' << list[i+4] << ' '<

i += 5; /* adds 5 to i each time */

}}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!