Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

must compile the program will read names, ages and weights for up to 100 people.

ID: 3635802 • Letter: M

Question

must compile

the program will read names, ages and weights for up to 100 people. This means that you need 3 arrays of 100 elements each. Then it will sort the data based on decreasing weights and finally print a report.

Here is the code for a bubble sort function sorting 1 array:

void sort ( double x[], int n )
{
int i;
bool swapped;

do {
swapped = false;
for ( i = 0; i < n-1; i++ ) {
if ( x[i] > x[i+1] ) {
swap ( x[i], x[i+1] );
swapped = true;
}
}
} while ( swapped );
}





Given appropriate input data you should produce a report like this one:

Name Age Weight
----------- --- ------
Fred 35 250.5
Barney 31 165.0
Betty 28 110.5
Wilma 33 115.0

Here is your skeleton code:

#include
#include
#include

using namespace std;

const int MAX = 100;

int read_data ( string names[], int ages[], double weights[], int max )
{
int n;

//
// Write this function first.
// Below here is the loop to read the input data.
//


assert ( n > 0 && n <= MAX );
return n;
}

void sort ( string names[], int ages[], double weights[], int n )
{
assert ( n > 0 && n <= MAX );

//
// Write this function last.
// Below here is the bubble sort code.
//

}

void print_report ( string names[], int ages[], double weights[], int n )
{
assert ( n > 0 && n <= MAX );

//
// Write this function second, so you can verify that you have read the data.
// Below here is the code to print the report.
//
}

int main()
{
string names[MAX];
int ages[MAX];
double weights[MAX];
int n;

n = read_data ( names, ages, weights, MAX );
assert ( n > 0 && n <= MAX );
sort ( names, ages, weights, n );
print_report ( names, ages, weights, n );

return 0;
}

Explanation / Answer

Here. Compiled in VS 2010. I used insertion sort here. It gave me the result as u need. Check it please. U can ask me any questions concerning the code if u need. #include #include #include using namespace std; const int MAX = 100; int read_data ( string names[], int ages[], double weights[], int max ) { int n; cout > n; for (int i = 0; i