Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Design And Implementation

Authors: Shouhong Wang, Hai Wang

1st Edition

1612330150, 978-1612330150

More Books

Students also viewed these Databases questions

Question

What do you understand by the term the psychological contract?

Answered: 1 week ago

Question

2. How much time should be allocated to the focus group?

Answered: 1 week ago

Question

1. Where will you recommend that she hold the focus group?

Answered: 1 week ago